prefill-vs-decode -- two inference regimes

Running a model happens in two quite different phases. First it reads your whole prompt in a single pass, every word at once, which keeps the chip's arithmetic units fully busy and is over quickly. Then it writes the answer one word at a time, and each of those steps does very little arithmetic while having to haul the whole model out of memory, along with everything it has stored about the conversation so far, so the chip spends its time waiting on memory instead of calculating. That is the pause and then the steady trickle of words you see in a chat window, and it is why the writing half, not the reading half, is what makes a service expensive to run.

Interactive page: the two phases of autoregressive inference, side by side -- prefill (process the whole prompt in one parallel pass) vs decode (generate one token at a time). Anchor: A4 KV cache / runtime shape (Family C). Companion to kv-cache, which shows the cache itself filling.

What it shows

The same attention is really computed in both (causal softmax(QKᵀ/√d)); the difference is the shape of the work: a parallel triangle once vs a growing single row every step. The cost readout contrasts the FLOPs/bytes and why prefill is fast-per-token while decode is the throughput bottleneck.

Press play (or scrub) to run prefill then the decode loop; drag the timeline handle to move through the steps; hover any cell for its value + which phase filled it.

Render tier

T2 (WebGL2 heatmaps for the prompt / attention / cache; Canvas2D for the timeline, brackets, arrows, and cost panel).

Wiring

layout.mount + controls (N, gen G, D, seed) + a (1 + G)-stage Transport (prefill then G decode steps) + onPointer timeline drag + hover. ?step / ?pos / ?hover hooks. Source: page.js.