What grouped-query attention is
Multi-head attention gives every query head its own key and value head; multi-query attention (the MQA tab) gives all of them one. Grouped-query attention (GQA) sits between the two: the query heads are split into groups, and each group shares one key head and one value head. With equal to the number of heads it is multi-head attention, with it is MQA.
This page records it in Qwen2.5-0.5B: 24 layers, every other one recorded, 14 query heads in 2 groups of 7, so 2 key heads and 2 value heads, each 64-dimensional, with rotary position embeddings (RoPE) on the queries and keys. The prompts are the MHA tab's three, so the two pages can be compared head for head.
Groups
Query head reads key and value head (counting from 0), so query heads 1–7 share the first pair and 8–14 the second:
The Query heads control in the toolbar draws the two groups of seven, each pointing at its K and V; the group of the selected head is highlighted. On the head card the Key and Value titles carry the group number and the query heads that share them. In code the sharing is a copy: the model computes 2 key heads and repeats each 7 times before the ordinary attention product.
Rotary position embeddings
Qwen2.5 adds no position vector to its inputs. Instead, RoPE rotates each query and key by an angle proportional to its position, pair by pair: dimensions and of a 64-dimensional head form a pair, turned by at position , with and base :
Because rotations compose, : the score depends on how far apart the two tokens are, not where they are. The RoPE boxes on the head card open the rotation. A key head is rotated once and read by all seven query heads of its group; values are never rotated.
The cache it keeps
Per token and layer, Qwen2.5-0.5B caches numbers for keys and values. Multi-head attention with the same 14 heads would cache , seven times more. The number of groups is the dial between cache size and quality: one group shares too much, one group per head saves nothing.
Ainslie et al. also showed that a model need not be trained this way from the start: a multi-head checkpoint can be converted by mean-pooling each group's key and value heads into one and then trained further with 5 % of the original pre-training compute, after which GQA came close to multi-head quality at nearly MQA's speed.
Where it came from
GQA was introduced by Ainslie et al. in 2023 as a generalisation of Shazeer's multi-query attention. Llama 2 used it in its largest models the same year, and it has since become the default in open decoder models, including the Qwen2.5 family recorded here. RoPE comes from Su et al. (2021). MLA (the MLA tab) shrinks the cache further by caching a compressed latent instead of fewer heads; the Window tab shows a model that combines key sharing with a limited attention span.
Papers
- GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints Introduces grouped-query attention and the recipe for uptraining multi-head checkpoints into it.
- Qwen2.5 Technical Report The model family this page records, built with grouped-query attention and RoPE.
- Fast Transformer Decoding: One Write-Head is All You Need Multi-query attention, the one-group end of GQA (the MQA tab).
- RoFormer: Enhanced Transformer with Rotary Position Embedding Rotary position embeddings, which rotate the queries and keys on this page.
- Llama 2: Open Foundation and Fine-Tuned Chat Models An early large open model family to adopt grouped-query attention.