Fix macOS builds on older SDKs (#3467)

This commit is contained in:
Jeffrey Morgan 2024-04-03 10:45:54 -07:00 committed by GitHub
parent 4f895d633f
commit cd135317d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 33 deletions

View file

@ -64,10 +64,10 @@ jobs:
echo $env:PATH echo $env:PATH
go generate -x ./... go generate -x ./...
if: ${{ startsWith(matrix.os, 'windows-') }} if: ${{ startsWith(matrix.os, 'windows-') }}
name: "Windows Go Generate" name: 'Windows Go Generate'
- run: go generate -x ./... - run: go generate -x ./...
if: ${{ ! startsWith(matrix.os, 'windows-') }} if: ${{ ! startsWith(matrix.os, 'windows-') }}
name: "Unix Go Generate" name: 'Unix Go Generate'
- uses: actions/upload-artifact@v4 - uses: actions/upload-artifact@v4
with: with:
name: ${{ matrix.os }}-${{ matrix.arch }}-libraries name: ${{ matrix.os }}-${{ matrix.arch }}-libraries
@ -148,7 +148,7 @@ jobs:
with: with:
go-version: '1.22' go-version: '1.22'
cache: true cache: true
- name: "Install ROCm" - name: 'Install ROCm'
run: | run: |
$ErrorActionPreference = "Stop" $ErrorActionPreference = "Stop"
write-host "downloading AMD HIP Installer" write-host "downloading AMD HIP Installer"
@ -156,7 +156,7 @@ jobs:
write-host "Installing AMD HIP" write-host "Installing AMD HIP"
Start-Process "${env:RUNNER_TEMP}\rocm-install.exe" -ArgumentList '-install' -NoNewWindow -Wait Start-Process "${env:RUNNER_TEMP}\rocm-install.exe" -ArgumentList '-install' -NoNewWindow -Wait
write-host "Completed AMD HIP" write-host "Completed AMD HIP"
- name: "Verify ROCm" - name: 'Verify ROCm'
run: | run: |
& 'C:\Program Files\AMD\ROCm\*\bin\clang.exe' --version & 'C:\Program Files\AMD\ROCm\*\bin\clang.exe' --version
- run: go get ./... - run: go get ./...
@ -185,7 +185,7 @@ jobs:
with: with:
go-version: '1.22' go-version: '1.22'
cache: true cache: true
- name: "Install CUDA" - name: 'Install CUDA'
run: | run: |
$ErrorActionPreference = "Stop" $ErrorActionPreference = "Stop"
write-host "downloading CUDA Installer" write-host "downloading CUDA Installer"
@ -199,7 +199,7 @@ jobs:
echo "CUDA_PATH=$cudaPath" >> $env:GITHUB_ENV echo "CUDA_PATH=$cudaPath" >> $env:GITHUB_ENV
echo "CUDA_PATH_V${cudaVer}=$cudaPath" >> $env:GITHUB_ENV echo "CUDA_PATH_V${cudaVer}=$cudaPath" >> $env:GITHUB_ENV
echo "CUDA_PATH_VX_Y=CUDA_PATH_V${cudaVer}" >> $env:GITHUB_ENV echo "CUDA_PATH_VX_Y=CUDA_PATH_V${cudaVer}" >> $env:GITHUB_ENV
- name: "Verify CUDA" - name: 'Verify CUDA'
run: nvcc -V run: nvcc -V
- run: go get ./... - run: go get ./...
- name: go generate - name: go generate
@ -216,7 +216,6 @@ jobs:
OLLAMA_SKIP_CPU_GENERATE: '1' OLLAMA_SKIP_CPU_GENERATE: '1'
# TODO - do we need any artifacts? # TODO - do we need any artifacts?
lint: lint:
strategy: strategy:
matrix: matrix:
@ -248,18 +247,18 @@ jobs:
esac >>$GITHUB_ENV esac >>$GITHUB_ENV
shell: bash shell: bash
- run: | - run: |
mkdir -p llm/build/linux/$ARCH/stub/bin/ mkdir -p llm/build/linux/$ARCH/stub/bin
touch llm/build/linux/$ARCH/stub/bin/stub.so touch llm/build/linux/$ARCH/stub/bin/ollama_llama_server
if: ${{ startsWith(matrix.os, 'ubuntu-') }} if: ${{ startsWith(matrix.os, 'ubuntu-') }}
- run: | - run: |
mkdir -p llm/build/darwin/$ARCH/stub/bin/ mkdir -p llm/build/darwin/$ARCH/stub/bin
touch llm/build/darwin/$ARCH/stub/bin/stub.dylib touch llm/build/darwin/$ARCH/stub/bin/ollama_llama_server
touch llm/ggml-metal.metal
if: ${{ startsWith(matrix.os, 'macos-') }} if: ${{ startsWith(matrix.os, 'macos-') }}
- run: | - run: |
mkdir -p llm/build/windows/$ARCH/stub/stub/bin/ mkdir -p llm/build/windows/$ARCH/stub/bin
touch llm/build/windows/$ARCH/stub/stub/bin/stub.dll touch llm/build/windows/$ARCH/stub/bin/ollama_llama_server
if: ${{ startsWith(matrix.os, 'windows-') }} if: ${{ startsWith(matrix.os, 'windows-') }}
shell: bash
- uses: golangci/golangci-lint-action@v4 - uses: golangci/golangci-lint-action@v4
with: with:
args: --timeout 8m0s args: --timeout 8m0s
@ -277,7 +276,7 @@ jobs:
env: env:
GOARCH: ${{ matrix.arch }} GOARCH: ${{ matrix.arch }}
CGO_ENABLED: '1' CGO_ENABLED: '1'
OLLAMA_CPU_TARGET: "static" OLLAMA_CPU_TARGET: 'static'
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
@ -294,18 +293,18 @@ jobs:
esac >>$GITHUB_ENV esac >>$GITHUB_ENV
shell: bash shell: bash
- run: | - run: |
mkdir -p llm/build/linux/$ARCH/stub/bin/ mkdir -p llm/build/linux/$ARCH/stub/bin
touch llm//build/linux/$ARCH/stub/bin/stub.so touch llm/build/linux/$ARCH/stub/bin/ollama_llama_server
if: ${{ startsWith(matrix.os, 'ubuntu-') }} if: ${{ startsWith(matrix.os, 'ubuntu-') }}
- run: | - run: |
mkdir -p llm/build/darwin/$ARCH/stub/bin/ mkdir -p llm/build/darwin/$ARCH/stub/bin
touch llm/build/darwin/$ARCH/stub/bin/stub.dylib touch llm/build/darwin/$ARCH/stub/bin/ollama_llama_server
touch llm/ggml-metal.metal
if: ${{ startsWith(matrix.os, 'macos-') }} if: ${{ startsWith(matrix.os, 'macos-') }}
- run: | - run: |
mkdir -p llm/build/windows/$ARCH/stub/stub/bin/ mkdir -p llm/build/windows/$ARCH/stub/bin
touch llm/build/windows/$ARCH/stub/stub/bin/stub.dll touch llm/build/windows/$ARCH/stub/bin/ollama_llama_server
if: ${{ startsWith(matrix.os, 'windows-') }} if: ${{ startsWith(matrix.os, 'windows-') }}
shell: bash
- run: go generate ./... - run: go generate ./...
- run: go build - run: go build
- run: go test -v ./... - run: go test -v ./...

View file

@ -15,10 +15,6 @@ import (
// TODO - this would ideally be in the llm package, but that would require some refactoring of interfaces in the server // TODO - this would ideally be in the llm package, but that would require some refactoring of interfaces in the server
// package to avoid circular dependencies // package to avoid circular dependencies
// WARNING - these tests will fail on mac if you don't manually copy ggml-metal.metal to this dir (./server)
//
// TODO - Fix this ^^
var ( var (
stream = false stream = false
req = [2]api.GenerateRequest{ req = [2]api.GenerateRequest{

View file

@ -18,7 +18,7 @@ sign() {
fi fi
} }
COMMON_DARWIN_DEFS="-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 -DCMAKE_SYSTEM_NAME=Darwin -DLLAMA_METAL_EMBED_LIBRARY=on" COMMON_DARWIN_DEFS="-DCMAKE_OSX_DEPLOYMENT_TARGET=11.3 -DLLAMA_METAL_MACOSX_VERSION_MIN=11.3 -DCMAKE_SYSTEM_NAME=Darwin -DLLAMA_METAL_EMBED_LIBRARY=on"
case "${GOARCH}" in case "${GOARCH}" in
"amd64") "amd64")
@ -41,7 +41,7 @@ case "${GOARCH}" in
BUILD_DIR="../build/darwin/${ARCH}/cpu" BUILD_DIR="../build/darwin/${ARCH}/cpu"
echo "Building LCD CPU" echo "Building LCD CPU"
build build
sign ${BUILD_DIR}/lib/libext_server.dylib sign ${BUILD_DIR}/bin/ollama_llama_server
compress compress
# #
@ -53,7 +53,7 @@ case "${GOARCH}" in
BUILD_DIR="../build/darwin/${ARCH}/cpu_avx" BUILD_DIR="../build/darwin/${ARCH}/cpu_avx"
echo "Building AVX CPU" echo "Building AVX CPU"
build build
sign ${BUILD_DIR}/lib/libext_server.dylib sign ${BUILD_DIR}/bin/ollama_llama_server
compress compress
# #
@ -66,7 +66,7 @@ case "${GOARCH}" in
echo "Building AVX2 CPU" echo "Building AVX2 CPU"
EXTRA_LIBS="${EXTRA_LIBS} -framework Accelerate -framework Foundation" EXTRA_LIBS="${EXTRA_LIBS} -framework Accelerate -framework Foundation"
build build
sign ${BUILD_DIR}/lib/libext_server.dylib sign ${BUILD_DIR}/bin/ollama_llama_server
compress compress
;; ;;
"arm64") "arm64")
@ -74,17 +74,17 @@ case "${GOARCH}" in
# Static build for linking into the Go binary # Static build for linking into the Go binary
init_vars init_vars
CMAKE_TARGETS="--target llama --target ggml" CMAKE_TARGETS="--target llama --target ggml"
CMAKE_DEFS="${COMMON_CPU_DEFS} -DBUILD_SHARED_LIBS=off -DLLAMA_ACCELERATE=off -DLLAMA_AVX=off -DLLAMA_AVX2=off -DLLAMA_AVX512=off -DLLAMA_FMA=off -DLLAMA_F16C=off ${CMAKE_DEFS}" CMAKE_DEFS="-DCMAKE_OSX_DEPLOYMENT_TARGET=11.3 -DCMAKE_SYSTEM_NAME=Darwin -DBUILD_SHARED_LIBS=off -DLLAMA_METAL=off -DLLAMA_ACCELERATE=off -DLLAMA_AVX=off -DLLAMA_AVX2=off -DLLAMA_AVX512=off -DLLAMA_FMA=off -DLLAMA_F16C=off ${CMAKE_DEFS}"
BUILD_DIR="../build/darwin/${ARCH}_static" BUILD_DIR="../build/darwin/${ARCH}_static"
echo "Building static library" echo "Building static library"
build build
init_vars init_vars
CMAKE_DEFS="${COMMON_DARWIN_DEFS} -DLLAMA_METAL_EMBED_LIBRARY=on -DLLAMA_ACCELERATE=on -DCMAKE_SYSTEM_PROCESSOR=${ARCH} -DCMAKE_OSX_ARCHITECTURES=${ARCH} -DLLAMA_METAL=on ${CMAKE_DEFS}" CMAKE_DEFS="${COMMON_DARWIN_DEFS} -DLLAMA_ACCELERATE=on -DCMAKE_SYSTEM_PROCESSOR=${ARCH} -DCMAKE_OSX_ARCHITECTURES=${ARCH} -DLLAMA_METAL=on ${CMAKE_DEFS}"
BUILD_DIR="../build/darwin/${ARCH}/metal" BUILD_DIR="../build/darwin/${ARCH}/metal"
EXTRA_LIBS="${EXTRA_LIBS} -framework Accelerate -framework Foundation -framework Metal -framework MetalKit -framework MetalPerformanceShaders" EXTRA_LIBS="${EXTRA_LIBS} -framework Accelerate -framework Foundation -framework Metal -framework MetalKit -framework MetalPerformanceShaders"
build build
sign ${BUILD_DIR}/lib/libext_server.dylib sign ${BUILD_DIR}/bin/ollama_llama_server
compress compress
;; ;;
*) *)