Bookkeeping of Variants of attention
= query heads, = key/value heads, = group size.
| Variant | Per-token KV | , , , | |
|---|---|---|---|
| MHA | 512 sKiB/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 .
Why is Decode attention memory-bound:
-
Numerator: For each of the query heads and past tokens, we do two vector operations:
- Dot product ( FLOPs for multiply-add)
- Weighted sum scores:
- Total = FLOPs
-
Denominator:
- Need to read the and tensors of dimension across heads and past tokens, where each element takes bytes.
-
and cancel out: making the context longer increases FLOPs and memory reads at the same rate - the AI is the same.
-
For MHA () in FP16 (): FLOP/byte.
- H100 has a ridge point ~200-300 FLOPs/byte so significantly memory bound
-
GQA (,), MQA () raises arithmetic intensity.
In standard dense linear layers (FFNs/projections), increasing batch size increases arithmetic intensity because all sequences share the same model weights (since you read the weights once and multiply them across token) However, in decode attention, every user in the batch has their own unique conversation history (their own KV cache).
- Increasing batch size multiplies FLOPs by , and multiplies KV cache reads by .
- The cancels out in the ratio, meaning batching never increases attention arithmetic intensity.
- Thus, maximum decode throughput is strictly capped by memory bandwidth divided by the KV cache size of the batch: (where is the per-token KV size from the table).
When running a huge model across multiple GPUs using Tensor Parallelism (TP), you split the attention heads evenly across GPUs:
- With GQA-8 (): If you use , each GPU gets 1 KV head, but if you scale to or , you can’t split 8 KV heads 16 ways, so you have to duplicate the KV cache across GPUs, wasting memory and bandwidth.
- With MLA: Because there is only one shared latent vector per token (effectively in terms of sharding), splitting across TP ranks forces every TP rank to store/read the full latent cache. Which is why MLA-based architectures (like DeepSeek) avoid high TP and instead rely on Data Parallelism (DP) for attention and Expert Parallelism (EP) for MoE layers.