Production LLM Deployment: vLLM & KV Caching
Achieve 10x higher serving throughput using PagedAttention, KV Cache optimization, continuous batching, and TensorRT-LLM.
1. The KV Cache Bottleneck in Autoregressive Generation
During generation, token \(t\) requires attention keys \(K\) and values \(V\) from all previous tokens \(1 \dots t-1\). Recomputing them at each step is \(O(T^2)\). The **KV Cache** stores these matrices in GPU VRAM.
\[ \text{Memory}_{\text{KV}} = 2 \times 2 \times n_{\text{layers}} \times n_{\text{heads}} \times d_{\text{head}} \times b \times s \quad \text{(bytes)} \]
2. PagedAttention & vLLM (Kwon et al., SOSP 2023)
Standard contiguous VRAM allocation wastes 60-80% of memory due to fragmentation. PagedAttention partitions the KV cache into non-contiguous virtual memory blocks (pages), increasing batch concurrency and serving throughput by **up to 24x**!