The KV Cache Memory Bottleneck
Understanding KV Cache Expansion
During autoregressive decoding, the self-attention mechanism requires access to key and value vectors from all prior tokens. Recomputing these vectors at every step would lead to O(N2) compute complexity. To avoid this, we cache them in VRAM.
Formula for KV Cache Size
For a model with L layers, Hkv key-value heads (with GQA group ratio G = Hq / Hkv), dimension per head Dhead, batch size B, sequence length S, and precision bytes per element P (e.g. 2 for FP16/BF16, 1 for FP8/Q8_0):
KV Cache (Bytes) = 2 × L × H_kv × D_head × B × S × P
For a 70B model with 80 layers, 8 KV heads (8:1 GQA), 128 head dim, FP16 precision (P = 2), and 8,192 sequence length: each user session consumes 2.68 GB (2.50 GiB = 2,684,354,560 bytes) of VRAM solely for the KV cache! Quantizing Paged KV blocks to Q8_0/Q4_0 (as in Infinity's HARNESS Engine, achieving 17.3M blocks/sec allocation with 1.29% peak fragmentation) compresses a 32K-context 32B Dense KV cache down to just 208 MiB.
Profile KV cache memory growth across concurrent user sessions and configure GQA compression.