Define GQA in transformer attention
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
GQA = Grouped-Query Attention: Q heads are split into G groups that share one K and one V head per group, shrinking the KV cache by the group factor.
Imagine an office where every analyst (a query) has a personal filing cabinet (keys and values). Reading from twenty cabinets every time you decode a token is slow and expensive. Picture grouping the analysts into teams of eight, where each team shares a single cabinet. The analysts still bring their own questions to the table, but the lookup happens against one shared filing cabinet per team. You read far less from the cabinet room each step, and the answers stay almost as good as before. GQA is that shared-cabinet trick for attention, and it is why modern open-weights chatbots feel fast on the same hardware.
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-side untouched, K and V grouped + KV cache formula + Llama 3.1 and Mistral as canonical adopters + the G = 8 sweet spot.
| Variant | KV head count | KV cache size | Quality vs MHA |
|---|---|---|---|
| MHA | n_heads | Full | Baseline |
| GQA (G = 8) | G = 8 | Roughly 1/4 of MHA at 32 heads | Within a fraction of a percent |
| MQA | 1 | 1 / n_heads | Measurable regression on harder tasks |
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.
Saying GQA reduces FLOPs. The savings are bandwidth and KV-cache memory, not compute. Q projections still run per head.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.