mlx-rs

Library Featured

Unofficial rust wrapper for Apple's mlx machine learning library.

Checked · Sources

Downloads
33,398
Dependents
36
Stars
389
Forks
75
Contributors
15
Commits
449
Latest release
0.34.0 ·

About

From the project README ·

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 MLX
  • accelerate - 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-rsMLX
0.340.32.2
0.330.32.2
0.320.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.

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.

mlx-rs beside the projects that share a topic with it
ProjectDownloadsDependentsStarsLatest releaseRuns on (GPU)Native codeLicense
mlx-rs This page Featured

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
mpsgraph-rs Listed Dormant

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
autograph Listed Dormant

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
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

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 days
  • dormancy: last activity 2026-11-05, 4 days ago, E = 365: active
  • rot: 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

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
Adoption16 active dependents, 15 new dependents in 365 days1 not measured
Adoption measurements
SignalValueSourceFetchedCounts
Active dependents16crates.io database dumpYes
New dependents (365 days)15crates.io database dumpYes
Peak active dependents16crates.io database dumpYes
Active dependents as a share of the peak1crates.io database dumpYes
Binary downloads per releaseNot measuredYes
MaintenanceLatest human commit: 4 days ago3 not measured
Maintenance measurements
SignalValueSourceFetchedCounts
Latest human commit2026-11-05GitHub repositoryYes
Latest release2026-11-04crates.io database dumpYes
First release2024-07-13crates.io database dumpYes
Latest version0.34.0crates.io database dumpYes
Days the oldest outside issue waits for a reply4GitHub repositoryYes
Maintainer replies over 365 days33GitHub repositoryYes
Repository archivedfalseGitHub repositoryYes
Repository gonefalseGitHub repositoryYes
Release commit or manifest in the repotruecrates.io packageYes
Published docstruecrates.io database dumpYes
Latest release fails cargo checkNot measuredYes
Build check dateNot measuredYes
Build check toolchainNot measuredYes
SecurityUnpatched vulnerabilities: none
Security measurements
SignalValueSourceFetchedCounts
Unpatched vulnerabilities past the grace windownoneRustSec advisory databaseYes
RustSec unmaintained advisorynoneRustSec advisory databaseYes
Deprecation noticenonecrates.io database dumpYes
Deprecated requirementpaste (RUSTSEC-2024-0436, https://rustsec.org/advisories/RUSTSEC-2024-0436.html)crates.io database dumpYes
Distribution15 releases, 33,398 downloads over 30 days5 not measured
Distribution measurements
SignalValueSourceFetchedCounts
Releases15crates.io database dumpYes
Downloads over 30 days33398crates.io database dumpYes
Binary downloads over the last 3 releasesNot measuredYes
Homebrew installs on request over 365 daysNot measuredYes
Repology repository familiesNot measuredYes
Docker pull growth over 90 daysNot measuredYes
Docker pulls at the growth baselineNot measuredYes
Every version a prereleasefalsecrates.io database dumpYes
Every version 0.0.xfalsecrates.io database dumpYes
Every version yankedfalsecrates.io database dumpYes
Crate deleted from crates.iofalsecrates.io database dumpYes
Repository389 stars, 75 forks, 15 contributors, 449 commits. Stars alone never qualify a project.
Repository measurements
SignalValueSourceFetchedCounts
GitHub stars389GitHub repositoryYes — one part of the repository route
GitHub forks75GitHub repositoryYes — one part of the repository route
Contributors with a GitHub account15GitHub contributorsYes — one part of the repository route
Commits on the default branch449GitHub repositoryNo
Repository's main crate left out of the entrynonecrates.io database dumpYes
Facts that never count
Facts that never count measurements
SignalValueSourceFetchedCounts
LicenseApache-2.0 OR MITcrates.io database dumpNo
Runs on, from listed crates and their direct dependenciesMetalcrates.io database dumpNo
What shows each backendMetal: mlx-rs feature metal, mlx-sys feature metalcrates.io database dumpNo
Native code, from listed crates and their dependenciesBinds native code: mach-sys, mlx, mlx-sys. Build uses a native toolchain: bindgen, cc, cmakecrates.io database dumpNo
Python bindings, from direct dependencies of listed cratesNo Python binding crate foundcrates.io database dumpNo
Crates that depend on a listed crate directly36crates.io database dumpNo

Corrections and review history

Report a correction

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.