Interview Lab
What happens when a long prompt interrupts decoding?
On one GPU, 8 requests have just emitted a token when a long prompt arrives. The long prompt needs 20 ms of prefill, and a decode step takes 4 ms. The scheduler starts prefill immediately, either in one pass or in 5 ms chunks with one decode step between chunks. Finishing prefill emits the new request’s first token.
For each schedule, what is the longest gap between tokens for the active requests, and when does the new request get its first token?
Animated solution
Two ways to schedule the GPU
At 0 ms, the eight active requests have just emitted a token. Each decode step takes 4 ms and emits one token per active request.
Full prefill
- Longest gap in active streams
- 24 ms
- Time to first token
- 20 ms
Chunked prefill
- Longest gap in active streams
- 9 ms
- Time to first token
- 32 ms
Chunking protects the active streams.
Chunking cuts the longest gap for active requests from 24 ms to 9 ms. The new request gets its first token at 32 ms instead of 20 ms.
Worked solution
| Schedule | Longest active token gap | New request’s first token |
|---|---|---|
| Full prefill | 24 ms | 20 ms |
| Chunked prefill | 9 ms | 32 ms |
- Full prefill. The new request gets its first token after 20 ms. The active batch waits through prefill and one decode step, so its longest gap is 20 + 4 = 24 ms.
- Chunked prefill. The active batch waits at most one chunk and one decode step, or 5 + 4 = 9 ms. There are 3 decode steps between the 4 chunks, so the new request gets its first token after 20 + 3 × 4 = 32 ms.
The example schedules one kind of work at a time. Real engines can batch prefill and decode together, so the latency trade-off depends on the scheduler and workload.