12 · I · Use
Inference and the KV cache
Frozen θ. Temperature, top-k, nucleus. Prefill once, then decode with cached keys and values.
Weights freeze. Only the forward map runs.
Once training is finished, is frozen. There is no “correct” next token sitting in a dataset, so there is nothing to compute a loss on and therefore nothing to back-propagate. Autoregressive generation:
- Start with prompt tokens .
- Forward → logits .
- Form a sampling distribution from .
- Draw , append, repeat.
Decoding math
- temperature. τ → 0 is greedy: argmax_k z_{t,k}
Top-k. Keep the largest logits, set the rest to , then softmax.
Nucleus / top-p (Holtzman et al., 2020). Keep the smallest set of tokens whose cumulative probability is at least , then renormalize.
No . No Jacobian. No Adam.
KV cache
Attention at step only needs and all past . Store (K, V) per layer:
New token: compute new , append , attend. Cost per new token is attention, not from scratch.
Prefill
O(T²)
One forward over the whole prompt. Every position attends to the past. Cache is filled.
Decode
O(t) / token
New q attends to cached K, V. Append one row. No Jacobian. No optimizer.
This is the entire user-facing model: frozen , forward pass, sample. Training was the process that carved . Inference only reads it.