GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - InftyAI/mlx: Rust bindings for Apple's MLX framework.

BranchesTags
Open more actions menu

Latest commit

 

History

25 Commits
25 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
crates
crates
 
 
hack
hack
 
 
.dockerignore
.dockerignore
 
 
.gitignore
.gitignore
 
 
.gitmodules
.gitmodules
 
 
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
Cargo.lock
Cargo.lock
 
 
Cargo.toml
Cargo.toml
 
 
Dockerfile
Dockerfile
 
 
LICENSE
LICENSE
 
 
Makefile
Makefile
 
 
OWNERS
OWNERS
 
 
README.md
README.md
 
 

Repository files navigation

MLX

crates.io License Discord

Rust bindings for Apple's MLX framework.

Platform: Apple Silicon (macOS) only.

Installation

cargo add mlxcore

Quick start

use mlxcore::{Array, Stream};

fn main() -> mlxcore::Result<()> {
    let s = Stream::default();

    // The `f32` suffix matters — see the note further down.
    let x = Array::from_slice(&[1.0f32, 4.0, 9.0], &[3]);

    println!("{:?}", x.sqrt(&s)?.to_vec::<f32>()); // [1.0, 2.0, 3.0]
    println!("{:?}", (&x * 2.0f32).to_vec::<f32>()); // [2.0, 8.0, 18.0]

    Ok(())
}

Architecture

The bindings are layered, the same way as MLX Swift:

mlxcore      (safe, idiomatic Rust API)   <- crates/mlxcore
mlxcore-sys  (raw unsafe FFI bindings)    <- crates/mlxcore-sys, generated by bindgen
mlx-c        (Apple's C API for MLX)      <- crates/mlxcore-sys/third_party/mlx-c (git submodule)
mlx          (Apple's C++ framework)      <- fetched by mlx-c's CMake build

MLX itself is C++, which Rust cannot bind to directly. We bind against mlx-c, Apple's official C API, whose CMake build pulls in MLX via FetchContent.

The mlx-c submodule sits inside mlxcore-sys rather than at the repository root because cargo package only ships files under the crate directory — from the root it would be missing from the published crate.

Within mlxcore, the modules follow the mlx-c headers they wrap:

Module Wraps Holds
Array (crate root) array.h, ops.h array construction, arithmetic, reductions, shapes, indexing
mlxcore::fast fast.h fused kernels: layer_norm, rms_norm, rope, scaled_dot_product_attention
mlxcore::io io.h load_safetensors / save_safetensors
mlxcore::random random.h seeded keys, uniform, normal

Building from source

git submodule update --init --recursive
make build
make test

Requirements: a recent Rust toolchain, make, cmake, and Xcode command-line tools. The first build compiles MLX from source and takes several minutes.

Examples

Runnable examples live in crates/mlxcore/examples:

cargo run --example hello       # arrays, shapes, streams
cargo run --example relu        # y = relu(x @ W + b) with random weights
cargo run --example attention   # a transformer attention block: QKV, RoPE, masked SDPA

Note: suffix float literals with f32

Unsuffixed float literals are f64 in Rust, and Apple GPUs have no float64 support. Since the default stream is the GPU, &[1.0, 2.0] builds an array that fails on every operation. Write &[1.0f32, 2.0], and &a * 2.0f32 for scalars.

float64 still works on an explicit Stream::cpu().

Features

  • metal (default) — GPU backend via Metal.
  • accelerate (default) — CPU BLAS via Apple's Accelerate framework.

About

Rust bindings for Apple's MLX framework.

Topics

apple-siliconmlxrust

Resources

Readme
MIT license

Code of conduct

Code of conduct

Contributing

Contributing
Activity
Custom properties

Stars

3 stars

Watchers

0 watching

Forks

1 fork
Report repository

Releases

Packages

Contributors

Languages

Generated from InftyAI/template-repo
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.