From 213ffdb54899cd82a4ecf911f217542a1b37d2fc Mon Sep 17 00:00:00 2001 From: Jeffrey Morgan Date: Tue, 5 Sep 2023 21:33:27 -0400 Subject: [PATCH] macos `amd64` compatibility fixes --- llm/ggml_llama.go | 5 ++++- llm/llama.cpp/generate_darwin_amd64.go | 2 +- llm/llama.cpp/generate_darwin_arm64.go | 2 +- scripts/build_darwin.sh | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/llm/ggml_llama.go b/llm/ggml_llama.go index 010d579a..8af62157 100644 --- a/llm/ggml_llama.go +++ b/llm/ggml_llama.go @@ -45,6 +45,7 @@ func osPath(llamaPath string) string { if runtime.GOOS == "windows" { return path.Join(llamaPath, "Release") } + return llamaPath } @@ -68,7 +69,9 @@ func initGGML() { case "windows": files = []string{"server.exe"} case "darwin": - files = append(files, "ggml-metal.metal") + if llamaPath == ggmlGPU { + files = append(files, "ggml-metal.metal") + } } for _, f := range files { diff --git a/llm/llama.cpp/generate_darwin_amd64.go b/llm/llama.cpp/generate_darwin_amd64.go index c2fd9f3e..ec647889 100644 --- a/llm/llama.cpp/generate_darwin_amd64.go +++ b/llm/llama.cpp/generate_darwin_amd64.go @@ -6,5 +6,5 @@ package llm //go:generate git -C ggml apply ../ggml_patch/0002-34B-model-support.patch //go:generate git -C ggml apply ../ggml_patch/0003-metal-fix-synchronization-in-new-matrix-multiplicati.patch //go:generate git -C ggml apply ../ggml_patch/0004-metal-add-missing-barriers-for-mul-mat-2699.patch -//go:generate cmake --fresh -S ggml -B ggml/build/cpu -DLLAMA_ACCELERATE=on -DLLAMA_K_QUANTS=on -DCMAKE_SYSTEM_PROCESSOR=x86_64 -DCMAKE_OSX_ARCHITECTURES=x86_64 +//go:generate cmake --fresh -S ggml -B ggml/build/cpu -DLLAMA_ACCELERATE=on -DLLAMA_K_QUANTS=on -DCMAKE_SYSTEM_PROCESSOR=x86_64 -DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_OSX_DEPLOYMENT_TARGET=10.11 //go:generate cmake --build ggml/build/cpu --target server --config Release diff --git a/llm/llama.cpp/generate_darwin_arm64.go b/llm/llama.cpp/generate_darwin_arm64.go index 4f48ebb8..d91682c0 100644 --- a/llm/llama.cpp/generate_darwin_arm64.go +++ b/llm/llama.cpp/generate_darwin_arm64.go @@ -6,5 +6,5 @@ package llm //go:generate git -C ggml apply ../ggml_patch/0002-34B-model-support.patch //go:generate git -C ggml apply ../ggml_patch/0003-metal-fix-synchronization-in-new-matrix-multiplicati.patch //go:generate git -C ggml apply ../ggml_patch/0004-metal-add-missing-barriers-for-mul-mat-2699.patch -//go:generate cmake --fresh -S ggml -B ggml/build/gpu -DLLAMA_METAL=on -DLLAMA_ACCELERATE=on -DLLAMA_K_QUANTS=on -DCMAKE_SYSTEM_PROCESSOR=arm64 -DCMAKE_OSX_ARCHITECTURES=arm64 +//go:generate cmake --fresh -S ggml -B ggml/build/gpu -DLLAMA_METAL=on -DLLAMA_ACCELERATE=on -DLLAMA_K_QUANTS=on -DCMAKE_SYSTEM_PROCESSOR=arm64 -DCMAKE_OSX_ARCHITECTURES=arm64 -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 //go:generate cmake --build ggml/build/gpu --target server --config Release diff --git a/scripts/build_darwin.sh b/scripts/build_darwin.sh index d2d54a92..e0bbf02d 100755 --- a/scripts/build_darwin.sh +++ b/scripts/build_darwin.sh @@ -8,6 +8,7 @@ GO_LDFLAGS="$GO_LDFLAGS -X github.com/jmorganca/ollama/server.mode=release" # build universal binary GOARCH=arm64 go generate ./... GOARCH=arm64 go build -ldflags "$GO_LDFLAGS" -o dist/ollama-darwin-arm64 +rm -rf llm/llama.cpp/ggml/build/*/bin GOARCH=amd64 go generate ./... GOARCH=amd64 go build -ldflags "$GO_LDFLAGS" -o dist/ollama-darwin-amd64 lipo -create -output dist/ollama dist/ollama-darwin-arm64 dist/ollama-darwin-amd64