The KV-cache is what makes long-context inference expensive
Quadratic cost is the training story. The inference story is the KV-cache: during autoregressive generation, you cache the key and value tensors for every token you've already processed so you don't recompute them on each new token. The cache grows linearly with context length, and at long context it dominates GPU memory.
The numbers are brutal. A 70B-parameter model with 64 attention heads, head dim 128, and 80 layers, serving fp16, uses roughly 2 × n_layers × n_heads × head_dim × 2 bytes per token of context. At 128K tokens that works out to about 40+ GB just for the cache — on top of the model weights. You can fit one user session on a single H100, maybe. Batching collapses.
GQA and MQA — buying back KV memory
Grouped Query Attention (GQA, used by Llama 2/3) shares K and V heads across groups of query heads. Llama 2 70B uses 8 KV heads for 64 query heads, an 8× KV-cache reduction with negligible quality loss. Multi-Query Attention (MQA) goes all the way: a single KV head, an N× reduction, with measurable quality loss on harder tasks. Most modern frontier models use GQA as a default.
Both still grow linearly with context. They reduce the constant — they don't change the slope. Which is why serving a 128K-context model still costs roughly 3–5× per request compared to 8K, even with GQA. That cost ratio shows up in API pricing tiers and in the long-context tax that every long-context provider passes through to customers.