mlx-rs
Library Featured
Unofficial rust wrapper for Apple's mlx machine learning library.
- Downloads
- 33,398
- Dependents
- 36
- Stars
- 389
- Forks
- 75
- Contributors
- 15
- Commits
- 449
- Latest release
- 0.34.0 ·
About
Rust bindings for Apple's mlx machine learning library.
⚠️ Project is in active development - contributors welcome!
Blaze supports this project by providing ultra-fast Apple Silicon macOS Github Action Runners. Apply the discount code AI25 at checkout to enjoy 25% off your first year.
Documentation
Due to known limitation of docsrs, we are hosting the documentation on github pages here.
Features
MLX is an array framework for machine learning on Apple Silicon. mlx-rs provides Rust bindings for MLX, allowing you to use MLX in your Rust projects.
Some key features of MLX and mlx-rs include:
Read the full README
- Performance: MLX is optimized for Apple Silicon, providing fast performance for machine learning tasks.
- Lazy Evaluation: MLX uses lazy evaluation to optimize performance and memory usage. Arrays are only materialized when needed.
- Dynamic Graphs: Computation graphs in MLX are constructed dynamically, allowing for flexible and efficient computation. Changing the shapes of function arguments does not require recompilation.
- Mutli-Device Support: MLX supports running computations on any of the supported devices (for now the CPU and GPU).
- Unified memory: MLX provides a unified memory model, meaning arrays live in the same memory space, regardless of the device they are computed on. Operations can be performed on arrays on different devices without copying data between them.
mlx-rs is designed to be a safe and idiomatic Rust interface to MLX, providing a seamless experience for Rust developers.
Examples
The examples directory contains sample projects demonstrating different uses cases of our library.
- mnist: Train a basic neural network on the MNIST digit dataset
- mistral: Text generation using the pre-trained Mistral model
Installation
Add this to your Cargo.toml:
[dependencies]
mlx-rs = "0.34.0"
See mlx-sys build configuration for system Xcode opt-in, deployment targets and NAX kernel requirements. Use a prebuilt MLX to build with Command Line Tools alone.
Feature Flags
metal- enables metal (GPU) usage in MLXaccelerate- enables using the accelerate framework in MLX
Important Notes on Automatic Differentiation
When using automatic differentiation in mlx-rs, there's an important difference in how closures work compared to Python's MLX. In Python, variables are implicitly captured and properly traced in the compute graph. However, in Rust, we need to be more explicit about which arrays should be traced.
❌ This approach may cause segfaults:
// Don't do this
let x = random::normal::<f32>(&[num_examples, num_features], None, None, None)?;
let y = x.matmul(&w_star)? + eps;
let loss_fn = |w: &Array| -> Result<Array, Exception> {
let y_pred = x.matmul(w)?; // x and y are captured from outer scope
let loss = Array::from_f32(0.5) * ops::mean(&ops::square(&(y_pred - &y))?, None, None)?;
Ok(loss)
};
let grad_fn = transforms::grad(loss_fn, &[0]);
✅ Instead, pass all required arrays as inputs to ensure proper tracing:
let loss_fn = |inputs: &[Array]| -> Result<Array, Exception> {
let w = &inputs[0];
let x = &inputs[1];
let y = &inputs[2];
let y_pred = x.matmul(w)?;
let loss = Array::from_f32(0.5) * ops::mean(&ops::square(y_pred - y)?, None, None)?;
Ok(loss)
};
let argnums = &[0]; // Specify which argument to differentiate with respect to
// Pass all required arrays in the inputs slice
let mut inputs = vec![w, x, y];
let grad = transforms::grad(loss_fn, argnums)(&inputs)?;
When using gradients in training loops, remember to update the appropriate array in your inputs:
let mut inputs = vec![w, x, y];
for _ in 0..num_iterations {
let grad = transforms::grad(loss_fn, argnums)(&inputs)?;
inputs[0] = &inputs[0] - Array::from_f32(learning_rate) * grad; // Update the weight array
inputs[0].eval()?;
}
We are actively working on improving this API to make it more ergonomic and closer to Python's behavior. For now, explicitly passing all required arrays as shown above is the recommended approach.
Versioning
mlx-rs follows semver on its own schedule, so a breaking change gets a new minor version whether or not MLX moved. Each release's changelog entry names the MLX version it builds:
| mlx-rs | MLX |
|---|---|
| 0.34 | 0.32.2 |
| 0.33 | 0.32.2 |
| 0.32 | 0.32.2 |
mlx-sys follows the version of mlx-c it binds.
Community
If you are excited about the project or want to contribute, don't hesitate to join our Discord! We try to be as welcoming as possible to everybody from any background. We're still building this out, but you can ask your questions there!
Status
mlx-rs is currently in active development and can be used to run MLX models in Rust.
MSRV
The minimum supported Rust version is 1.88.0.
The MSRV is the minimum Rust version that can be used to compile each crate.
License
mlx-rs is distributed under the terms of both the MIT license and the Apache License (Version 2.0). See LICENSE-APACHE and LICENSE-MIT for details. Opening a pull request is assumed to signal agreement with these licensing terms.
Compatibility
- Runs on
- Metal
What shows it
- Metal: mlx-rs feature metal, mlx-sys feature metal
- Native code
- Required
- Binds native code: mach-sys, mlx, mlx-sys
- Build uses a native toolchain: bindgen, cc, cmake
- Python bindings
- No Python binding crate found
- License
- Apache-2.0 OR MIT
Compare with similar projects
Order: strongest tier first, then most downloads, then name, with unmeasured values last. A library counts downloads over 30 days. An app counts binary downloads per release. An app with none counts its crate downloads over 30 days. ML Rust runs this catalogue, so its closest project always gets a row.
| Project | Downloads | Dependents | Stars | Latest release | Runs on (GPU) | Native code | License |
|---|---|---|---|---|---|---|---|
|
Unofficial rust wrapper for Apple's mlx machine learning library. |
33,398 downloads over 30 days | 36 | 389 | 0.34.0 | Metal | Binds native code: mach-sys, mlx, mlx-sys. Build uses a native toolchain: bindgen, cc, cmake | Apache-2.0 OR MIT |
|
tch-rs Featured
Rust wrappers for the PyTorch C++ api (libtorch). Python bindings Also in Run and serve models. |
1,190,464 downloads over 30 days | 124 | 5,518 | 0.26.0 | CUDA | Binds native code: tch, torch-sys. Build uses a native toolchain: cc | Apache-2.0 OR MIT |
|
burn Featured
Flexible and Comprehensive Deep Learning Framework in Rust Also in Run and serve models. |
521,465 downloads over 30 days | 391 | 16,257 | 0.22.1 | CUDA, WebGPU, Metal, ROCm, Vulkan | Binds native code: netlink-sys (feature iroh), nvml-wrapper-sys (feature sys-metrics), torch-sys (feature tch) | Apache-2.0 OR MIT |
|
boostr Listed
ML framework on numr for training and inference on CPU, CUDA and WebGPU: attention, quantization, inference scheduling and distributed execution. Models include LLaMA, Mamba2, Qwen3.5, Whisper, Kokoro, VITS, VoxCPM2, Silero VAD, CLAP and super-resolution. Loads SafeTensors and GGUF. Also in Run and serve models. |
1,265 downloads over 30 days | 7 | 20 | 0.11.2 | CUDA, WebGPU | Binds native code: ring (feature distributed) | Apache-2.0 |
|
Modern Rust bindings for Apple's Metal Performance Shaders Graph framework Also in Train models. |
398 downloads over 30 days | 2 | Not measured | 0.2.0 | Metal | No native code found | MIT |
|
A machine learning library for Rust. Also in Train models. |
25 downloads over 30 days | 0 | 333 | 0.2.1 | GPU support unknown | Binds native code: curl-sys (feature mnist), libz-sys (feature mnist) | Apache-2.0 OR MIT |
All projects in Run and serve modelsAll projects in Train models
Why FeaturedIt passes every Featured gate.
What it meets
- It has 16 active dependents and 15 new dependents in 365 days. Featured needs 11 active dependents or 9 new dependents in 365 days.
- Active dependents are at 100% of their peak. Featured needs at least 50%.
- Docs are present. The release commit or a manifest ties the crate to the repository.
- No vulnerability advisory stays unpatched past the grace window. At least one version is neither a prerelease nor 0.0.x.
- The last activity is on 5 Nov 2026, 4 days ago. The rules expect an update within 365 days. Dormancy rule
What else the check found
- The latest release requires the deprecated dependency paste. RUSTSEC-2024-0436 Rot signals rule
Exact rules: Featured library. The check on applied thresholds version 9.
Every rule outcome, as the check records it
expected-interval: version 0.34.0 base 140, doubled for 16 active users, raised to the 365-day floor: E = 365 daysdormancy: last activity 2026-11-05, 4 days ago, E = 365: activerot: deprecated requirement `paste (RUSTSEC-2024-0436, https://rustsec.org/advisories/RUSTSEC-2024-0436.html)`featured: featured: active_users 16, new_adopters 15, former_glory 1
Crates4 crates
- mlx-rs Primary
- mlx-internal-macros
- mlx-macros
- mlx-sys
Measurements and sources
Each signal row shows the raw value, its source and the fetch date. The Sources list gathers every distinct source on this page. Movement needs more history.
Sources6 sources
- Description: the crates.io description
- crates.io database dump, fetched
- RustSec advisory database, fetched
- GitHub repository, fetched
- crates.io package, fetched
- GitHub contributors, fetched
Adoption16 active dependents, 15 new dependents in 365 days1 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Active dependents | 16 | crates.io database dump | Yes | |
| New dependents (365 days) | 15 | crates.io database dump | Yes | |
| Peak active dependents | 16 | crates.io database dump | Yes | |
| Active dependents as a share of the peak | 1 | crates.io database dump | Yes | |
| Binary downloads per release | Not measured | Yes |
MaintenanceLatest human commit: 4 days ago3 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Latest human commit | 2026-11-05 | GitHub repository | Yes | |
| Latest release | 2026-11-04 | crates.io database dump | Yes | |
| First release | 2024-07-13 | crates.io database dump | Yes | |
| Latest version | 0.34.0 | crates.io database dump | Yes | |
| Days the oldest outside issue waits for a reply | 4 | GitHub repository | Yes | |
| Maintainer replies over 365 days | 33 | GitHub repository | Yes | |
| Repository archived | false | GitHub repository | Yes | |
| Repository gone | false | GitHub repository | Yes | |
| Release commit or manifest in the repo | true | crates.io package | Yes | |
| Published docs | true | crates.io database dump | Yes | |
| Latest release fails cargo check | Not measured | Yes | ||
| Build check date | Not measured | Yes | ||
| Build check toolchain | Not measured | Yes |
SecurityUnpatched vulnerabilities: none
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Unpatched vulnerabilities past the grace window | none | RustSec advisory database | Yes | |
| RustSec unmaintained advisory | none | RustSec advisory database | Yes | |
| Deprecation notice | none | crates.io database dump | Yes | |
| Deprecated requirement | paste (RUSTSEC-2024-0436, https://rustsec.org/advisories/RUSTSEC-2024-0436.html) | crates.io database dump | Yes |
Distribution15 releases, 33,398 downloads over 30 days5 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Releases | 15 | crates.io database dump | Yes | |
| Downloads over 30 days | 33398 | crates.io database dump | Yes | |
| Binary downloads over the last 3 releases | Not measured | Yes | ||
| Homebrew installs on request over 365 days | Not measured | Yes | ||
| Repology repository families | Not measured | Yes | ||
| Docker pull growth over 90 days | Not measured | Yes | ||
| Docker pulls at the growth baseline | Not measured | Yes | ||
| Every version a prerelease | false | crates.io database dump | Yes | |
| Every version 0.0.x | false | crates.io database dump | Yes | |
| Every version yanked | false | crates.io database dump | Yes | |
| Crate deleted from crates.io | false | crates.io database dump | Yes |
Repository389 stars, 75 forks, 15 contributors, 449 commits. Stars alone never qualify a project.
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| GitHub stars | 389 | GitHub repository | Yes — one part of the repository route | |
| GitHub forks | 75 | GitHub repository | Yes — one part of the repository route | |
| Contributors with a GitHub account | 15 | GitHub contributors | Yes — one part of the repository route | |
| Commits on the default branch | 449 | GitHub repository | No | |
| Repository's main crate left out of the entry | none | crates.io database dump | Yes |
Facts that never count
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| License | Apache-2.0 OR MIT | crates.io database dump | No | |
| Runs on, from listed crates and their direct dependencies | Metal | crates.io database dump | No | |
| What shows each backend | Metal: mlx-rs feature metal, mlx-sys feature metal | crates.io database dump | No | |
| Native code, from listed crates and their dependencies | Binds native code: mach-sys, mlx, mlx-sys. Build uses a native toolchain: bindgen, cc, cmake | crates.io database dump | No | |
| Python bindings, from direct dependencies of listed crates | No Python binding crate found | crates.io database dump | No | |
| Crates that depend on a listed crate directly | 36 | crates.io database dump | No |
Corrections and review history
No correction applies to this entry.
Judgments
A judgment enters only through an approved issue and a merged pull request.
No judgment applies to this entry.