Skip to content
Inference Academy

MLX vs llama.cpp on Apple Silicon

Both run LLMs on a Mac's GPU. How they differ in model formats, quantisation, speed, memory and tooling, with the bandwidth maths that sets the speed limit on every Mac, the commands to benchmark both fairly, and which to pick for chat, coding, long prompts and fine-tuning.

Key takeaways

  • MLX and llama.cpp both run models on a Mac's GPU with the same unified memory and bandwidth, so the differences are in software.
  • llama.cpp uses GGUF files with many quantisation levels and runs on almost every platform; MLX is Apple Silicon only and mostly 4-bit and 8-bit.
  • MLX is often slightly faster for the same model and bit width, but the gap varies by model and version.
  • Compare fairly: same model and bit width, same prompt and output length, warm up, take the median, and check quality too.
  • Choose llama.cpp for Ollama and cross-platform setups, MLX for the last bit of Mac speed or LoRA fine-tuning.

By

7 min read

Share
On this page

On a Mac you have two first-class ways to run open models on the GPU: llama.cpp (directly, or through Ollama, LM Studio and Jan) using Metal, and MLX, Apple's own array framework, through mlx-lm or LM Studio's MLX engine. Both use the same unified memory and the same memory bandwidth, so the differences are in software: file formats, quantisation schemes, kernels and the tools built around each.

This guide explains where the speed limit on a Mac comes from, how the two engines differ, how to benchmark them fairly, and which one to pick for common jobs.

#Side by side

llama.cpp (Metal) MLX (mlx-lm)
Who builds it Open-source community, started by Georgi Gerganov Apple's machine learning research team, open source
Model format GGUF (one file, weights plus metadata) MLX safetensors (converted from Hugging Face weights)
Quantisation Many levels: Q2 to Q8, K-quants, i-quants Mostly 4-bit and 8-bit (plus some others), group-wise
Typical decode speed Close to the bandwidth limit Often slightly faster for the same model and bit width, varies by model and version
Prompt processing Good Often good to better on recent versions
Other platforms Everywhere (CUDA, ROCm, Vulkan, CPU) Apple Silicon only
Fine-tuning Not its focus LoRA fine-tuning built into mlx-lm
Ecosystem Ollama, LM Studio, Jan, many front ends LM Studio, Python scripts, a basic OpenAI-compatible server
Language C and C++ Python front end over C++ and Metal

#Why the hardware sets the same limit for both

When a model generates text, each new token requires reading every weight once from memory (why memory bandwidth decides LLM speed). On a Mac, the CPU and GPU share one pool of unified memory, and its bandwidth is the speed limit for both engines:

Chip Memory bandwidth
M4 120 GB/s
M4 Pro 273 GB/s
M3 Max (top configuration) 400 GB/s
M4 Max (top configuration) 546 GB/s
M2 Ultra 800 GB/s
M3 Ultra 819 GB/s

These are Apple's published figures. Lower-binned Max chips have less bandwidth, so check your exact configuration.

A rough ceiling for generation speed is bandwidth divided by model size, times the share of peak bandwidth an engine actually reaches (about 60 to 80% is typical):

tokens per second≈0.7×bandwidthmodel size in bytes\text{tokens per second} \approx \frac{0.7 \times \text{bandwidth}}{\text{model size in bytes}}

Worked example. An 8B model at about 4.5 bits per weight is roughly 4.6 GB. On an M4 Max with 546 GB/s:

0.7×5464.6≈83 tokens per second\frac{0.7 \times 546}{4.6} \approx 83 \ \text{tokens per second}

A 70B model at the same precision is about 40 GB. On an M3 Ultra with 819 GB/s, the ceiling is about 0.7×819/40≈140.7 \times 819 / 40 \approx 14 tokens per second.

Neither engine can beat this ceiling; they differ in how close they get. That's why the speed gap between MLX and llama.cpp is usually a few percent to perhaps 20%, not a factor of two. If someone reports a much bigger gap, check that they compared the same model at the same size.

#Quantisation: "4-bit" isn't one thing

Both engines store weights in small groups, each with its own scale, so the real bits per weight are higher than the headline number:

Scheme Engine Approximate bits per weight
MLX 4-bit, group size 64 MLX about 4.5 (4 bits plus a scale and bias per group)
Q4_0 llama.cpp about 4.5
Q4_K_M llama.cpp about 4.8 to 4.9 (mixes 4-bit and 6-bit blocks)
MLX 8-bit MLX about 8.5
Q8_0 llama.cpp about 8.5

Two consequences:

  1. A Q4_K_M file is a little bigger than an MLX 4-bit file of the same model, so it reads a little more memory per token and will be a little slower even with identical kernels. That's not a fair speed test.
  2. Quality differs too. Q4_K_M keeps some sensitive layers at higher precision, which usually helps quality. Different schemes lose different things, so compare quality as well as speed (which quantisation should you pick).

For the fairest speed comparison, match file size, not the label. MLX 4-bit against Q4_0 is closer than MLX 4-bit against Q4_K_M.

#Prompt processing is a different story

