Skip to content

Guide · Open source

How to use MLX: install and run arrays on Apple silicon

Updated · written with AI from the project's own documentation and checked against our catalogue data

MLX is an open-source array framework for machine learning on Apple silicon, developed by Apple machine learning research. It is aimed at researchers and developers who want to build and run models on a Mac. This guide shows you how to install MLX, what its core ideas mean in practice, and where to find ready-made examples to start from.

MLXml-explore/mlx · ★ 29k · MIT

Quick start

  1. 1Check your platform. MLX is built for Apple silicon Macs. Confirm you have Python installed, since the README lists Python and pip as prerequisites.
  2. 2Install MLX. Run pip install mlx in your terminal to install the framework from PyPI.
  3. 3Learn the array API. Read the quick start guide in the documentation. If you know NumPy, most array operations will look familiar.
  4. 4Try an example. Open the MLX examples repository and run a project such as Whisper or the LLaMA text generation example.
  5. 5Build your own model. Use mlx.nn and mlx.optimizers to structure a model and train it, following the PyTorch-like API.

Install MLX with pip

MLX is published on PyPI, so you install it with pip. The README gives the command for macOS. Python is required, but the README does not state which Python version to use, so check the documentation if you need a specific one.

  • On macOS, install the framework with the standard package command.
  • On Linux, the README lists two other options: a CUDA backend and a CPU-only package.
  • To build the C++ and Python APIs from source, see the installation section of the documentation.
pip install mlx

Install the Linux variants (CUDA or CPU-only)

If you are on Linux rather than a Mac, the README describes two installs. The CUDA backend and the CPU-only package are installed with the extras shown below. Cross-platform support is narrower than general frameworks, so confirm that these options fit your hardware before you plan around them.

  • CUDA backend: install the mlx package with the cuda extra.
  • CPU-only: install the mlx package with the cpu extra.
pip install mlx[cuda] pip install mlx[cpu]

Understand the core ideas: arrays, lazy computation and unified memory

MLX has a Python API that closely follows NumPy, so array code will look familiar if you already use NumPy. Computations are lazy, which means arrays are only materialized when needed. Computation graphs are built dynamically, so changing the shapes of function arguments does not trigger slow compilations.

The most distinctive feature is unified memory. Arrays live in shared memory, and operations can run on any supported device, currently the CPU and the GPU, without transferring data between them.

  • NumPy-style array operations in Python, with C++, C and Swift APIs also available.
  • mlx.nn and mlx.optimizers provide higher-level building blocks with APIs that follow PyTorch.
  • Composable function transformations cover automatic differentiation, automatic vectorization and computation graph optimization.

Explore the examples to run real models

The MLX examples repository contains working projects you can study or adapt. The README lists a transformer language model training example, text generation with LLaMA and LoRA finetuning, image generation with Stable Diffusion, and speech recognition with OpenAI's Whisper.

Start with the quick start guide in the official documentation for a first walkthrough of the API. The examples are the fastest way to see how a full model is put together.

  • Transformer language model training
  • Text generation with LLaMA and LoRA finetuning
  • Image generation with Stable Diffusion
  • Speech recognition with Whisper

Cite MLX in research

If MLX helps your research and you want to cite it, the README provides a BibTeX entry. The software was initially developed with equal contribution by Awni Hannun, Jagrit Digani, Angelos Katharopoulos, and Ronan Collobert.

What people use it for

  • Experiment with machine learning models on a Mac with Apple silicon.
  • Run text generation with LLaMA or finetune it with LoRA using the MLX examples.
  • Transcribe speech locally with the Whisper example.
  • Generate images with the Stable Diffusion example.
  • Build bindings or applications in C++, C or Swift for Apple silicon machine learning.

Frequently asked questions

Is MLX free to use?

MLX is open source and released under the MIT licence, as stated in the project details. You can use, modify and distribute it under those terms, subject to the licence text in the repository.

What do I need to install MLX?

The README lists Python and pip as prerequisites. It does not state a specific Python version, so check the documentation for that. On macOS you install with pip install mlx.

Does MLX work on Windows?

The source does not describe Windows support. It lists CPU and GPU devices, and the Linux install options mention CUDA and CPU-only packages, so cross-platform support is narrower than general frameworks. MLX is designed for Apple silicon.

How is MLX different from PyTorch?

MLX has an API that closely follows NumPy for arrays and higher-level packages that follow PyTorch's API. Its main difference is the unified memory model, where arrays live in shared memory and can be used by the CPU or GPU without copying data.

What are the alternatives to MLX?

The README names PyTorch, JAX, TinyGrad and ArrayFire as comparable projects. Choose one of these if you need broader hardware support or a different ecosystem.

Can I run LLaMA or Whisper with MLX?

Yes, the MLX examples repository includes LLaMA text generation with LoRA finetuning and speech recognition with OpenAI's Whisper. These are examples built on the framework, not separate applications.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

MLX suits researchers and developers on Apple silicon Macs who already know NumPy or PyTorch and want a familiar API with unified memory. It is not the right choice if you need to deploy on Windows or non-Apple hardware, or if you want a finished end-user app rather than a framework for building models.

Install options & downloads