Inference sampling generates tokens in two phases: prefill processes prompt tokens in parallel, then autoregressive decoding samples one token at a time. section 4.3.1
The main operational trade-offs are:
- Prefill populates the key–value (KV) cache without generating tokens. section 4.3.1
- Autoregressive decoding reuses cached attention state instead of recomputing all prior tokens. section 4.3.1
- Caching consumes GPU VRAM or CPU RAM but can substantially reduce sampling time. section 4.3.1
- Performance analysis compares arithmetic intensity with hardware memory-transfer and compute limits. section 4.3.1
Measuring KV-cache impact
A GPT-Neo generation benchmark on a T4 GPU compares Transformers generate calls with use_cache=True and use_cache=False; caching averages 10.281 seconds versus 51.978 seconds without it. section 4.3.1
