MLX-native ONNX Runtime execution provider (plugin EP) for Apple Silicon
Project description
onnxruntime-mlx (Python package)
Pip-installable MLX-native execution provider for ONNX Runtime on Apple
Silicon. The wheel bundles the cargo-built libonnxruntime_mlx_ep.dylib plugin
EP (plus its mlx-c / mlx dynamic dependencies and mlx.metallib) and a
thin pure-Python locator that finds it, so Python users can register the EP
with a stock onnxruntime wheel — no ONNX Runtime fork or manual dylib path
required.
- Import name:
onnxruntime_mlx - Distribution name:
onnxruntime-mlx - Platform: macOS 14+ on Apple Silicon (arm64) only
- Requires:
onnxruntime >= 1.22(plugin-EP C API,ORT_API_VERSION >= 27)
Install
The wheel is built from a full repository checkout (the build hook runs
cargo build --release in the sibling rust/ crate). Install a Rust toolchain
(rustup) and brew install mlx-c first, then:
# from the repo root; point at the ORT C-API headers (or set ORT_HOME):
ORT_INCLUDE_DIR=/path/to/onnxruntime/include python -m build --wheel ./python
# or install directly:
ORT_INCLUDE_DIR=/path/to/onnxruntime/include pip install ./python
Build backend: hatchling with a custom build hook (hatch_build.py). There
is no compiled Python extension — the EP is a Rust cdylib, and the Python
layer is a pure-Python locator. The hook:
- runs
cargo build --releasein../rust(honouringORT_INCLUDE_DIR, else$ORT_HOME/include), then - bundles the resulting dylib + the
mlx-c/mlxruntime into the package (relinked to@loader_path), and - forces a single
py3-none-macosx_*_arm64platform wheel.
Because the wheel ships zero CPython-ABI code, one wheel installs on CPython
3.12, 3.13 and the free-threaded (3.13t/3.14t) builds — and abi3audit --strict is clean by construction (nothing auditable).
Usage
import onnxruntime as ort
import onnxruntime_mlx
onnxruntime_mlx.register_execution_provider_library() # once per process
sess = ort.InferenceSession(
"model.onnx",
providers=["MLXExecutionProvider", "CPUExecutionProvider"],
)
Public API (onnxruntime_mlx)
| Function | Returns |
|---|---|
ep_name() |
"MLXExecutionProvider" |
version() |
the installed package version string |
vendor() |
"onnxruntime-mlx" |
library_path() |
absolute path to the bundled libonnxruntime_mlx_ep.dylib |
Plus register_execution_provider_library() and append_to_session_options().
How the dylib + mlx deps are bundled
The build hook (hatch_build.py):
- copies
libmlxc.dylib,libmlx.dylib, andmlx.metallibnext to the plugin inside the package; - rewrites the plugin's mlx dependencies to
@loader_path/lib{mlxc,mlx}.dyliband the bundled install ids to match, then re-signs (ad-hoc) each mutated binary.
The Rust EP does not link libonnxruntime (it reaches ORT purely through
the OrtApi function-pointer table), so there is no onnxruntime dependency to
rewrite; onnxruntime is never vendored and must match the host at runtime.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file onnxruntime_mlx-0.1.0-py3-none-macosx_14_0_universal2.whl.
File metadata
- Download URL: onnxruntime_mlx-0.1.0-py3-none-macosx_14_0_universal2.whl
- Upload date:
- Size: 37.0 MB
- Tags: Python 3, macOS 14.0+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef0f22aae8192640273cb6ec0c3c25db2d0777f10e1ce394648801c97ea316c8
|
|
| MD5 |
8e93f169afa36ef4cb485374dba73750
|
|
| BLAKE2b-256 |
ecc6a2e32a0f7c345ae5dbd7a3e30f33c08803a5c90ca2a1bd0af79b3d1f8efd
|
Provenance
The following attestation bundles were made for onnxruntime_mlx-0.1.0-py3-none-macosx_14_0_universal2.whl:
Publisher:
publish.yml on justinchuby/onnxruntime-mlx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
onnxruntime_mlx-0.1.0-py3-none-macosx_14_0_universal2.whl -
Subject digest:
ef0f22aae8192640273cb6ec0c3c25db2d0777f10e1ce394648801c97ea316c8 - Sigstore transparency entry: 2169981650
- Sigstore integration time:
-
Permalink:
justinchuby/onnxruntime-mlx@e63db3101d2bbd91d3776d39f685ec4d62c8900a -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/justinchuby
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e63db3101d2bbd91d3776d39f685ec4d62c8900a -
Trigger Event:
release
-
Statement type: