From 7fa6e51686236315ee4920dc79ceb1d7ef3d8199 Mon Sep 17 00:00:00 2001 From: Jeffrey Morgan Date: Tue, 5 Sep 2023 12:53:57 -0400 Subject: [PATCH] generate binary dependencies based on GOARCH on macos (#459) --- llm/llama.cpp/generate.go | 3 +++ llm/llama.cpp/generate_darwin_amd64.go | 8 ++++++++ .../{generate_darwin.go => generate_darwin_arm64.go} | 5 +---- scripts/build_darwin.sh | 6 ++++-- 4 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 llm/llama.cpp/generate_darwin_amd64.go rename llm/llama.cpp/{generate_darwin.go => generate_darwin_arm64.go} (78%) diff --git a/llm/llama.cpp/generate.go b/llm/llama.cpp/generate.go index e24dd76c..dbbf05b7 100644 --- a/llm/llama.cpp/generate.go +++ b/llm/llama.cpp/generate.go @@ -1,3 +1,6 @@ +//go:build !darwin +// +build !darwin + package llm //go:generate git submodule init diff --git a/llm/llama.cpp/generate_darwin_amd64.go b/llm/llama.cpp/generate_darwin_amd64.go new file mode 100644 index 00000000..1d7f94ae --- /dev/null +++ b/llm/llama.cpp/generate_darwin_amd64.go @@ -0,0 +1,8 @@ +package llm + +//go:generate git submodule init +//go:generate git submodule update --force ggml +//go:generate git -C ggml apply ../ggml_patch/0001-add-detokenize-endpoint.patch +//go:generate git -C ggml apply ../ggml_patch/0002-34B-model-support.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 --build ggml/build/cpu --target server --config Release diff --git a/llm/llama.cpp/generate_darwin.go b/llm/llama.cpp/generate_darwin_arm64.go similarity index 78% rename from llm/llama.cpp/generate_darwin.go rename to llm/llama.cpp/generate_darwin_arm64.go index df8eadca..934c943f 100644 --- a/llm/llama.cpp/generate_darwin.go +++ b/llm/llama.cpp/generate_darwin_arm64.go @@ -1,11 +1,8 @@ -//go:build darwin -// +build darwin - package llm //go:generate git submodule init //go:generate git submodule update --force ggml //go:generate git -C ggml apply ../ggml_patch/0001-add-detokenize-endpoint.patch //go:generate git -C ggml apply ../ggml_patch/0002-34B-model-support.patch -//go:generate cmake -S ggml -B ggml/build/gpu -DLLAMA_METAL=on -DLLAMA_ACCELERATE=on -DLLAMA_K_QUANTS=on +//go:generate cmake -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 --build ggml/build/gpu --target server --config Release diff --git a/scripts/build_darwin.sh b/scripts/build_darwin.sh index d7143615..d2d54a92 100755 --- a/scripts/build_darwin.sh +++ b/scripts/build_darwin.sh @@ -6,8 +6,10 @@ GO_LDFLAGS="-X github.com/jmorganca/ollama/version.Version=$VERSION" GO_LDFLAGS="$GO_LDFLAGS -X github.com/jmorganca/ollama/server.mode=release" # build universal binary -CGO_ENABLED=1 GOARCH=arm64 go build -ldflags "$GO_LDFLAGS" -o dist/ollama-darwin-arm64 -CGO_ENABLED=1 GOARCH=amd64 go build -ldflags "$GO_LDFLAGS" -o dist/ollama-darwin-amd64 +GOARCH=arm64 go generate ./... +GOARCH=arm64 go build -ldflags "$GO_LDFLAGS" -o dist/ollama-darwin-arm64 +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 rm dist/ollama-darwin-amd64 dist/ollama-darwin-arm64 codesign --deep --force --options=runtime --sign "$APPLE_IDENTITY" --timestamp dist/ollama