Match each attention variant to its KV-cache memory reduction strategy.
MHA: per-head K/V. MQA: one shared K/V (max compression, quality hit). GQA: K/V shared in groups (Llama-2/3 sweet spot). MLA: low rank latent K/V (DeepSeek-V2/V3, smaller than MQA at MHA quality).
Imagine a team of detectives (query heads) each needing a copy of the case file (K, V). MHA gives each detective their own file, best for the work but lots of storage. MQA gives the whole team one shared file, saves space but everyone's investigation is more similar. GQA breaks the team into small groups and gives one file per group, balanced. MLA compresses the file into a shorthand notebook that the team decodes when needed, smallest storage of all.
Detailed answer & concept explanation~7 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
Position each on the sharing spectrum, quote cache-savings ratios, name production users, explain GQA uptraining, and articulate MLA's structural difference (latent compression vs head sharing).
| Variant | K, V heads per layer (vs N query heads) | Cache savings vs MHA | Quality vs MHA | Notable users |
|---|---|---|---|---|
| MHA | N | 1x (baseline) | Baseline | GPT-2/3, Llama-1, BERT |
| MQA | 1 | Nx | Drops on some tasks | PaLM, Falcon-1, StarCoder |
| GQA | G (typically N/8) | N/G x (~8x at G=8) | Near-MHA | Llama-2/3, Mistral, Qwen |
| MLA | Latent of dim d_c (~512), no head count | ≈ 10-20x (depends on d_c) | Matches MHA per DeepSeek | DeepSeek-V2/V3 |
Real products, models, and research that use this idea.
- Llama 4 Maverick, Llama-3 70B/8B/405B, Llama-2 70B: GQA with 8 KV heads.
- Mistral Large 3, Mistral 7B, Mixtral 8x7B, Qwen 3: GQA with 8 KV heads on 32+ query heads.
- DeepSeek-V2, V3, and V4 (2026): MLA with latent dim around 512.
- PaLM, original Falcon, StarCoder: MQA (historical; mostly retired in 2026).
- Original GPT-2/3, Llama-1, BERT: MHA (legacy baselines).
What an interviewer would ask next. Try answering before peeking at the approach.
QHow does Ainslie et al. 2023 uptrain an existing MHA checkpoint to GQA?
QWhy doesn't MLA destroy too much information by compressing K, V to a small latent?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Confusing MQA with GQA. MQA has exactly one shared K, V across ALL query heads; GQA has multiple K, V groups (more than 1 but fewer than num_query_heads).
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.