Running Qwen 3.8 27B on a 24 GB MacBook Pro with MLX and llama.cpp
With a roughly 3,100-token prompt, my Qwen 3.8 27B setup took about 24 seconds to stream 256 tokens on llama.cpp and about 20 seconds on MLX. Most of the saving came before the stream started. llama.cpp long-prompt runs · MLX long-prompt runs
My first benchmark with the default MLX settings froze the Mac and ended in a watchdog reboot. I recorded these timings on a later run with memory limits in place. Benchmark repository
The Mac and the two model builds
I ran one server at a time on a MacBook Pro with an 18-core M5 Pro and 24 GB of unified memory. The local panic report lists chip identifier T6050 and macOS build 26B131. The model files alone are about 16 GB. During inference, the model weights, the state saved for the tokens already processed, and temporary GPU buffers all use the same physical memory as macOS. MLX unified memory documentation
With the default macOS GPU limit, loading the model failed with Insufficient Memory. For both servers I set iogpu.wired_limit_mb=20480 to raise the limit on how much memory the GPU can keep resident. Benchmark setup
llama.cpp | MLX | |
|---|---|---|
Runtime | llama.cpp b12774 with Metal |
|
Weight conversion | Unsloth UD-Q4_K_M GGUF, 16.6 GB | MLX Community 4-bit, 16.05 GB across three weight files |
Context memory | Reserves a 65,536-token context at startup with 8-bit ( | Allocates cache as the context grows. The key-value cache stays at its original precision for the lengths tested. |
Startup configuration |
Both builds come from the same Qwen checkpoint. Unsloth's GGUF stores different weight tensors at different precisions. The MLX build uses 4-bit affine quantization, where each group of 64 quantized weights shares a scale and an offset. Switching servers also changed the weight files and the context cache settings, so the timings compare two complete setups. Qwen model card · Unsloth conversion · MLX quantization config · MLX quantization API
How I timed each request
The same Python script sent one request at a time to each running server's /v1/chat/completions endpoint. Each request started with a new ID and a randomly generated list of 20 or 3,000 words, followed by the same instruction to write a long essay about computing history. I discarded one warm-up per prompt size and took the median of three timed requests. The script set temperature to 0 and both servers reported 256 output tokens on every timed request. Prompt and request code · Run and median calculation
I timed requests from the client after the model had loaded. Time to first token runs from the start of the HTTP request to the first chunk carrying text or reasoning. That can be earlier than the first visible answer text. Effective prefill divides the prompt-token count by that delay, so it includes request overhead and the first step of generation as well as prompt processing. Generation speed measures the remaining 255 tokens from the first chunk to the last. Total time runs from request start to the last such chunk. Timing code
Each request still began with the same chat template and the words Run id. llama.cpp reported reusing 42 tokens on every timed request, about a third of the short prompt. I use first-token delay to compare the short prompts because the prefill rate would count cached tokens as if the server had processed them again. The saved MLX runs have no equivalent cache count. llama.cpp cache counts · Saved MLX data
Benchmark results
The table shows medians of three requests at each prompt size from one session per server. Percent changes are relative to llama.cpp. Saved comparison · llama.cpp runs · MLX runs
Prompt | Metric | llama.cpp | MLX | Change |
|---|---|---|---|---|
Short | Prompt tokens | 137 | 138 | |
Short | Time to first token | 0.50 s | 0.42 s | −16% |
Short | Generation | 16.0 tok/s | 17.7 tok/s | +11% |
Short | Total time | 16.43 s | 14.81 s | −10% |
Long | Prompt tokens | 3,118 | 3,118 | |
Long | Time to first token | 8.11 s | 5.84 s | −28% |
Long | Effective prefill | 384.3 tok/s | 533.9 tok/s | +39% |
Long | Generation | 16.0 tok/s | 17.5 tok/s | +10% |
Long | Total time | 24.06 s | 20.40 s | −15% |
On the short prompt, both servers started streaming in about half a second. Almost all of the saving came from faster generation once the stream had started.
Halfpenny Mac reported a 48% generation speedup on an M4 Pro Mac mini. It compared 15.8 tok/s from oMLX 0.6.2 with 10.7 tok/s from llama-bench on llama.cpp b10470. It estimated oMLX generation from the difference in elapsed time between 1-token and 256-token requests. My test used mlx-lm directly and timed the stream the same way on both servers. Halfpenny Mac's benchmark
The watchdog reboot and the settings I changed
When the Mac rebooted, the local panic report recorded watchdog timeout: no checkins from watchdogd after 94 seconds without a check-in. It also listed five swap files in use. Memory pressure could explain the freeze. The report establishes the watchdog timeout and leaves the cause of the freeze open. Incident summary
MLX's Metal allocator keeps freed GPU buffers around so it can reuse them. In MLX 0.32.5, the default limit for that pool matches the allocation target, the smaller of 1.5 times the GPU's recommended working set and 95% of physical memory. Separately, mlx-lm 0.32.2 can save model state from up to ten prompts for reuse on later requests, with no byte limit by default. That means the server can hold onto old prompt state while processing a fresh request. MLX allocator defaults · MLX-LM cache defaults
For the next run, I cut the amount of memory the server could hold onto and added a guard.
- MLX allocator. The wrapper sets an 18 GiB allocation target for MLX operations, a 0.5 GiB limit on reusable buffers, and a wired-memory limit of up to 18 GiB. The allocation target is a guideline for MLX operations. The whole server can use more memory. Memory wrapper · MLX memory-limit API
- Request settings. The launcher serves one request at a time, saves one prompt cache, and processes prompts 512 tokens at a time, down from 2,048. Smaller steps reduce how much intermediate data MLX needs at once. The launcher enables 8-bit KV quantization at 5,000 tokens. All timed requests stayed below that threshold. MLX launcher · KV quantization threshold
- Memory guard. A shell script checks macOS once a second and stops the server if memory pressure reaches critical or swap use grows by more than 3,072 MB from its starting level. I tested the guard in a simulation. Memory guard
The launcher also passes --prompt-cache-bytes 2GB. In mlx-lm 0.32.2, the server enforces that byte limit only when it batches requests. Setting --kv-bits 8 disables batching even below the quantization threshold, so the benchmark's prompt cache was limited by entry count alone. Batching check · Byte-limit enforcement
What I would use on this Mac
I'm keeping llama.cpp as my daily default. It allocates cache for a 65,536-token context at startup and includes a browser chat page. The MLX benchmark reached about 3,100 input tokens. Before using MLX near 64K, I'd measure peak memory and first-token delay at that length. llama.cpp launcher · MLX long-prompt runs
Part 2 will give each engine one attempt at ten Python exercises from Aider's Polyglot benchmark. The test harness extracts the submitted code and grades it using the original Exercism unit tests. A gap of one or two tasks would be hard to interpret with a single attempt per task. Quality harness · Task provenance