4 releases

0.21.0 Feb 3, 2025
0.21.0-rc.2 Jan 31, 2025
0.21.0-rc.1 Jan 19, 2025
0.14.0 Jul 13, 2024

#86 in Machine learning

Download history 2/week @ 2024-12-10 92/week @ 2025-01-14 12/week @ 2025-01-21 176/week @ 2025-01-28 85/week @ 2025-02-04

365 downloads per month

MIT/Apache

1.5MB
33K SLoC

Rust 24K SLoC // 0.0% comments C++ 7.5K SLoC // 0.0% comments Python 1K SLoC // 0.5% comments C 320 SLoC // 0.0% comments

mlx-rs

Rust bindings for Apple's mlx machine learning library.

Discord Current Crates.io Version Documentation Test Status Blaze Rust Version license

⚠️ 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:

  • 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.21.0"

Feature Flags

  • metal - enables metal (GPU) usage in MLX
  • accelerate - enables using the accelerate framework in MLX

Versioning

For simplicity, the main crate mls-rs follows MLX’s versioning, allowing you to easily see which MLX version you’re using under the hood. The mlx-sys crate follows the versioning of mlx-c, as that is the version from which the API is generated.

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

Dependencies

~2.2–10MB
~110K SLoC