You've quantized your model. You've batched your requests. Yet your GPUs still sit at 40% utilization while the KV cache eats VRAM for breakfast. The bottleneck isn't compute anymore—it's memory fragmentation. vLLM's PagedAttention solves this by treating KV cache like virtual memory, and the throughput gains are staggering.
Why Standard KV Cache Fails at Scale
Traditional LLM inference allocates contiguous GPU memory for the entire KV cache upfront. For a 7B model with 4K context, that's ~1.5 GB per sequence. Multiply by batch size and you hit OOM errors fast. Worse, variable sequence lengths leave massive gaps—internal fragmentation wasting 20-50% of reserved memory. You can't pack more requests because the allocator needs contiguous blocks.
PagedAttention: Virtual Memory for KV Cache
PagedAttention borrows a page from OS design. It splits the KV cache into fixed-size blocks (typically 16-32 tokens each) and maps logical sequences to non-contiguous physical blocks via a block table. The attention kernel fetches keys and values from scattered blocks on the fly. No more contiguous allocation. No more reserved padding. Memory utilization jumps to near 100%.
Memory Sharing Unlocks Advanced Decoding
Because blocks are reference-counted, multiple sequences can share identical prefix blocks. This enables parallel sampling (generating 10 completions per prompt) and speculative decoding (draft model proposes, target verifies) without duplicating the prompt KV cache. The memory savings compound: 10x sampling costs ~1.1x memory, not 10x.
| Metric | Standard Attention | PagedAttention (vLLM) |
|---|---|---|
| GPU Memory Utilization | 40-60% | 85-95% |
| Max Batch Size (A100 80GB, Llama-2-7B) | 32 | 128+ |
| Throughput (tokens/sec) | Baseline | 2-4x Higher |
| Prefix Sharing Overhead | O(n) per sequence | O(1) block refs |
Tuning Block Size and Memory Utilization
Block size trades off fragmentation vs. metadata overhead. Smaller blocks (16 tokens) reduce internal fragmentation but increase block table size. Larger blocks (32-64) reduce table pressure but waste more memory on short sequences. Start with 16 for general workloads. Set gpu_memory_utilization to 0.85-0.90 to leave headroom for CUDA graphs and activation memory. Monitor num_free_blocks in vLLM logs—if it hits zero, you're OOM.
Production Checklist
Deploying vLLM in production requires more than flipping a switch. Profile your actual workload: measure TTFT (time to first token) and TPOT (time per output token) at target concurrency. Use vllm bench to find the sweet spot for max_num_batched_tokens and max_num_seqs. Set up Prometheus metrics (/metrics endpoint) to track queue depth, cache hit rate, and GPU utilization. Configure request-level timeouts and max-token limits to prevent stragglers from blocking the batch.
"PagedAttention is the first attention algorithm that achieves near-optimal memory utilization without sacrificing model accuracy or requiring model modifications.
— Woosuk Kwon et al., vLLM Paper (2023)
Next Steps
Clone the vLLM repo and run the benchmark suite against your model and hardware. Compare PagedAttention vs. Hugging Face TGI on identical prompts. Measure the memory savings from prefix caching on your specific traffic patterns. Then integrate the OpenAI-compatible API server into your stack—it drops in as a drop-in replacement for most inference endpoints.










