Wide prefill: 832.69 to 1,820.43 tokens/s, within about 1 % of Metal on the same M2 Ultra
Our kernel-replay engine on Asahi Linux now digests a 952-token prompt at 1,820.43 tokens/s, against about 1,836.7 for llama.cpp's Metal backend on macOS on the same machine. The kernels did not change. The batch width did: 512 rows per pass and 16 column tiles per launch, the geometry Metal already used. Decode sits at 130.4 against about 144.6. The windows are not yet like-for-like, and the prefill run is a diagnostic.
On one Apple M2 Ultra, our kernel-replay engine on Asahi Linux went from 832.69 to 1,820.43 tokens/s of prefill on a 952-token prompt with a 4-bit Qwen3-4B model. llama.cpp's Metal backend on macOS, on the same machine with the same model file and the same prompt, measures about 1,836.7 tokens/s.
That puts us within about 1 % on prefill and 10 % behind on decode (130.4 against about 144.6 tokens/s). Both comparisons carry caveats, stated below and not in a footnote: the timing windows differ, the GPU clock cannot be pinned on this platform, and the prefill run is a diagnostic, not the formal pre-registered arm.
The main finding: Metal's prefill advantage was batch width, 512 prompt rows per pass and 16 column tiles per matrix-multiply launch. It was not different kernel arithmetic. We were already replaying the same kernel family, 32 rows at a time.
What the engine is
Prefill is the pass that reads the prompt before the model generates anything. Decode generates one token per pass after that. Tokens per second (tok/s) is the throughput of each.
The engine replays GPU programs captured from llama.cpp's Metal backend: the compiled kernel binaries, their uniform words (the small constant block each launch reads its shapes and strides from), buffer bindings, launch geometry and barrier flags. It submits them to the M2 Ultra's GPU (the AGX family) through Mesa's Asahi kernel interface, with no shader compiler in the loop. The earlier posts in this series cover split-K prefill and decode launch grouping.
The numbers
Every row uses the same M2 Ultra, the same Qwen3-4B-Q4_0 model file and the same 952-token prompt.
| prefill | tok/s | timing window |
|---|---|---|
| llama.cpp Metal, macOS (4 runs) | ~1,836.7 (1,830.53–1,841.72) | llama.cpp prompt-eval timer |
| ours, wide (diagnostic, N=5) | 1,820.427881 | request start to final prompt argmax |
| ours, 32-row, same session (N=5) | 832.694948 | same as above |
| llama.cpp Vulkan, Asahi (earlier run) | 523.845 | llama.cpp's own timer |
| omarchy-mlx, Vulkan, Asahi (N=5) | 131.126119 | prompt ÷ time to first token |
| decode | tok/s | timing window |
|---|---|---|
| llama.cpp Metal, macOS (4 runs) | ~144.6 (141.70–145.02) | llama.cpp eval timer, includes submit and sync |
| ours, Metal's thread counts (N=5) | 130.4 (130.29–130.78) | GPU interval of one decode pass |
| llama.cpp Vulkan, Asahi (earlier run) | 44.647 | llama.cpp's own timer |
| omarchy-mlx, Vulkan, Asahi (N=5) | 5.784577 | 32 decode intervals |
The prefill and decode rows for our engine come from separate runs. No joint prompt-plus-generation request on the new configuration is claimed.
The paired prefill timing ran five wide and five 32-row requests, interleaved in alternating order, after one untimed warm-up request per arm. No sample was discarded. The wide arm's median request took 0.522953977 s against 1.143275820 s. The median paired speedup is 2.185403×, with the five pairs between 2.178475× and 2.191881×.
The 32-row arm reproduces the configuration published in the split-K post, 833.559 tokens/s, to within one tokens/s.
Correctness came first
Every number above sits behind a token-id gate. For each of the 952 prompt positions, the engine's highest-scoring next token (the argmax) must equal the reference's. The gate ran on the full vocabulary at every position before any timing child was allowed to start.
The wide pass matched 952 of 952 positions. The fresh 32-row control matched 951 of 952; its one miss, position 899, is a known departure that every admitted arm in this campaign carries.
The finding: Metal was running a wider batch
llama.cpp splits a prompt into ubatches, the row blocks it processes per pass. Metal ran this prompt at ubatch 512: one pass of 512 rows, then one of 440. Our engine ran 30 passes of 32 rows.
Inside each pass, the matrix multiply launches a grid of threadgroups (the
GPU's scheduling unit, 128 threads here). Each threadgroup computes a tile of
64 output features by 32 prompt rows. A launch's column tiles are those
32-row tiles laid side by side, so 16 of them cover 512 rows. Metal's
captures, made with the same binary, model and prompt as the 1,836.7
comparator, record every 4-bit prefill matrix multiply as
kernel_mul_mm_q4_0_f32 with 16 column tiles per launch (14 for the
440-row tail). We launched one.
The kernel is the same family we replay: the same 64 × 32 tile built on the GPU's simdgroup matrix instructions. The Metal comparator binary also predates llama.cpp's newer few-row MMA matrix-multiply kernels; that commit is dated 2026-10-05 and is not an ancestor of the comparator's build, and even at the current head those kernels only serve up to 16 rows. Metal's 1,836.7 did not come from a different kernel family. What differed was the launch geometry, and which compiled variant of the same kernel ran.
Two measurements made this concrete.
Metal, swept by batch width
We booted the same machine into macOS and swept the ubatch on the same 952 prompt with the comparator binary, three runs per width:
| Metal ubatch (rows) | prefill tok/s, three runs | median |
|---|---|---|
| 32 | 712.03 / 712.71 / 713.04 | 712.71 |
| 64 | 1,215.67 / 1,223.37 / 1,213.05 | 1,215.67 |
| 128 | 1,539.95 / 1,544.45 / 1,547.62 | 1,544.45 |
| 256 | 1,738.50 / 1,746.66 / 1,741.90 | 1,741.90 |
| 512 | 1,835.71 / 1,833.13 / 1,832.88 | 1,833.13 |
At its own 32-row operating point, Metal measured 712–713 tokens/s, below our 833.559. We state that as a direction, not a ratio, because our window is the wider request window. The ubatch-512 runs reproduced the banked comparator's timing band and token ids.
One captured kernel, swept by grid width
On Asahi, we took one captured matrix-multiply launch (4096 output rows, contraction 2560) and ran it at widths from 32 to 512 rows, with a numeric proof against a float64 reference before every arm and five timed runs each:
| rows | column tiles | median ms | ns per row | weight GB/s |
|---|---|---|---|---|
| 32 | 1 | 0.155875 | 4,871 | 37.84 |
| 64 | 2 | 0.190917 | 2,983 | 61.79 |
| 128 | 4 | 0.273541 | 2,137 | 86.25 |
| 256 | 8 | 0.553917 | 2,164 | 85.19 |
| 512 | 16 | 0.931791 | 1,820 | 101.28 |
Sixteen 32-row launches cost 2.4940 ms; one 512-row launch costs 0.9318 ms. The same kernel is 2.68× cheaper per row when one launch carries 16 tiles, and its effective weight bandwidth rises from 37.8 to 101.3 GB/s. The other four prefill shapes moved the same way, with 512-row cost between 0.110× and 0.534× of their own 32-row cost.
Both sides gain about 2.5× from going wide. Apple's GPU under Asahi gets the same wide-batch efficiency Metal gets, once the engine asks for it.
A projection built from that single-launch sweep predicted about 1,057 tokens/s end to end (range 999–1,225). The real wide pass reached 1,820.43. The projection held every non-matrix-multiply operation at its 32-row cost, and the real run widened all of them. That is the likeliest reason for the miss; it has not been isolated.
The bug that made the first wide pass wrong
Building the wide pass meant writing new inputs for every operation at 512 and 440 rows. We tiled each operation's captured 32-row input slices out to the new row counts; the tiled values sit in slots the engine overwrites with real data at run time, and weights and parameters were copied unchanged. That choice was a hypothesis until the 952-position gate passed.
The first full run did not pass. It executed both wide passes and produced 952 finite token ids, but only 58 of 952 matched the reference, and the first miss was at position 32.
The cause was one element-wise operation: the residual add, which llama.cpp implements as a fused binary kernel. In 140 instances of it, the word that sets the output row count had been widened to 512 and 440, but four other uniform words still described 32 rows: the input row bound, the broadcast extent, and a float divisor and its reciprocal (still 32 and 1/32). The Metal source returns early for any row past the input bound. So rows after 31 were never computed; they kept the tiled template values.
Correcting exactly those four words in the 140 operations moved the two sampled pass endpoints onto the reference's tokens. The full run then matched 952 of 952. No engine code changed. Earlier, a run with a barrier after every operation had kept the same wrong tokens, so a missing barrier was not the cause.
Decode: the same graph, a different cost per dependency
Decode now runs 130.4 tokens/s against Metal's ~144.6, about 0.90×.
The graph is already Metal's graph. Our decode pass and Metal's, at the matched shape after the same prompt, both issue 725 launches, with barriers at identical sites except one (506 against 505). The twelve kernel families appear in the same counts, and 11 of the 12 kernel binaries are byte-identical. The one that differs, the 4-bit matrix-vector kernel, was measured earlier at equal speed when we replayed Metal's version instead.
The last admitted change matched Metal's threadgroup sizes. Our RMS normalisation and SwiGLU activation launches were running 448 and 896 threads where Metal runs 640 and 1,024, because we allocated more registers than the kernels need. Correcting that on 109 operations moved the device interval from 7.7859 to 7.6699 ms per decode pass (−1.49 %, ranges disjoint), 128.4 to 130.4 tokens/s, with both arms at 983 of 984 on a 984-position gate.
One lever failed, and stays in the record. A narrower barrier word,
0x600000d0 in place of 0x6000017c, passed a short dependent-chain safety
ladder: all 18 cells, covering read-after-write, write-after-write and
write-after-read hazards. On the full 725-operation decode graph it matched
77 of 984 positions, wrong from position 0, with no non-finite
values. The run stopped there, as pre-registered, and the wider word remains.
Our reading, untested: some consumer among the graph's 506 dependency
transitions needs a barrier bit the narrow word drops.
The current hypothesis for the remaining gap is synchronisation cost per dependent step. On the same kernel, an independent launch costs 6.66 µs under Asahi against 7.00 µs under Metal, but a dependent launch costs 14.4–15.0 µs against 11.2 µs. Under Asahi the barrier acts as a full drain of the GPU's command stream. Multiplied over 506 transitions, that excess is about 1.9 ms per pass, more than the 0.860 ms lower-bound device gap measured before the geometry change. This is arithmetic over separate measurements, not an isolated cause. Splitting the graph into concurrent jobs cannot hide it: every barrier lies on the critical path.
MLX
For MLX on this machine we have chosen omarchy-mlx, which runs MLX on Vulkan through the Honeykrisp driver. On our exact model file and prompt it measures 131.126119 tokens/s prefill and 5.784577 tokens/s decode (fresh five-run baseline, matching the 131.09 / 5.808 of the day before). We plan to upstream fixes after thorough testing. The patches are written; GPU results are pending.
What this does not say
- The prefill comparison is not like-for-like yet. Our 1,820.43 is request wall time: it includes host-side encoding, staging and logits readback, from request start to the final prompt argmax. Metal's 1,836.7 is llama.cpp's prompt-eval timer. The wide run printed a GPU interval only for its final 440-row pass (250.369709 ms), so it cannot supply a GPU-only total. A GPU-only measurement is running.
- The decode comparison mixes windows too. Our 130.4 is the GPU device interval of one decode pass. Metal's 144.6 includes host submission and synchronisation. Our own host-window reading at the same context was lower, 114.906 tokens/s, measured before the thread-count change.
- GPU clocks cannot be asserted on Asahi. Frequency scaling is run by firmware, with no Linux interface to read or pin it, so every Asahi receipt records the clock state as unassertable. The numbers are gated and internally consistent; they are not certified performance data.
- The 1,820.43 run is a diagnostic. It ran on generated input files corrected by hand: the 140-operation word fix, re-typed headers on 72 attention fixtures with unchanged payloads, and four omitted lookup slots tiled to size. The formal, pre-registered run is pending.
- This is one prompt and one shape. 952 tokens, one model, one machine.
Reproduction
- Hardware: Mac Studio, Apple M2 Ultra, 192 GB.
- Asahi side: Fedora Asahi Remix 44, kernel
7.2.2-tb4-gpu72n; replay engine binary 44b0f12b…for prefill and f22098e2…for decode. - macOS side: macOS 26.6.2; llama.cpp Metal
llama-completion, a patcheda8bad38build, binary 4a64d03d…; -c 1024 -b 512 -ub 512 -n 32 --temp 0 --ignore-eos --no-warmup, prompt passed as token ids. - Model: Qwen3-4B-Q4_0 GGUF,
92f4a83c…. - Prompt: a frozen 952-token id file,
769cb003…. - Prefill protocol: 952-position token-id gate on both arms first, one untimed warm request per arm, then N=5 interleaved pairs; request start through final prompt argmax, setup excluded.
- Decode protocol: 984-position token-id gate on both arms, N=5 timed children per arm, median GPU device interval of the final decode pass.
