Experiments #157f
Row 157: a cold 8k prefill idles the GPU about 178 ms (traced) at the chunk boundaries and the MoE cadence...
done
What was tested
Row 157: a Cold means the server has never seen this prompt start; warm means part of it is already remembered from before. 8k Prefill: the model reading the whole prompt before it can write the first token. Read more idles the A graphics card, used here as the chip that does the heavy arithmetic for a model. about 178 ms (traced) at the chunk boundaries and the Mixture of experts: a model made of many specialist sub-networks where only a few run per token. Read more cadence drains. Fixes, both lossless: (a) no `mlx_clear_cache` between the chunks of one prefill (`src/generate.zig:2012` at d1158e56), so the next chunk's transients reuse MLX's buffer cache, the clear kept once after the prefill, with peak memory read at 8k, 16k and 32k; (b) the MoE prefill's cadence eval every 4 layers (`src/transformer.zig:10649`) issued as an async eval one block behind, so the host builds the next 4 layers while the GPU runs. Step 1, untraced and timing-free of The writing phase: the model produces the reply one token at a time. Read more: the best against each fix and both on 3 cold 8k and 16k bench first turns, max_tokens 1, the `[prefill-trace]` totals paired in alternating order, and the best's untraced idle read off the same totals (row 157's trace cost about 2%); step 2, if a fix gains 30 ms or more at 8k: identity on 150 replies, then a Mac pair on the 50 sessions
Model and setup
the best
Expected gain
first The unit of text a model reads and writes: roughly a short word or a piece of a longer one. -1% to -2% on cold 8k turns (traced upper bound 178 ms of 9.1 s), about -0.2% reply per turn (inferred: row 109a's -3.8% cold first token gave -0.6% reply)
Where the idea came from
`2026-11-27-mac-r157-cold-prefill-idle/README.md` § Result
Outcome
done 2026-11-27 (read-rows): A valid experiment that did not beat the best score by more than the noise. at 8k for either fix or both (8k paired The middle value when results are sorted: half the requests were faster, half slower.: C -6.0 ms, Y -14.5 ms, CY -26.5 ms against the -30 ms line, A/A floor 25.7 ms, no fix below zero in all three repeats); at 16k, reported beside it, C -41.8, Y -66.6 and CY -110.0 ms (A/A -25.8); 45 of 45 first tokens equal; untraced the best's 8k prefill is 8.92 s against row 157's 9.12 s traced, so most of the traced idle was the trace or graph build; CY queued as row 157fs for the next lossless stack (`2026-11-27-mac-r157f-prefill-boundary-fix/README.md` § Result)
Lesson
with no trace, the best's cold 8k prefill leaves little idle at its chunk boundaries for a host-side fix. Keeping the buffer cache between chunks and running the MoE cadence one block behind save a median 26.5 ms together at 8k (inside twice the 26 ms floor) and about 50 to 95 ms at 16k against the A/A, losslessly by first token. Most of row 157's 178 ms of traced idle was the trace's cost or graph-building host work. Size a prefill fix untraced before building it, and read a paired run per request: one block-wide shift moved C's repeat 1 by 190 ms on every request alike.
Adopted
no (no gain at 8k by the pre-registered rule; CY, lossless and small, is queued as row 157fs for the next lossless stack, with its identity check first)