Describe what happens during the decode phase of LLM inference.
Decode is the autoregressive loop where one forward pass produces one token, appending its K and V to the cache and attending over the full cache to sample the next token.
Picture writing a long sentence one word at a time, where each new word has to consider every word you have already written. To save time you keep a small notebook of notes about every previous word, so you do not have to reread the whole story each step. You take the next blank space, jot down notes for the single new word you are about to add, glance over every note in the book, then write down what comes next. Then you repeat. The model does the same thing. Reading the prompt is one big batch operation; producing the answer is hundreds of these one-step writes. That is why long answers feel slow even when the prompt was short.
Detailed answer & concept explanation~6 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
5 min: define decode as one forward pass per token, walk through the Q-K-V asymmetry and KV cache append, explain why it is strictly sequential and bandwidth-bound, then connect to batching and continuous batching as the throughput lever.
Real products, models, and research that use this idea.
- vLLM continuous batching merges new requests into the in-flight decode batch every step on H100 and B200 clusters serving Llama 4 and DeepSeek V4.
- Anthropic streams Claude Opus 4.7 output token by token as the decode loop produces each token, exposing per-step timing in the API.
- TensorRT-LLM in-flight batching schedules decode steps for hundreds of concurrent users on a single GPU to amortise weight reads.
- SGLang's RadixAttention shares KV cache prefixes across decode loops for users with similar system prompts, cutting per-request memory.
- OpenAI's GPT-5.5 batch API trades streaming for higher batch sizes during decode, which is how it offers 50 percent off the realtime rate.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy is Q computed fresh each decode step instead of cached like K and V?
QHow does continuous batching let you mix requests at different decode positions in one batch?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Treating decode as a single matmul like prefill. Decode is N sequential forward passes, each producing one token, which is why output length dominates wall-clock time.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.