[PR #13735] [MERGED] MLX - dynamic loading of mlx-c #14368

Closed
opened 2026-04-13 00:51:54 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/13735
Author: @dhiltgen
Created: 1/15/2026
Status: Merged
Merged: 1/17/2026
Merged by: @dhiltgen

Base: mainHead: mlx_dlopen


📝 Commits (3)

📊 Changes

24 files changed (+9043 additions, -228 deletions)

View changed files

📝 Dockerfile (+6 -12)
MLX_VERSION (+1 -0)
📝 README.md (+2 -2)
📝 scripts/build_darwin.sh (+9 -11)
📝 x/imagegen/cmd/engine/generate.go (+4 -4)
📝 x/imagegen/cmd/engine/main.go (+5 -1)
📝 x/imagegen/mlx/compile.go (+1 -1)
x/imagegen/mlx/doc.go (+6 -0)
x/imagegen/mlx/generate_wrappers.go (+439 -0)
x/imagegen/mlx/mlx.c (+5786 -0)
📝 x/imagegen/mlx/mlx.go (+55 -190)
x/imagegen/mlx/mlx.h (+2337 -0)
x/imagegen/mlx/mlx_dynamic.c (+144 -0)
x/imagegen/mlx/mlx_dynamic.h (+29 -0)
📝 x/imagegen/mlx/mlx_test.go (+21 -0)
📝 x/imagegen/models/qwen_image/pipeline_test.go (+21 -0)
📝 x/imagegen/models/qwen_image/qwen_image.go (+0 -1)
📝 x/imagegen/models/qwen_image_edit/rope_test.go (+22 -0)
📝 x/imagegen/nn/nn_test.go (+22 -0)
📝 x/imagegen/runner/runner.go (+6 -0)

...and 4 more files

📄 Description

Create a wrapper layer to indirect the dependency on mlx-c so the main ollama binary does not have a load-time dependency on mlx-c, mlx, and on linux, cuda. Lazy load the library via dlopen so we can adjust the path to ensure the dependencies are found and fail gracefully if not present.

This enables us to move back to shipping a single ollama CLI executable on Mac/Linux with MLX enabled, and safeguard against potential missing libraries by deferring library dependency resolution.

Verified on Mac and Linux. The Windows impl is untested for now.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/13735 **Author:** [@dhiltgen](https://github.com/dhiltgen) **Created:** 1/15/2026 **Status:** ✅ Merged **Merged:** 1/17/2026 **Merged by:** [@dhiltgen](https://github.com/dhiltgen) **Base:** `main` ← **Head:** `mlx_dlopen` --- ### 📝 Commits (3) - [`ffdc257`](https://github.com/ollama/ollama/commit/ffdc257bef698bd28f10f34279076ea2a0eed7ff) MLX - dynamic loading of mlx-c - [`1c2d073`](https://github.com/ollama/ollama/commit/1c2d073750295aef05836b111f5b0b9fae2a79e8) review comments - [`ffff6e3`](https://github.com/ollama/ollama/commit/ffff6e37ac800ca59194fb26ff29392f2d224de4) fix broken tests ### 📊 Changes **24 files changed** (+9043 additions, -228 deletions) <details> <summary>View changed files</summary> 📝 `Dockerfile` (+6 -12) ➕ `MLX_VERSION` (+1 -0) 📝 `README.md` (+2 -2) 📝 `scripts/build_darwin.sh` (+9 -11) 📝 `x/imagegen/cmd/engine/generate.go` (+4 -4) 📝 `x/imagegen/cmd/engine/main.go` (+5 -1) 📝 `x/imagegen/mlx/compile.go` (+1 -1) ➕ `x/imagegen/mlx/doc.go` (+6 -0) ➕ `x/imagegen/mlx/generate_wrappers.go` (+439 -0) ➕ `x/imagegen/mlx/mlx.c` (+5786 -0) 📝 `x/imagegen/mlx/mlx.go` (+55 -190) ➕ `x/imagegen/mlx/mlx.h` (+2337 -0) ➕ `x/imagegen/mlx/mlx_dynamic.c` (+144 -0) ➕ `x/imagegen/mlx/mlx_dynamic.h` (+29 -0) 📝 `x/imagegen/mlx/mlx_test.go` (+21 -0) 📝 `x/imagegen/models/qwen_image/pipeline_test.go` (+21 -0) 📝 `x/imagegen/models/qwen_image/qwen_image.go` (+0 -1) 📝 `x/imagegen/models/qwen_image_edit/rope_test.go` (+22 -0) 📝 `x/imagegen/nn/nn_test.go` (+22 -0) 📝 `x/imagegen/runner/runner.go` (+6 -0) _...and 4 more files_ </details> ### 📄 Description Create a wrapper layer to indirect the dependency on mlx-c so the main ollama binary does not have a load-time dependency on mlx-c, mlx, and on linux, cuda. Lazy load the library via dlopen so we can adjust the path to ensure the dependencies are found and fail gracefully if not present. This enables us to move back to shipping a single `ollama` CLI executable on Mac/Linux with MLX enabled, and safeguard against potential missing libraries by deferring library dependency resolution. Verified on Mac and Linux. The Windows impl is untested for now. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-13 00:51:54 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#14368