Review — Autoregressive generation
Back to the lesson · Learning path plan
What to remember
- Prefill processes the prompt and returns logits at its last position, which are used to select the first generated token.
- During decode, each selected token extends the context and influences the next distribution. A KV cache lets the model reuse keys and values from earlier positions.
- Decoding may take the highest-scoring token or sample. An end token, stop sequence or length limit can terminate the loop.
Recall from memory
Does selecting the first generated token require a separate decode forward pass after prefill?
Show the answer
Prefill already provides the logits used to select it. The selected token then becomes the input to the pass that prepares the next prediction.
Visual card — One decode step with a KV cache
In one causal attention head, the prefix A B C is already cached and D enters the model. Which vectors are read for A B C? Which are computed for D? Which positions can D attend to?
A B C · prefix
→
Vectors read: ?
D · new input
→
Vectors computed: ?
Show the card answer
A B C. Read the keys K and values V for those three positions.
D. Compute Q, K, and V for D and append its key and value to the cache. D’s query can use the keys and values at A, B, C, and D. The causal mask allows the current position.
Trace the second step when generating or scoring an observed continuation.
In serving, time to first token (TTFT) includes waiting and prefill, among other costs. Time per output token (TPOT) describes the pace after the first token. Scheduling can affect these measurements.