# What is MLX?

> MLX is Apple's machine learning framework for Apple silicon. On a Mac it is often the fastest way to run a model.

MLX is an open-source array framework from Apple's machine learning research team. It runs only on Apple silicon, and on that hardware it is often the fastest engine you can use.

## Apple's framework

MLX is to Apple silicon roughly what PyTorch is to NVIDIA GPUs. It is a general library for building and running models, with a Python API and a C++ core. It lives at [github.com/ml-explore/mlx](https://github.com/ml-explore/mlx) under the MIT licence.

For running language models you use a companion package called **mlx-lm**. It loads models, generates text, runs a local server and converts models to MLX format.

MLX models are a separate format from GGUF. They are folders of safetensors files plus a config. The `mlx-community` organisation on Hugging Face hosts thousands of them, usually labelled `4bit`, `6bit` or `8bit`. [What is quantization?](https://localagi.co/quantization) explains the labels.

**The catch.** 
MLX does nothing on Windows, Linux or an Intel Mac. If you want one setup across machines, [llama.cpp](https://localagi.co/llama-cpp) is the portable choice.

## Why it is often fastest on a Mac

MLX was written for one chip family, so it carries no compromises for others. Its kernels target Apple's GPU through Metal directly and are built around [unified memory](https://localagi.co/memory), where the CPU and GPU share one pool with no copying.

In practice, the same model at the same bit width usually decodes faster in MLX than as a GGUF in llama.cpp on the same Mac. The gap varies by model and chip, and llama.cpp's Metal backend closes it on some models. Prefill on long prompts is where MLX tends to pull furthest ahead.

**Rule of thumb.** 
On a Mac, try the MLX build of a model first. If an app offers both, compare them on your own prompts with [a quick benchmark](https://localagi.co/benchmarking).

New Apple chips also get MLX support early, because the same company builds both. [Is a Mac good for local AI?](https://localagi.co/apple-silicon) covers which chips have the bandwidth to make this matter.

## mlx-lm from the command line

Install it with pip into a Python environment.

```bash
pip install mlx-lm
```

Generate one answer. The first run downloads the model from Hugging Face.

```bash
mlx_lm.generate --model mlx-community/Qwen3-8B-4bit --prompt "Explain unified memory in two sentences."
```

The command prints the answer, then the prompt speed, the generation speed and the peak memory used. That last line is a quick way to check a model fits.

For a back-and-forth chat in the terminal:

```bash
mlx_lm.chat --model mlx-community/Qwen3-8B-4bit
```

To serve the [OpenAI-compatible API](https://localagi.co/local-api):

```bash
mlx_lm.server --model mlx-community/Qwen3-8B-4bit --port 8080
```

**The catch.** 
`mlx_lm.server` and `llama-server` both default to port 8080. Run them side by side and one fails to start. Pass a different `--port` to one of them.

**Try it.** 

```bash
mlx_lm.generate --model mlx-community/Qwen3-8B-4bit --prompt "Write a haiku about memory bandwidth." --max-tokens 100
```

## Apps that use it

You do not need a terminal to use MLX. Several apps run it for you.

- [LM Studio](https://localagi.co/lm-studio) ships an MLX engine next to llama.cpp. It picks MLX when you download an MLX build of a model.
- mlx-lm's own server, above, works with any chat app that speaks the OpenAI API, such as Open WebUI.
- A number of smaller Mac-only apps wrap MLX as well. [Which chat app should I use?](https://localagi.co/chat-apps) lists the main ones.

## Go deeper

### Lazy evaluation

MLX does not run an operation when you write it. It builds a graph and runs it only when a result is needed. That lets it fuse steps together and skip work, which helps on a GPU where launching many small kernels is costly.

### Converting your own models

mlx-lm can convert a Hugging Face model and quantize it in one step.

```bash
mlx_lm.convert --hf-path Qwen/Qwen3-8B -q
```

The `-q` flag quantizes to 4-bit by default. The result is a local folder you can pass to `--model`. Most people never need this, because `mlx-community` has already done it.

### Fine-tuning on a Mac

mlx-lm also trains LoRA adapters with `mlx_lm.lora`. Unified memory means a Mac with plenty of RAM can fine-tune models that would not fit on a consumer GPU. It is slower than a data-centre GPU, but it runs. [Should I fine-tune a model?](https://localagi.co/fine-tuning) covers when that is worth doing.

### Memory limits

macOS caps how much unified memory the GPU may use, leaving the rest for the system. A model that nearly fills your RAM can fail to load even though the numbers look close. [Will the model fit in my memory?](https://localagi.co/memory) covers the headroom to leave.
