The Two Phases of LLM Inference
Every time you call an LLM API, inference runs in two distinct phases with radically different performance characteristics.
Prefill processes your entire prompt at once. Because all input tokens are known upfront, the GPU can compute attention across all of them in parallel — this is essentially a giant matrix multiply. A 1,000-token prompt typically takes ~50–200 ms on a modern A100.
Decode generates one token at a time. Each step attends over the entire context (prompt + tokens generated so far), produces a probability distribution, samples one token, and feeds it back as input for the next step. This is inherently serial — you cannot generate token n+1 until you have token n. Generating 200 tokens might take 2–5 seconds on the same hardware.
The consequence: latency-sensitive applications care more about decode throughput, while cost-sensitive batch jobs care about prefill efficiency. Almost every optimization in LLM serving targets one of these two phases.
