How I Changed 13 Lines of MLX Code for a 20% Speedup Running LLMs Locally on a Mac
mlx-lm's server was reading a number it didn't need on every single token. That one read stopped the CPU and GPU from working at the same time. Taking it out made a 35B model on my M1 Max about 20% faster.

Over the weekend I was pairing with my coding pal Opus 5.5 on local LLM optimisation. The goal was simple: find out which engine runs a big model fastest on my M1 Max with 64 GB. We lined up mlx-lm against Ollama (GGUF with MTP, and MLX NVFP4), BaseRT and ZMLX, and started benchmarking.
I expected the result to be a ranking. Instead it was a bug.
Something was making the CPU wait
mlx-lm is Apple's own LLM library for Apple Silicon, and mlx_lm.server is its OpenAI-compatible server. It should be one of the fastest options on a Mac. It was slower than it had any reason to be.
Here is why. Generating text is a loop: the GPU computes one token, then the next, then the next. MLX is clever about this. Before it hands you the current token, it has already queued up the work for the next one with mx.async_eval. So while the GPU is busy, the CPU gets on with building the step after that. The two run side by side.
Unless something makes the CPU stop and wait.
That something was one line in the server:
logprobs[token].item()
It runs on every generated token. .item() pulls a value out of the GPU and back into Python, which means it has to wait until the GPU has finished. Every token, the CPU stops, waits for the GPU, then carries on. The side-by-side overlap is gone.
The annoying part is that the value was a logprob, the model's confidence in the token it picked. Most requests never ask for logprobs. The server was waiting for a number it then threw away.
The fix
Only read the logprob when the request actually asks for it.
That's the whole idea. In practice it touches both code paths in the server: the batched one, and the single-request one used when you pass a seed, kv_bits or a draft model. It's 13 lines in mlx_lm/server.py, plus one test that fails on the current code and passes with the fix. When you do ask for logprobs, you get exactly the same values as before, bit for bit.
How much faster
Tokens per second on the M1 Max, before and after:
| Model | Run | Before | After | Change |
|---|---|---|---|---|
| Qwen3.6-35B-A3B | 1 request at a time | 59.0 | 70.0 | +18.6% |
| Qwen3.6-35B-A3B | 4 requests at a time | 103 | 119 | +15.5% |
| Qwen3.6-35B-A3B | seeded single request | 61.1 | 73.3 | +20.0% |
| 0.5B | 1 request at a time | 274.0 | 319.0 | +16.4% |
| 0.5B | 4 requests at a time | 429.5 | 606.5 | +41.2% |
On the 35B model, the one you'd actually use for real work, that's 15 to 20%. I ran the "before" numbers a second time and they moved by a point or two, so treat those as the honest range.
The 41% looks great in a headline, but it's only the tiny 0.5B model with four requests at once. I'm not going to claim that for anything bigger.
Where it stands
I've opened it as PR #1950 on mlx-lm. It's not merged yet. A maintainer wants to land a refactor of the server code first, so it's on hold until then.
I've since re-run it on an M5 Pro: +15% on the 35B model with one request at a time, and +9% with four at once.
For the record on who did what: Opus 5.5, running in Claude Code, found the blocking read and wrote the fix and the test. I reviewed it, checked the numbers held up and submitted it.
The bit I keep coming back to is how small it was. One blocking call per token, in a loop that runs on every token you ever generate. If you're running models locally, it's worth asking what else in your stack is quietly making the CPU wait.