From 035db09cb307b7eddadc22fc9fedc1ecb8b55714 Mon Sep 17 00:00:00 2001 From: Eric Long Date: Tue, 24 Dec 2024 10:58:45 +0800 Subject: [PATCH] fixpatch: ollama 0.5.4-1 Fix CPU runner without any optimization like AVX. Upstreamed to https://github.com/ollama/ollama/pull/8224. --- ollama/cpu-non-avx.patch | 24 ++++++++++++++++++++++++ ollama/riscv64.patch | 21 +++++++++++++-------- 2 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 ollama/cpu-non-avx.patch diff --git a/ollama/cpu-non-avx.patch b/ollama/cpu-non-avx.patch new file mode 100644 index 000000000..6012341a0 --- /dev/null +++ b/ollama/cpu-non-avx.patch @@ -0,0 +1,24 @@ +diff --git a/make/Makefile.cpu b/make/Makefile.cpu +index 968ae934..ca4d7df2 100644 +--- a/make/Makefile.cpu ++++ b/make/Makefile.cpu +@@ -8,6 +8,7 @@ ifeq ($(origin CUSTOM_CPU_FLAGS),undefined) + RUNNERS = cpu_avx cpu_avx2 + endif + endif ++RUNNERS += cpu + + DIST_RUNNERS = $(addprefix $(RUNNERS_DIST_DIR)/,$(addsuffix /ollama_llama_server$(EXE_EXT),$(RUNNERS))) + BUILD_RUNNERS = $(addprefix $(RUNNERS_BUILD_DIR)/,$(addsuffix /ollama_llama_server$(EXE_EXT),$(RUNNERS))) +@@ -16,6 +17,11 @@ cpu: $(BUILD_RUNNERS) + + dist: $(DIST_RUNNERS) + ++$(RUNNERS_BUILD_DIR)/cpu/ollama_llama_server$(EXE_EXT): TARGET_CPU_FLAGS="" ++$(RUNNERS_BUILD_DIR)/cpu/ollama_llama_server$(EXE_EXT): ./llama/*.go ./llama/runner/*.go $(COMMON_SRCS) $(COMMON_HDRS) ++ @-mkdir -p $(dir $@) ++ GOARCH=$(ARCH) go build -buildmode=pie $(CPU_GOFLAGS) -trimpath -tags $(subst $(space),$(comma),$(TARGET_CPU_FLAGS)) -o $@ ./cmd/runner ++ + $(RUNNERS_BUILD_DIR)/cpu_avx/ollama_llama_server$(EXE_EXT): TARGET_CPU_FLAGS="avx" + $(RUNNERS_BUILD_DIR)/cpu_avx/ollama_llama_server$(EXE_EXT): ./llama/*.go ./llama/runner/*.go $(COMMON_SRCS) $(COMMON_HDRS) + @-mkdir -p $(dir $@) diff --git a/ollama/riscv64.patch b/ollama/riscv64.patch index 204987b87..007df553e 100644 --- a/ollama/riscv64.patch +++ b/ollama/riscv64.patch @@ -1,15 +1,17 @@ --- PKGBUILD +++ PKGBUILD -@@ -37,7 +37,7 @@ build() { +@@ -37,7 +37,9 @@ build() { # Unset these otherwise somehow nvcc will try to use them. unset CFLAGS CXXFLAGS - make dist CUDA_12_PATH=/opt/cuda -+ make dist ++ # CPU runner is not automatically selected due to lack of optimization, but ++ # it is required by Arch packaging ++ make dist RUNNER_TARGETS='cpu rocm' go build . } -@@ -50,7 +50,7 @@ check() { +@@ -50,7 +52,7 @@ check() { package_ollama() { install -Dm755 ollama/ollama "$pkgdir/usr/bin/ollama" mkdir -p "$pkgdir"/usr/lib/ollama/runners @@ -18,7 +20,7 @@ install -Dm755 $pkgname/$pkgbase "$pkgdir/usr/bin/$pkgbase" install -dm755 "$pkgdir/var/lib/ollama" -@@ -67,7 +67,7 @@ package_ollama-rocm() { +@@ -67,7 +69,7 @@ package_ollama-rocm() { depends+=(ollama hipblas) mkdir -p "$pkgdir"/usr/lib/ollama/runners @@ -27,7 +29,7 @@ } package_ollama-cuda() { -@@ -75,7 +75,7 @@ package_ollama-cuda() { +@@ -75,7 +77,7 @@ package_ollama-cuda() { depends+=(ollama cuda) mkdir -p "$pkgdir"/usr/lib/ollama/runners @@ -36,17 +38,20 @@ } package_ollama-docs() { -@@ -85,3 +85,13 @@ package_ollama-docs() { +@@ -85,3 +87,16 @@ package_ollama-docs() { cp -r $pkgbase/docs "$pkgdir/usr/share/doc/$pkgbase" install -Dm644 $pkgbase/LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE" } + +pkgname=(${pkgname[@]/ollama-cuda}) +makedepends=(${makedepends[@]/cuda}) -+source+=(remove-unsupported-flags.patch) -+b2sums+=('19f2aefbc5f4c4ba3102275f6e6e5376500cadc8df609873c290b29210ddd60926fadef315b2878ba3f97591469b862b9c7dd6e797017f3bc8cbd8bccc577086') ++source+=(remove-unsupported-flags.patch ++ cpu-non-avx.patch) ++b2sums+=('19f2aefbc5f4c4ba3102275f6e6e5376500cadc8df609873c290b29210ddd60926fadef315b2878ba3f97591469b862b9c7dd6e797017f3bc8cbd8bccc577086' ++ 'f87f77e957c07122164e2aa791dfdbb6bb20c3b55bee485fe30e9c212789fec4ec84012542878b9404f50d3fd41c51667d1bf7ed6614fd089efcc145fe124c84') + +prepare() { + cd ollama + patch -Np1 -i "$srcdir"/remove-unsupported-flags.patch ++ patch -Np1 -i "$srcdir"/cpu-non-avx.patch +}