Prefill is the first phase of generative Transformer inference. It processes all prompt tokens in parallel, populates the key–value (KV) cache, and produces no generated tokens. Autoregressive sampling then uses that cached attention state to decode tokens one at a time. section 4.3.1
Operationally, prefill matters because it:
- Processes the prompt in one forward pass instead of repeatedly recomputing attention over already-seen prompt tokens. section 4.3.1
- Consumes memory for cached keys and values in GPU VRAM or CPU RAM, so sequence length and batch size are capacity constraints. section 4.3.1 section 4.3.2
- Contributes to end-to-end latency alongside per-token decoding; a practical estimate adds prefill time to the time for generated tokens. section 4.3.3
- Supports higher-throughput dynamic batching when queued requests share a forward pass, but queuing can harm chatbot response latency. section 4.3.2
Estimating a GPT-Neo run
For a 300-token prompt on a T4, an example estimates roughly 50 ms for prefill and 36 ms per generated token. The resulting estimate is 50 + (300 × 36) = 10.85 seconds, while measured execution also includes other overheads. section 4.3.3
Figure 4.1 The (Q × KT) × V computation process with caching
Use the attention-flow diagram to see how cached keys and values avoid recomputing the full prior sequence during decoding. section 4.3.1
