Verba/Rapida

Esperimenti #157

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

done

Il testo degli esperimenti resta in inglese, come l'ha scritto il laboratorio.

Cosa è stato provato

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)

Modello e configurazione

the best

Guadagno atteso

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

Da dove viene l'idea

row 105b; engine audit 2026-11-13

Esito

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)

Lezione

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.

Adottato

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)

Vuoi vedere cosa hanno prodotto questi esperimenti? Lesto, il motore di inferenza per Gemma 4 sui Mac con Apple silicon, è su lestoengine.com

Creato da Federico Andrioli, @fedeandri su X Le misure di un laboratorio di ricerca, ricavate direttamente dai suoi file. Dati aggiornati al