Skip to content

Grouped-query attention shares key and value heads

2026-11-07

During decoding, every new token must load the keys and values of everything before it. If each of H query heads has its own key and value head, that is a lot to load. Multi-query attention keeps a single key head and a single value head, which "drastically speeds up decoder inference," but quality can drop.

Grouped-query attention divides the H query heads into G groups. Each group shares one key head and one value head. With G = 1 it is multi-query attention, and with G = H it is ordinary multi-head attention, so G is a dial between the two. The key-value cache shrinks by a factor of H/G; with 32 query heads and 8 groups, that is 4 times smaller.

An existing multi-head model can be converted. Each group's key and value head is the mean of the original heads in the group, and the model is then trained further on about 5% of its original pre-training compute. The paper found mean pooling worked better than keeping one head or starting from random weights.

Does it cost quality? On T5-XXL the paper's table gives 1.51 s per sample and quality 47.2 for multi-head, 0.24 s and 46.6 for multi-query, and 0.28 s and 47.1 for 8 groups. Nearly all of the speed, almost none of the quality loss.

Ainslie et al., EMNLP 2023, §2.2, §3.1 and Table 1