git: 13825a9a521d - main - misc/ollama: add patches for: image generation hanging/timeout on slow CPUs, etc.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 27 Mar 2026 22:58:09 UTC
The branch main has been updated by yuri:
URL: https://cgit.FreeBSD.org/ports/commit/?id=13825a9a521d20dff96d70bafdcb79472805314a
commit 13825a9a521d20dff96d70bafdcb79472805314a
Author: Yuri Victorovich <yuri@FreeBSD.org>
AuthorDate: 2026-03-27 13:34:02 +0000
Commit: Yuri Victorovich <yuri@FreeBSD.org>
CommitDate: 2026-03-27 22:58:07 +0000
misc/ollama: add patches for: image generation hanging/timeout on slow CPUs, etc.
Enable image gen via MLX - now your local llama can finally draw Beastie
in sunglasses:
$ ollama run x/z-image-turbo "FreeBSD Beastie in sunglasses drinking coffee at the beach"
---
misc/ollama/Makefile | 2 +-
.../files/patch-x_imagegen_models_zimage_vae.go | 35 ++++++++++++++++++++++
misc/ollama/files/patch-x_imagegen_server.go | 26 ++++++++++++++++
3 files changed, 62 insertions(+), 1 deletion(-)
diff --git a/misc/ollama/Makefile b/misc/ollama/Makefile
index f10ae5724905..e78c28f88d48 100644
--- a/misc/ollama/Makefile
+++ b/misc/ollama/Makefile
@@ -1,7 +1,7 @@
PORTNAME= ollama
DISTVERSIONPREFIX= v
DISTVERSION= 0.18.3
-PORTREVISION= 1
+PORTREVISION= 2
CATEGORIES= misc # machine-learning
MAINTAINER= yuri@FreeBSD.org
diff --git a/misc/ollama/files/patch-x_imagegen_models_zimage_vae.go b/misc/ollama/files/patch-x_imagegen_models_zimage_vae.go
new file mode 100644
index 000000000000..0c9e990b52ba
--- /dev/null
+++ b/misc/ollama/files/patch-x_imagegen_models_zimage_vae.go
@@ -0,0 +1,35 @@
+--- x/imagegen/models/zimage/vae.go.orig 1979-11-30 00:00:00.000000000 -0800
++++ x/imagegen/models/zimage/vae.go
+@@ -332,6 +332,16 @@
+
+ // Forward applies the ResNet block with staged evaluation
+ func (rb *ResnetBlock2D) Forward(x *mlx.Array) *mlx.Array {
++ // Keep x alive across intermediate Eval calls (cleanup() would free it otherwise).
++ // The residual connection at the end needs the original x.
++ wasKept := x.Kept()
++ mlx.Keep(x)
++ defer func() {
++ if !wasKept {
++ x.Free()
++ }
++ }()
++
+ var h *mlx.Array
+
+ // Stage 1: norm1
+@@ -461,6 +471,15 @@
+ // Input and output are in NHWC format [B, H, W, C]
+ func (ab *VAEAttentionBlock) Forward(x *mlx.Array) *mlx.Array {
+ residual := x
++ // Keep residual alive across intermediate Eval calls.
++ // The residual addition at stage 3 needs the original input.
++ wasKept := residual.Kept()
++ mlx.Keep(residual)
++ defer func() {
++ if !wasKept {
++ residual.Free()
++ }
++ }()
+ shape := x.Shape()
+ B := shape[0]
+ H := shape[1]
diff --git a/misc/ollama/files/patch-x_imagegen_server.go b/misc/ollama/files/patch-x_imagegen_server.go
new file mode 100644
index 000000000000..a49851568dec
--- /dev/null
+++ b/misc/ollama/files/patch-x_imagegen_server.go
@@ -0,0 +1,26 @@
+-- same issue as first chunk: https://github.com/ollama/ollama/issues/15107
+
+--- x/imagegen/server.go.orig
++++ x/imagegen/server.go
+@@ -55,7 +55,9 @@
+ return &Server{
+ modelName: modelName,
+ done: make(chan error, 1),
+- client: &http.Client{Timeout: 10 * time.Minute},
++ // No client-level timeout: image generation on CPU can take many minutes.
++ // Cancellation is handled via request context.
++ client: &http.Client{},
+ }, nil
+ }
+
+@@ -116,8 +118,8 @@
+ cmd := exec.Command(exe, "runner", "--imagegen-engine", "--model", s.modelName, "--port", strconv.Itoa(port))
+ cmd.Env = os.Environ()
+
+- // On Linux, set LD_LIBRARY_PATH to include MLX library directories
+- if runtime.GOOS == "linux" {
++ // On Linux and FreeBSD, set LD_LIBRARY_PATH to include MLX library directories
++ if runtime.GOOS == "linux" || runtime.GOOS == "freebsd" {
+ // Build library paths: start with LibOllamaPath, then add any mlx_* subdirectories
+ libraryPaths := []string{ml.LibOllamaPath}
+ if mlxDirs, err := filepath.Glob(filepath.Join(ml.LibOllamaPath, "mlx_*")); err == nil {