Verba/Rapida

Experiments #157

Cold prefill chunk boundaries: each 2,048-token chunk ends with a blocking KV eval, `mlx_clear_cache` and a...

done

What was tested

chunk boundaries: each 2,048-token chunk ends with a blocking KV eval, `mlx_clear_cache` and a scheduler tick (`src/generate.zig:1847-1910`) and drains the 8 times inside (cadence every 4 layers, `src/transformer.zig:9920-9921`); one Metal System Trace (row 149's `diag149_job.sh` shape, the best's own build) over 3 cold 6k prefills, GPU idle gaps over 0.2 ms placed against the prefill trace's chunk stamps; then the fixes it names (cadence as an async eval one block behind, no cache clear between chunks, both lossless) and `MLX_SERVE_PREFILL_CHUNK` 4096 as a separate rounding arm; diagnostic, timing-free (`2026-11-13-mac-engine-audit/README.md` F6)

Model and setup

the best

Expected gain

sizes 20 to 80 ms, 0.3% to 1.1% of the cold first (inferred; row 105b measured 12.5 ms per warm turn)

Where the idea came from

row 105b; engine audit 2026-11-13

Outcome

done 2026-11-27 (read-rows): line met, 178.10 ms of idle in gaps of 0.2 ms or more a cold 8k prefill (176.65, 189.70, 178.10; 2% of a 9.1 s prefill), most at the 3 inner chunk boundaries (54 to 74 ms a request: blocking K/V eval, `mlx_clear_cache`, then the next chunk's graph, `src/generate.zig:2000-2012` at d1158e56) and the last chunk's end (16 to 40 ms), the cadence drains 1 to 3 ms each; the trace slows the prefill about 2%, so the reading is an upper bound; row 157f queued (`2026-11-27-mac-r157-cold-prefill-idle/README.md` ยง Result)

Lesson

a cold 8k prefill on the best idles the GPU about 178 ms in gaps of 0.2 ms or more (2% of its 9.1 s), most of it at the chunk boundaries. Each of the three inner boundaries costs 8 to 41 ms, the largest gap usually the first, where the code evaluates the K/V, empties MLX's buffer cache and only then builds the next chunk's graph. The MoE cadence's blocking eval every 4 layers adds 1 to 3 ms a drain. A Metal System Trace slows the same prefill by about 2%, the size of what it measures, so a trace shows where idle sits and the fix's gain must be sized untraced.

Adopted

no (a diagnostic; the line is met, so row 157f is queued: no cache clear between one prefill's chunks and the cadence eval one block behind, both lossless, sized untraced first)

Want to see what these experiments produced? Lesto, the Gemma 4 inference engine for Apple silicon Macs, is on lestoengine.com

Made by Federico Andrioli, @fedeandri on X A research lab's own measurements, generated from its files. Data built