Grouped-Query Attention (GQA)
Generating text is a memory problem more than an arithmetic one. Each new token attends to every earlier one, so the keys and values for the whole sequence are kept in the KV cache — and in standard attention that cache carries a separate copy for every head. Grouped-query attention is the compromise that shrinks it without hurting quality.
The ideaIn ordinary multi-head attention each head owns its queries, keys and values. Multi-query attention went to the opposite extreme, sharing one set of keys and values across all heads: the cache collapses, but quality drops measurably and training becomes less stable. GQA sits between them. Query heads are split into groups, and each group shares one key-value pair — sixty-four query heads with eight key-value groups, for instance, an eightfold cache reduction. A model already trained with full multi-head attention can be converted with a short uptraining pass instead of being retrained from scratch.
Why nearly every recent model uses it- A smaller KV cache means more concurrent users on one GPU, which is what serving cost per request actually measures.
- Long contexts become affordable, since the cache grows linearly with sequence length.
- Decoding speeds up, because less data crosses the memory bus for each token.
- Benchmark quality lands close to full multi-head attention, unlike the multi-query extreme.
You will find it in LLaMA 2's 70B model and every size of LLaMA 3, as well as Mistral and Gemma — a quiet architectural default rather than a tuning knob, and a large part of why those models serve long contexts at a sane price.
Grouped-query attention (GQA) lets groups of query heads share one set of keys and values, rather than each head holding its own as in multi-head attention. This shrinks the KV cache several-fold, cutting memory per request and speeding up memory-bound decoding, while keeping quality close to full multi-head attention — unlike multi-query attention's single shared pair. It is the default in LLaMA 3, Mistral and Gemma, and it is what makes long contexts and large batches affordable.
Imagine a team of sixty translators, each insisting on a private copy of a growing stack of notes. The office runs out of shelf space fast. Grouped-query attention is the simple fix: put the translators into small groups and give each group one shared copy. The work still gets done, and the shelves hold a fraction of the paper. In a language model, those notes are what it is holding on to about the conversation so far. Sharing them means the same computer can handle longer conversations and more people at once — which is why almost every recent model is built this way.