Skip to content

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:

  1. Start with prompt tokens .
  2. Forward → logits .
  3. Form a sampling distribution from .
  4. Draw , append, repeat.

Decoding math

(12.1)
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.

(12.2)

No . No Jacobian. No Adam.

KV cache

Attention at step only needs and all past . Store (K, V) per layer:

(12.3)

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.