Generation is limited by bandwidth; reading a long prompt (prefill) is limited by compute, because thousands of tokens are processed in parallel (prefill vs decode). Mac GPUs have far less matrix-multiply throughput than data-centre NVIDIA GPUs, so long prompts are where Macs feel slow: a 20,000-token document can take many seconds before the first word appears.

This is where kernel quality matters most, and where the two engines have traded the lead across versions. Apple's newest chips add matrix acceleration inside the GPU, and recent MLX versions are built to use it, so check current numbers on your own machine if long prompts matter to you (coding assistants, document chat, RAG).

#Memory: how much of your Mac can the GPU use?

By default, macOS lets the GPU use only part of unified memory (roughly two-thirds to three-quarters, depending on the total). On a 64 GB Mac, that may be about 48 GB for model plus KV cache. You can raise the limit until the next reboot:

bash
sudo sysctl iogpu.wired_limit_mb=57344

That example allows 56 GB. Leave enough for macOS and your other apps, or the system will start swapping and everything slows down.

Both engines also support a smaller KV cache for long contexts (KV cache explained):

  • llama.cpp: --cache-type-k q8_0 --cache-type-v q8_0 (with flash attention enabled) roughly halves KV memory.
  • MLX: --kv-bits quantises the cache, and --max-kv-size caps it with a rotating window.

#How to benchmark both fairly

The speed difference is usually small, so test it properly (measuring speed).

llama.cpp has a built-in benchmark that reports prompt processing (pp) and text generation (tg) separately:

bash
llama-bench -m Llama-3.1-8B-Instruct-Q4_0.gguf -p 512 -n 128 -r 5

MLX prints prompt and generation speed after each run:

bash
mlx_lm.generate --model mlx-community/Meta-Llama-3.1-8B-Instruct-4bit \
  --prompt "$(cat prompt-512-tokens.txt)" --max-tokens 128

Then follow these rules:

  1. Same model, same size. Compare files of similar size, as explained above.
  2. Same prompt length and output length, and record prompt processing and generation separately.
  3. Warm up first, then run at least five times and take the median.
  4. Close memory-hungry apps, and keep the laptop plugged in; macOS throttles on battery.
  5. Test at your real context length. Speed at 512 tokens says little about speed at 16,000.
  6. Check quality as well as speed. Run a few of your own prompts through both, or a small quality check.
  7. Record versions of both engines and macOS. Both projects improve quickly, and a result from six months ago may already be out of date.

#Features beyond raw speed

Feature llama.cpp MLX
OpenAI-compatible server llama-server, mature, with parallel slots mlx_lm.server, simpler
Speculative decoding Yes (-md draft model) Yes (--draft-model)
Grammar and JSON output Yes (GBNF grammars, JSON schema) Via libraries such as Outlines
Vision models Yes, for many model families Via mlx-vlm
LoRA fine-tuning Limited Built in (mlx_lm.lora), including QLoRA-style 4-bit bases
Model conversion convert_hf_to_gguf.py then llama-quantize mlx_lm.convert --hf-path ... -q
Pre-converted models Huge choice of GGUF uploads The mlx-community organisation on Hugging Face

#Which to choose

Your situation Pick
You use Ollama, or want one setup that also works on Linux and Windows llama.cpp
You need an unusual quantisation level to squeeze a model into memory (Q3, Q5, i-quants) llama.cpp
You want JSON or grammar-constrained output from a local server llama.cpp
You want the last bit of decode speed on a Mac MLX (measure it)
You want to fine-tune with LoRA on the same machine MLX
You're writing Python research code against the model MLX
You don't want to choose LM Studio runs either engine; switch and measure

#Common mistakes

  • Comparing different file sizes and calling it an engine comparison.
  • Testing a 100-token prompt when your real use is 10,000-token documents.
  • Ignoring the GPU memory limit, then blaming the engine when a model that "should fit" falls back to slow paths or fails to load.
  • Running on battery or with other heavy apps open.
  • Assuming last year's benchmark still holds. Both engines change monthly.

#FAQ

Is MLX always faster than llama.cpp on a Mac? No. It's often slightly faster at the same bit width, but the gap depends on the model, the quantisation, the context length and the versions. Measure your own case.

Can I use the same model file in both? No. llama.cpp uses GGUF; MLX uses its own safetensors layout. Both are converted from the same Hugging Face weights, and many popular models are available pre-converted for both.

Does Ollama use MLX? Ollama is built on llama.cpp's engine. LM Studio offers both llama.cpp and MLX engines.

What size model can my Mac run? Roughly, the model file plus KV cache must fit within the GPU's share of memory. See how much VRAM do you need and the model picker.

#Go deeper

More detail, with commands, is in MLX on Apple Silicon and Apple Silicon for LLMs. For tuning either engine on a Mac, see platform tuning.

comparisonapple-siliconmlxllama.cpp

Found this useful?

Send it to someone who is learning the same thing.

Share this article

Next: learn it step by step, free

Engines compared from the inside

How vLLM, SGLang, TensorRT-LLM and llama.cpp schedule, batch and cache, side by side. A free lesson with step-through diagrams and a quiz.

Get new articles by email

One short email when a new guide is out. Unsubscribe any time.