Bookkeeping of Variants of attention
= query heads, = key/value heads, = group size.
| Variant | Per-token KV | , , , | |
|---|---|---|---|
| MHA | 512 KiB/token | ||
| GQA- | 128 KiB (), 64 KiB () | ||
| MQA | 1 | 16 KiB/token | |
| MLA | latent | ~36 KiB/token (, ) |
MLA caches a per-token low-rank latent shared by all heads, plus a decoupled RoPE vector . and are reconstructed by up-projections that can be absorbed into and .
Decode attention reads the whole KV cache to produce one token. Arithmetic intensity of that read: The cancels: intensity is independent of context length and equals the group size (times ). MHA gives FLOP/byte in FP16, hopelessly memory-bound. GQA-8 gives 8; MQA gives 32. Each query group reuses one KV read, which is the whole point.
Same effect via the batch axis: sequences each read their own KV, so unlike weights, KV traffic does not amortize over the batch. That is why appears in the throughput ceiling in Batch Size and Latency Tradeoff.
Quality tradeoff
- MQA is the aggressive end: measurable quality loss and training instability, largely abandoned for large models.
- GQA with recovers MHA quality within noise while cutting the cache 4–8×. The current default.
- MLA matches or beats MHA quality at an MQA-sized cache, because the latent is a learned low-rank bottleneck rather than a hard head-sharing constraint. Cost: a more complex kernel and more compute in the projections.
Also note: GQA changes the KV tensor layout, so tensor parallelism can only shard KV heads ways. Beyond you must replicate the KV cache across ranks, an easy and expensive mistake at high TP. MLA has the same issue in sharper form (one shared latent), which is one reason MLA models lean on data/expert parallelism instead.
Whiteboard version
Write , divide free HBM by for concurrency (KV Cache Sizing), divide by for the throughput ceiling. Everything else about the variant is quality and kernel availability.
Rule of thumb
GQA group size is simultaneously the KV memory divisor and the decode-attention arithmetic-intensity multiplier. Pick unless you have a reason not to.