Expand MQA and state its KV-cache cost tradeoff
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
MQA = Multi-Query Attention: every Q head keeps its own projection but all heads share one K and one V, shrinking the KV cache by n_heads at a measurable quality cost.
Picture a meeting room with twenty people asking different questions, each consulting their own personal filing cabinet. MQA tears out nineteen of the cabinets and tells everyone to share the one that remains. The questions still vary person to person, but they all consult the same source of information. That makes the room dramatically cheaper to run, because there is only one cabinet to maintain. The catch is that the single shared cabinet has less room to specialize, so subtle answers may drop in quality. MQA is that aggressive sharing trade, useful when you need to squeeze the last byte of memory out of a deployment.
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.
3 min: acronym expansion + Q stays per head, K and V collapse to one + factor of n_heads cache reduction + measurable quality regression + PaLM and Falcon-40B as adopters, modern default now GQA.
| Variant | K and V heads | KV cache size | Quality vs MHA |
|---|---|---|---|
| MHA | n_heads | Full | Baseline |
| MQA | 1 | 1 / n_heads | Measurable regression on harder tasks |
| GQA (G = 8) | G = 8 | G / n_heads | Within a fraction of a percent |
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 shares one K and V across the entire layer; GQA shares per group of heads.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.