The Standard GQA KV-Cache Formula

Every autoregressive token stores a Key vector and a Value vector across every transformer layer. The exact byte footprint per token is: 2 * layers * kv_heads * head_dim * bytes_per_element. For Llama 3.3 70B (80 layers, 8 KV heads, 128 head_dim) at FP16 (2 bytes), each 1,000 tokens consumes ~312.5 MiB. At 128k context, KV-cache alone requires 40 GiB on top of model weights!

How DeepSeek MLA Changes the Equation

DeepSeek-V2, V3, and R1 replace full K/V matrices with Multi-Head Latent Attention (MLA), caching only a compressed latent vector plus a small decoupled RoPE key (typically 576 elements per layer). Even with 61 layers and 671B parameters, DeepSeek-R1 needs only ~67 MiB per 1,000 tokens at FP16.

KV-Cache Quantization (Q8_0 and Q4_0)

Passing --cache-type-k q8_0 --cache-type-v q8_0 in llama.cpp or --kv-cache-dtype fp8 in vLLM cuts KV-cache memory roughly in half with near-zero perplexity impact, immediately doubling your safe OOM Context Horizon.

Core Physics Formula

GQA Bytes/Token = 2 * layers * kvHeads * headDim * kvBytes
MLA Bytes/Token = layers * mlaCacheDim * kvBytes
Total KV (GiB)  = (Bytes/Token * contextTokens * concurrentUsers) / 1024^3