paged attention

PagedAttention, introduced in vLLM, revolutionizes KV cache management by treating it like operating system virtual memory with fixed-size pages. Traditional implementations allocate contiguous memory for the maximum possible sequence length per request, causing severe fragmentation: a system supporting 2K max context wastes 50% memory on average-length requests. PagedAttention divides KV cache into fixed blocks (typically 16-32 tokens each), allocated on-demand as sequences grow. A block table maps logical cache positions to physical memory blocks, enabling non-contiguous storage. This approach reduces memory waste from 60-80% to under 4%, enabling 2-4x higher throughput through increased batching. Further innovations include prefix caching (sharing KV blocks for common prompt prefixes across requests), copy-on-write for beam search (avoiding duplicate storage), and memory swapping to CPU when GPU memory is exhausted. PagedAttention enables efficient handling of mixed-length requests in production systems, crucial for chat applications where prompt and response lengths vary dramatically. The technique is implemented in vLLM, TensorRT-LLM, and other inference frameworks, becoming standard for LLM serving infrastructure.

Go deeper with CFSGPT

Get AI-powered deep-dives, save terms, and run advanced simulations — free account.

Create Free Account