Match each attention variant to its KV-cache memory reduction strategy.
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
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.
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.
What an interviewer would ask next. Try answering before peeking at the approach.
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.