Glossary · Attention
Grouped-query attention (GQA)
Also: GQAKV headsnum_key_value_heads
Read it at the depth you need: one sentence · a paragraph · the math · in the models here
1In one sentence
Attention where groups of query heads share one key/value head, shrinking the KV cache by the group size with little loss in quality.
2In a paragraph
In grouped-query attention the model keeps all its query heads but only a few key/value heads; each KV head serves a group of query heads. Llama 3 8B has 32 query heads and 8 KV heads, so four query heads read the same keys and values. The KV cache, which is what limits long contexts and big batches, shrinks by that factor of four. It sits between full multi-head attention (one KV head per query head) and multi-query attention (one KV head for all).
3The math, shapes and parameters
With H query heads, K key/value heads (K divides H) and head size h, the projections are
WQ: [H·h, d] WK: [K·h, d] WV: [K·h, d] WO: [d, H·h]
Query head j uses KV head ⌊j / (H/K)⌋. In code the K key and value heads are repeated H/K times before the usual attention. In config.json K is num_key_value_heads.
KV cache per token = 2 × L × K × h × bytes
Against MHA that is a factor H/K smaller, and the k and v projections shrink by the same factor (a small saving in parameters). The compute per token barely changes: every query head still scores every cached key.
Term by term on Notation Decoder, the sister site: Multi-head attention, decoded
4In the 96 models on this site
81 of the 96 models here use grouped (or multi-query) attention. The largest of each series, per token in BF16, against what the same layers would cache with a KV head for every query head:
| Model | Query / KV heads | Group | KV per token | If it were MHA | KV at 32K |
|---|---|---|---|---|---|
| SmolLM3 3B | 16 / 4 | 4× | 73.7 KB | 294.9 KB | 2.4 GB |
| Granite 3.3 8B | 32 / 8 | 4× | 163.8 KB | 655.4 KB | 5.4 GB |
| Falcon3 10B | 12 / 4 | 3× | 163.8 KB | 491.5 KB | 5.4 GB |
| Gemma 3 27B | 32 / 16 | 2× | 507.9 KB | 1.0 MB | 16.6 GB |
| Gemma 2 27B | 32 / 16 | 2× | 376.8 KB | 753.7 KB | 3.1 GB (its max, 8K) |
| Gemma 4 31B | 32 / 4 | 8× | 901.1 KB | 2.3 MB | 29.5 GB |
| OLMo 3 32B | 40 / 8 | 5× | 262.1 KB | 1.3 MB | 8.6 GB |
| OLMo 2 32B | 40 / 8 | 5× | 262.1 KB | 1.3 MB | 1.1 GB (its max, 4K) |
| Seed-OSS 36B | 80 / 8 | 10× | 262.1 KB | 2.6 MB | 8.6 GB |
| Phi-3.5 MoE | 32 / 8 | 4× | 131.1 KB | 524.3 KB | 4.3 GB |
| DeepSeek-R1-Distill-Llama-70B | 64 / 8 | 8× | 327.7 KB | 2.6 MB | 10.7 GB |
| Qwen2.5 72B | 64 / 8 | 8× | 327.7 KB | 2.6 MB | 10.7 GB |
| Qwen3-Next 80B-A3B | 16 / 2 | 8× | 24.6 KB | 196.6 KB | 805 MB |
| gpt-oss-120b | 64 / 8 | 8× | 73.7 KB | 589.8 KB | 2.4 GB |
| Mixtral 8x22B | 48 / 8 | 6× | 229.4 KB | 1.4 MB | 7.5 GB |
| MiniMax M2 | 48 / 8 | 6× | 254.0 KB | 1.5 MB | 8.3 GB |
| Qwen3 235B-A22B | 64 / 4 | 16× | 192.5 KB | 3.1 MB | 6.3 GB |
| GLM-4.5 | 96 / 8 | 12× | 376.8 KB | 4.5 MB | 12.3 GB |
| Qwen3.5 397B-A17B | 32 / 2 | 16× | 30.7 KB | 491.5 KB | 1.0 GB |
| Llama 4 Maverick (17B-128E) | 40 / 8 | 5× | 196.6 KB | 983.0 KB | 6.4 GB |
| Llama 3.1 405B | 128 / 8 | 16× | 516.1 KB | 8.3 MB | 16.9 GB |
| Nemotron 3 Ultra 550B-A55B | 64 / 2 | 32× | 12.3 KB | 393.2 KB | 403 MB |
| Inkling | 64 / 8 | 8× | 495.6 KB | 2.2 MB | 16.2 GB |
| Ling-1T | 64 / 8 | 8× | 327.7 KB | 2.6 MB | 10.7 GB |
Introduced in Ainslie et al., “GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints” (2023).
Related
Multi-head attention (MHA) · Multi-query attention (MQA) · Multi-head latent attention (MLA) · KV cache · every term