Decode-phase attention is memory bandwidth bound. Explain what flips the regime.
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
During prefill, attention is compute-bound, but during decode, the same layer becomes memory bandwidth bound. Explain why generating one token per step changes the regime, and name two optimizations that exploit this insight.
At decode, Q has length 1 per step, so the attention matmul is tiny, but the full KV cache must stream from HBM, making bandwidth (not FLOPs) the bottleneck.
Imagine a chef cooking one omelette per minute (decode) versus a chef cooking 100 omelettes in a batch (prefill). For the single omelette, the time is dominated by walking to the fridge to fetch all the ingredients (streaming the cache from memory), the actual cooking is a few seconds. For the batch, the chef opens the fridge once, takes out everything, and the cooking dominates. The kitchen bottleneck flips from 'how fast can the chef cook' (compute) to 'how fast can you fetch ingredients' (memory bandwidth). Decode-time LLM serving has the same flip every single token step.
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.
8 min: Q shape difference between prefill and decode, arithmetic intensity calculation, roofline interpretation, concrete cache bytes for production models, GQA and MQA as cache shrinkers, KV quantization, Flash-Decoding parallelization, speculative decoding as a regime-flipper, multiplicative composition in the 2026 stack.
| Property | Prefill | Decode |
|---|---|---|
| Q shape per layer per head | (T, d) | (1, d) |
| K, V shape | (T, d), built from input | (T, d), cached |
| FLOPs per layer | O(T^2 d), large | O(T d), small |
| Bytes loaded per layer | O(T d), amortized over T queries | O(T d), per single query |
| Arithmetic intensity | O(T), high | O(1), low |
| Regime | Compute-bound (tensor cores) | Memory bandwidth bound (HBM) |
| Bottleneck | FLOPs | Bytes streamed per step |
| Main optimizations | FlashAttention, tensor-core efficient kernels | GQA/MQA/MLA, KV quantization, Flash-Decoding |
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Assuming decode is slow because of FLOPs. The FLOPs per decode step are tiny; the bottleneck is moving the KV cache from HBM to SRAM, which is why every decode optimization targets bytes per token rather than ops per token.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.