AI Dojo Open on the typewriterThe typewriter

Explainer

Grouped-query attention

2 min read
Assumes: you know what the KV cache stores.
First published 19 November 2026. Last edited 19 November 2026.

A design in which several query heads share one set of keys and values, so the KV cache is smaller.

An attention layer runs several heads side by side. A head is one separate way of comparing tokens, with its own queries, keys and values. In the original multi-head attention (MHA), every query head has its own keys and values. Multi-query attention (MQA) shares one set of keys and values across all the query heads (Shazeer, 2019). Grouped-query attention (GQA) sits between the two: each group of query heads shares one key-value head (Ainslie et al., 2023). The cache stores keys and values only, so its size follows the number of key-value heads, not query heads.

Illustration. Three invented models have 32 layers, 32 query heads, a head size of 128 and 2-byte numbers. Only their key-value heads differ:

DesignKV headsPer token10,000 tokens
MHA32524,288 bytesabout 5.2 GB
GQA8131,072 bytesabout 1.3 GB
MQA116,384 bytesabout 0.16 GB

That is why two models of similar size can need very different cache memory. Real configurations show the choice: Qwen3-8B lists 32 attention heads and 8 key-value heads (its configuration file). Sharing has a price. The GQA authors write that MQA “can lead to quality degradation”, and report GQA quality close to multi-head attention at a speed comparable to MQA.

Going deeper

Multi-head latent attention (MLA) shrinks the cache by a different mechanism, compression: it compresses keys and values into a smaller latent vector and caches that. DeepSeek-V2's authors report a KV cache 93.3% smaller than their earlier DeepSeek 67B, a comparison between two different models rather than a test of MLA alone (DeepSeek-V2 paper). GQA keeps every token, so it is not sparse attention.

In the long read: heads and layers. Then try Estimate the KV cache.