MLX on Apple silicon

I explore how the MLX framework optimizes the performance of large language models on Apple Silicon.

Categories:AI

A topic page: a summary of what my posts say, with each claim quoted from the post it came from. The posts are the authority. Last checked 2026-11-06.

Summary. I explore how the MLX framework optimizes the performance of large language models on Apple Silicon. I demonstrate that MLX provides significant speed and memory advantages over PyTorch by leveraging unified memory and compiled training steps.

What the posts say

MLX is a framework designed for Apple silicon.

β€œMLX is an array framework designed for efficient and flexible machine learning research on Apple silicon.” β€” MLX 1

The MLX engine provides a significant speed advantage when the training step is compiled.

β€œWith it, MLX is about a quarter faster than itself, and 16% faster than PyTorch.” β€” MiniGPT (Part 4)

MLX uses less memory than PyTorch for the exact same machine and task.

β€œMLX uses less memory either way: 3.7 to 3.9 GB against PyTorch's 4.6 GB, about 15 to 20% less for exactly the same machine.” β€” MiniGPT (Part 4)

MLX avoids memory copying because Apple chips share a single pool of memory.

β€œMLX is built around that, so there is nothing to copy and no .to(device) anywhere: the training batch goes straight into an MLX array, and the GPU reads it where it is.” β€” MiniGPT (Part 4)

Lazy evaluation allows MLX to see the full list of steps before it starts.

β€œThat sounds like a delay, but it gives MLX the whole list of steps before it starts, so it can see which ones can be done together, and which ones are never needed at all.” β€” MiniGPT (Part 4)

The results from both the PyTorch and MLX versions are nearly identical.

β€œBut they should end up in the same place, and they do: after 3,000 steps, the MLX machine scores 0.689 bits per byte on the test stories, and the PyTorch machine from Part 3 scores 0.697.” β€” MiniGPT (Part 4)

I used a specific python command to fuse the model.

β€œI ran python -m mlx_lm fuse to create the fused model” β€” MLX 1

I converted the model to GGUF format for compatibility.

β€œI ran convert_hf_to_gguf.py to convert the fused model to GGUF format” β€” MLX 1

The posts behind this page

  • MiniGPT (Part 4) β€” The same machine on a faster engine: rebuilding MiniGPT in Apple's MLX, what one shared pool of memory, lazy calculation, and compiling the training step buy, and a fair race against PyTorch on the same Mac, with a follow-along notebook
  • MiniGPT (Part 5) β€” The block inside today's small models: four changes Meta made for Llama (RMSNorm, rotary positions, SwiGLU, and shared keys and values), each turned back off in turn to find out which one actually matters, with a follow-along notebook
  • MiniGPT (Part 6) β€” Learning from a teacher: training a small MiniGPT to copy a bigger model's whole wheel of chances, why the teacher must share the student's pieces, and a tested finding: the most helpful teacher was not the best storyteller, but the one whose wheels the student could copy, with a follow-along notebook
  • MiniGPT (Part 7) β€” Reading a longer row in the same memory: why attention's cost grows with the square of the row, how a sliding window caps it, why writing the window as a mask saves nothing, and a secret-word test of what a long row is for, and of how far a window really reaches, with a follow-along notebook
  • Distillation (Part 2) β€” Turning a pretrained base model into a chat model with LoRA on a 64GB Mac Studio, then testing whether a second teacher, DeepSeek, produces a better one than GPT-3.5 did
  • Distillation (Part 1) β€” How DeepSeek stands accused of breaking OpenAI's terms of service.
  • MLX 1 β€” Using Apple's MLX framework to run and fine-tune large language models efficiently on Apple Silicon Macs