How does Paged Attention work?
hardAnswer
- vLLM (Kwon 2023) allocates the KV cache in fixed-size 'pages' (e.g., 16 tokens each) via a page table — like OS virtual memory.
- Benefits: (1) no fragmentation as sequences grow / shrink; (2) memory sharing across sequences with a common prefix (parallel sampling, beam search); (3) enables continuous batching with variable-length sequences.
- Reduces KV-cache memory waste from ~60% (naive contiguous allocation) to ~4%.
- Foundation of vLLM's throughput advantage.
Check yourself — multiple choice
- Contiguous KV allocation
- KV cache in fixed-size pages via a page table → no fragmentation + prefix sharing + variable-length batching (vLLM)
- Same as memory pooling in CUDA
- Only for training
Paged Attention: OS-style paging for KV cache → tiny fragmentation + prefix sharing.
#inference#kv-cache#serving
Practise LLMs & GenAI
214 interview questions in this topic.
Related questions
- What does 'automatic prefix caching' do in vLLM?
- What is the KV cache and why does it matter for LLM inference?
- What is Grouped-Query Attention (GQA) and why does it matter?
- What is prompt caching and when does it help?
- What's the difference between prefill and decode in LLM inference?
- What is continuous / dynamic batching in LLM serving?