Grouped-Query Attention GQA
Grouped-query attention is a variant between multi-head attention and multi-query attention: it lets several query heads share one group of key-value heads. With almost no loss of quality it compresses the key-value cache at inference time by a large margin, making it the standard compromise of contemporary mainstream large models and a concept that cannot be avoided when understanding the inference cost of large models.
Core Principles
In standard multi-head attention, every query head has its own independent key head and value head. During autoregressive generation the keys and values of historical tokens must be cached and reused, otherwise every generated token would require recomputing the whole history. The cache size is proportional to the number of layers, the number of heads and the context length, so with long contexts it often becomes the largest single consumer of memory, and it directly determines concurrency capacity.
Multi-query attention takes the extreme route: all query heads share a single group of key-value heads, so the cache is compressed to the minimum and memory traffic during decoding drops sharply, but expressive diversity suffers and quality degrades visibly on some tasks. Grouped-query attention takes the middle path: the heads are split into several groups, and the query heads within a group share one set of key-value heads. When the number of groups equals the number of query heads it degenerates into standard multi-head attention, and when the number of groups is one it degenerates into multi-query attention, so it is a continuously adjustable spectrum on which engineering can pick a position according to the deployment budget. Its expressiveness is determined by the number of groups, while memory usage is roughly inversely proportional to the ratio of total heads to groups, and the two form a clear trade-off curve.
The key insight is that the inference bottleneck is the key-value cache, not the queries. Compressing the key-value heads directly cuts memory usage and memory traffic during decoding, while the query heads stay unchanged, so most of the expressiveness is preserved. In practice a low-cost conversion path is common: first train with multi-head attention, then average-pool the key-value heads into the grouped form, or complete the migration with a small amount of continued training, so that almost nothing has to be rebuilt from scratch.
The 70-billion-parameter version of LLaMA 2 and the whole LLaMA 3 family adopted this design, and most open-source and commercial models have followed since, making it the de facto standard quickly. Practice shows that with about eight groups the key-value cache can be squeezed to one quarter to one eighth of its original size while benchmark scores stay almost unchanged, and this cost-performance ratio is the fundamental reason it has been so widely adopted.
Key Points
First, what is compressed is the cache, not the computation: training compute is basically unchanged and the benefit concentrates on the inference side, which is where it differs in positioning from sparse attention. Second, the number of groups is a tunable hyperparameter: more groups moves closer to multi-head and improves quality but enlarges the cache; fewer groups saves memory but limits expressiveness, so it must be weighed against the deployment scenario.
Third, it is coupled with tensor parallelism: the number of groups must be divisible by the degree of parallelism, otherwise the split is uneven, so head counts and device counts must be planned in advance for distributed deployment. Fourth, it can be stacked with weight quantization to compress the cache further, and together the two determine whether long contexts can run at all and how much concurrency they can sustain.
Fifth, the empirical judgment is: product-oriented models with limited training resources and heavy inference pressure almost always choose it, while research settings that pursue ultimate single-point quality and do not count memory can still do fine with full multi-head attention.
Common Misconceptions
A common misunderstanding is that grouped-query attention noticeably lowers training quality, when in fact with a suitable number of groups the quality loss is very small and many model evaluations show no visible difference. Another misunderstanding conflates it with sparse attention; it does not change the connection pattern of attention, only the way key-value heads are shared.
Application Scenarios
Large-model inference deployment, long-context serving, highly concurrent online question answering, small on-device models, batch throughput optimization, multi-turn dialogue cache management, and streaming generation of video and speech.