Grouped-query attention (GQA) is a mechanism that splits the query heads into groups, with the heads in the same group sharing one key head and one value head. Ainslie et al. proposed it in 2023 in the paper "GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints" (EMNLP 2023).
The motivation lies in the weaknesses of multi-query attention (MQA). MQA uses a single set of keys and values for all heads, which reduces the amount of data loaded when generating text one word at a time and makes generation much faster. On the other hand, it can degrade quality or make training unstable. GQA does not reduce the key and value heads all the way to one; it stops at an intermediate number .
Depending on the value of , GQA bridges the following two (Section 2.2 of the paper).
| Number of query heads sharing one key/value head | Equivalent to | |
|---|---|---|
| 1 | Multi-head attention | |
| GQA | ||
| MQA |
For head in group of the groups, the computation is:
are per-group weights, and heads in the same group use the same ones. is scaled dot-product attention. The paper calls a model with groups GQA- (for example, GQA-8).
If eight researchers all pass around a single reference binder (MQA), waiting time is minimal, but the perspectives they can investigate are limited. If they work in pairs with one binder per pair (GQA), the effort of carrying binders hardly changes, yet each pair can investigate from a different perspective.
The left side of the figure at the top of the article shows the computation flow, and the right side compares the number of key and value heads.

