Repolode
ml-explore

ml-explore/mlx-swift

Swift API for MLX, the array framework for machine learning on Apple silicon, letting Swift developers run ML research and experiments.

Stars
2,066
Forks
371
Open issues
56
Last commit
20 hours ago

What is it?

MLX Swift wraps MLX, an array framework for machine learning on Apple silicon, so that Swift code can use the same array, neural network and optimizer building blocks. It is distributed as a Swift package that exposes libraries such as MLX, MLXNN, MLXOptimizers and MLXRandom.

The package can be added through Xcode or SwiftPM and built with xcodebuild, which is needed to compile Metal shaders on macOS. A CMake build is also provided, including a native Linux path with a CPU backend and an optional CUDA GPU backend.

LLM and VLM implementations live in a separate mlx-swift-lm project, and the mlx-swift-examples repository contains sample apps such as an MNIST trainer, a chat app and a Stable Diffusion example.

Key features

  • 01Provides Swift access to the MLX array framework for Apple silicon
  • 02Ships MLX, MLXNN, MLXOptimizers and MLXRandom as separate Swift package products
  • 03Installable via Xcode or SwiftPM, with xcodebuild needed for Metal shaders
  • 04CMake build with native Linux support, including CPU and CUDA GPU backends

Use cases

  • Running machine learning experiments natively in Swift on a Mac or iOS device
  • Building an on-device app that trains or runs small neural networks on Apple silicon
  • Porting MLX Python research code to a Swift codebase

Quick start

  1. 1

    Add the mlx-swift package to your Package.swift

    .package(url: "https://github.com/ml-explore/mlx-swift", from: "0.10.0")
  2. 2

    Add the MLX, MLXNN and MLXOptimizers libraries as target dependencies

  3. 3

    Clone the repo and pull the submodules before building locally

    git submodule update --init --recursive
  4. 4

    Build and run the tests with Xcode's command-line tool

    xcodebuild test -scheme mlx-swift-Package -destination 'platform=OS X'

Things to know

  • Targets Apple silicon; the main Metal GPU backend is macOS-focused.
  • SwiftPM on the command line cannot build the Metal shaders, so the full build requires Xcode.
  • Linux builds use the CPU backend by default, and CUDA support is Linux-only.

Topics

FAQ

What is mlx-swift?
Swift API for MLX, the array framework for machine learning on Apple silicon, letting Swift developers run ML research and experiments. MLX Swift wraps MLX, an array framework for machine learning on Apple silicon, so that Swift code can use the same array, neural network and optimizer building blocks. It is distributed as a Swift package that exposes libraries such as MLX, MLXNN, MLXOptimizers and MLXRandom.
Is mlx-swift free to use? What license does it have?
mlx-swift is open source under the MIT license. Check the license terms before using it in commercial products.
Is mlx-swift still maintained?
Actively maintained. The last commit to mlx-swift was on Oct 19, 2026.
What can I use mlx-swift for?
Running machine learning experiments natively in Swift on a Mac or iOS device Building an on-device app that trains or runs small neural networks on Apple silicon Porting MLX Python research code to a Swift codebase
How do I install mlx-swift?
Add the mlx-swift package to your Package.swift: .package(url: "https://github.com/ml-explore/mlx-swift", from: "0.10.0") Add the MLX, MLXNN and MLXOptimizers libraries as target dependencies Clone the repo and pull the submodules before building locally: git submodule update --init --recursive Build and run the tests with Xcode's command-line tool: xcodebuild test -scheme mlx-swift-Package -destination 'platform=OS X'
Where can I get mlx-swift?
The source code and installation instructions are on GitHub: https://github.com/ml-explore/mlx-swift

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects