L1 Beginner · Module 3: The performance mental model
3.4Prefill vs decode: TTFT and TPOT
A request runs as one big compute-bound prefill followed by many small memory-bound decode steps. The first sets time to first token, the second sets time per output token, and the two pull a serving engine in opposite directions.
By the end you will be able to
- ✓Predict TTFT and TPOT for a model, GPU and request shape from roofline arithmetic
- ✓Explain why prefill is compute-bound and decode is memory-bound
- ✓Show how batching trades per-user TPOT for total throughput
- ✓Explain why prefill and decode interfere when they share a GPU
You met the two phases in 0.2 and 1.4. With arithmetic intensity (3.2) you can now predict how long each one takes.
Two phases, two limits
Prefill runs all prompt tokens through the model at once. Every weight matmul has rows, so its intensity is in the hundreds or thousands: compute-bound. Its time is about
Decode runs one new token per sequence. At batch , matmul intensity is about , and attention intensity is about 1–8 regardless of batch. Unless is in the hundreds, it is memory-bound:
For Llama-3-8B on an H100, a 2,048-token prompt and 256 output tokens, the roofline gives TTFT ≈ 30 ms and TPOT ≈ 4.6 ms. The whole answer takes about 1.2 s, and 97% of it is decode.
- TTFT
- 30.3 ms
- TPOT
- 4.57 ms
- end to end
- 1.19 s
- tokens/s per user
- 219
Prefill is compute-bound (99% of its time in compute-limited ops). It processes 2,048 tokens in one pass.
Decode is memory-bound. Each step makes 1 token, so the GPU produces 219 tokens/s in total.
Roofline lower bounds in BF16, prefill of this one request alone. Real engines reach maybe 60–85% of these speeds.
Batching: the central trade
Decode at batch 1 wastes almost all of the GPU’s arithmetic. Adding sequences to a step reuses the weights already being loaded, so throughput rises nearly in proportion while TPOT grows slowly, until the KV cache reads take over. That gives every serving engine its core dial:
- Small batches: fast tokens for each user, expensive per token.
- Large batches: cheap tokens, slower for each user, and more memory spent on KV cache.
The right setting depends on what users were promised: a service-level objective (SLO) such as “TTFT under 500 ms and TPOT under 50 ms at the 99th percentile”. Chapters 13.1 and 16.2 turn that into numbers you can measure.
Why the phases interfere
A serving engine runs both phases for different users on the same GPU. When a new request’s prefill enters a step, that step becomes compute-bound and much longer, and every user in the decode batch waits for it. A 30 ms prefill inserted into a stream of 5 ms decode steps is a visible stutter for everyone.
Sources
Check your understanding
0 / 4 answered1.Which GPU spec most affects TPOT at small batch sizes?
2.Why is prefill compute-bound?
3.Going from batch 1 to batch 64 in decode usually…
4.Why can a new request's prefill hurt other users' TPOT?