Prefill and decode: name the two phases of LLM inference and say which one is compute-bound
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Prefill processes all prompt tokens in parallel and is compute-bound (saturates tensor cores). Decode generates one token at a time and is memory bandwidth bound (HBM read of the full KV cache per step).
Imagine ordering a meal at a restaurant. The kitchen has to do two very different jobs. First, when you place your whole order at once (the prompt), the chef can fire up every burner in parallel and cook all the dishes simultaneously; the bottleneck is how much heat the kitchen can put out. Then, once the meal is going, the server has to walk to the kitchen, pick up one dish, and bring it to your table, then walk back for the next; the bottleneck is no longer how fast the kitchen cooks but how fast the server can run. LLM inference works the same way: prefill is the parallel cooking burst, decode is the per-dish trip back and forth. The two have completely different bottlenecks, which is why they get tuned separately.
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.
Walk the roofline picture, explain prefill as a compute-bound parallel matmul over all prompt tokens, contrast decode as a bandwidth-bound per-token loop against the full KV cache, derive the TTFT-vs-TPOT split, and close with the modern optimizations (continuous batching, KV compression, speculative decoding, chunked prefill) that target each side of the asymmetry.
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.
Treating LLM inference as one uniform workload and missing that prefill and decode have completely different bottlenecks (compute vs bandwidth) requiring different optimizations.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.