What is grouped-query attention?

Grouped-query attention is an attention layout in which query heads in multi-head attention are split into groups, each sharing a single key and value head, which reduces the key and value data stored at inference.

Unlike multi-query attention, where all query heads share one key and value head, grouped-query attention has several key and value heads, but fewer than the query heads. In classic multi-head attention every query head has its own key and value head.

Topic
Machine learning, models and training
Also known as
GQA
Origin
2023, Ainslie et al.

How grouped-query attention works

  1. Query heads are split into equal-sized groups.
  2. Each group computes one key and one value projection that its query heads share.
  3. At inference the KV cache stores data per key and value head rather than per query head; calculation: with 32 query heads and 8 key and value heads it shrinks by a factor of 4 (32 / 8 = 4).
  4. Existing multi-head models can be converted to this layout with brief extra training.

In more detail

The memory-bandwidth bottleneck

In autoregressive decoding, loading the KV cache from GPU High Bandwidth Memory (HBM) at every generated token makes inference memory-bandwidth-bound rather than compute-bound. By shrinking the KV tensor per token, GQA directly reduces HBM traffic and boosts tokens-per-second throughput as well as maximum concurrent batch size.

The tensor parallelism constraint

When scaling inference across multiple GPUs with Tensor Parallelism, each shard typically needs at least one KV head; if the tensor-parallel degree exceeds the number of KV heads (for instance, 8 KV heads split across 16 GPUs), KV heads must be replicated, reducing memory savings. Recent deployments also combine GQA with FP8 KV-cache quantisation.

Converting an existing model to GQA

Converting an existing Multi-Head Attention checkpoint to GQA ("uptraining") works by mean-pooling the key and value projection weights within each head group and continuing pre-training for about 5% of the original pre-training compute, as the original paper reports. This allows organisations or model labs to retrofit legacy models without full retraining from scratch.

Commonly confused terms

TermHow it differs
Multi-head latent attention (MLA)Multi-Head Latent Attention (MLA, popularised by DeepSeek-V2 and V3) compresses keys and values into a shared low-rank latent vector and reconstructs them via absorbed projections, achieving even smaller KV-cache footprints per token than GQA at the cost of extra matrix projection logic.

Why grouped-query attention matters for on-premises AI

In long-context, multi-user inference, the KV cache takes much of GPU memory. Grouped-query attention shrinks it, freeing room on the same GPU for longer contexts or more concurrent requests while reducing memory bandwidth needs. This directly affects model choice in in-house hardware planning. Quality loss is smaller than with multi-query attention, which is why it is common in recent open-weight models.

ON-PREMISES EXAMPLE

Comparing two models for an in-house clinical note summarisation assistant, a hospital checks their key and value head counts; the grouped-query attention model handles longer patient files in the same GPU memory, so it comes out ahead.

Common questions

How does grouped-query attention differ from multi-query attention?

Multi-query attention has one key and value head. Grouped-query attention has several, each serving a group of query heads.

Does grouped-query attention reduce quality?

It can differ only slightly from classic multi-head attention. It loses less quality than multi-query attention while keeping the memory gain.

Sources

In the glossary: Glossary, E to L

What does this term mean for your infrastructure?

We can work out together in a technical assessment how it maps onto your data, hardware and security requirements.

Request a technical assessment →

This site sets no cookies. Visitor numbers are counted in aggregate using a cookieless method that does not identify anyone. See the Privacy Policy for details.