Attention runs as several heads side by side. Each head has its own queries, and in the original transformer each also had its own keys and values. This is multi-head attention (MHA).
Keys and values are what a model keeps in its KV cache, so every key/value head adds to the memory each token costs. Multi-query attention (MQA) takes the opposite extreme: all query heads share a single key/value head. The cache becomes far smaller, but the heads have less to work with.
Grouped-query attention (GQA) sits in between. The query heads are split into a few groups, and each group shares one key/value head. Every query head still asks its own question, but heads in the same group look things up in the same keys and read the same values.
The saving is easy to work out. The KV cache is proportional to the number of key/value heads, so a model with four times as many query heads as key/value heads stores a quarter of the cache that MHA would. For example, Llama 3.1 8B has 32 query heads sharing 8 key/value heads, so its cache is a quarter of the MHA size.
The authors of GQA reported quality close to MHA with speed close to MQA, and many open models now use it. For local AI, it is one of the main reasons long contexts fit on ordinary hardware. The explainer’s calculator shows the cache for real models under MHA and GQA side by side.