Expand MQA and state its KV-cache cost tradeoff
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.
Detailed answer & concept explanation~5 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.
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.
- PaLM, the early Google decoder-only model, used MQA throughout to keep its KV cache small at scale.
- Falcon-40B from TII shipped MQA, which let it serve faster decode than equivalently sized MHA models.
- Llama 3.1 and Mistral Large 3 dropped MQA in favor of GQA at group size 8, recovering quality with most of the savings.
- ChatGLM and several early 7B-class open models adopted MQA to keep decoder KV cache small before GQA became standard.
- Some on-device deployments of small Llama variants still use MQA when KV cache must fit in tight phone-class memory budgets.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy does collapsing K and V hurt quality more than collapsing Q would?
QCan you upgrade an MHA checkpoint to MQA without retraining from scratch?
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 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.
Same topic, related formats. Practice these next.