mlx

Dart bindings for Apple's MLX array framework on Apple Silicon, via FFI to mlx-c.

Provides the MlxArray tensor type with a DType system and lazy eval; the ops surface (elementwise math, matmul, reductions, FFT, channels-last convolutions, group-wise quantization); keyed random sampling; safetensors I/O; and an MLXNN-style neural-network layer (Module, linear / conv / embedding / norm / RNN layers, KV-cache) whose parameter names match MLX-converted checkpoints 1:1.

Platform: macOS on Apple Silicon only.

Install

dart pub add mlx
dart run mlx:setup

dart run mlx:setup builds the native mlx-c libraries once and installs them into a user-level cache (~/Library/Caches/mlx-dart/<tag>/, override the base with MLX_DART_CACHE); the loader finds them automatically afterwards — no environment variables required. It is idempotent (re-running is a no-op until the pinned mlx-c tag changes; --force rebuilds). The build clones and compiles MLX + mlx-c, so it needs git, cmake, and the Xcode command line tools, and takes a couple of minutes the first time.

Usage

import 'package:mlx/mlx.dart';

void main() {
  final a = MlxArray.fromList(<double>[1, 2, 3, 4], <int>[2, 2]);
  final b = ones(<int>[2, 2]);
  final c = matmul(a, b);
  eval(<MlxArray>[c]); // MLX is lazy — force evaluation before reading.
  print(c);
}

See example/example.dart for a runnable version.

Libraries

mlx
Dart FFI bindings to mlx-c for running MLX on Apple Silicon.