Skip to content

Commit

Permalink
fixpatch: ollama 0.5.4-1
Browse files Browse the repository at this point in the history
Fix CPU runner without any optimization like AVX. Upstreamed to ollama/ollama#8224.
  • Loading branch information
hack3ric authored and felixonmars committed Dec 24, 2024
1 parent c34b4be commit 035db09
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
24 changes: 24 additions & 0 deletions ollama/cpu-non-avx.patch
Original file line number Diff line number Diff line change
@@ -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 $@)
21 changes: 13 additions & 8 deletions ollama/riscv64.patch
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
+}

0 comments on commit 035db09

Please sign in to comment.