02 · Reference notes
← All visual guidesGrouped-Query Attention Explained
Grouped-query attention (GQA) reduces KV-cache size by letting groups of query heads share key and value heads, making LLM decoding more memory-efficient.
01 · Definition
What is Grouped-Query Attention?
Each query head can still ask a different question about the context. The sharing happens only in the saved key and value representations that must be read repeatedly while a model generates tokens.
02 · Mechanism
Why the KV cache matters
During autoregressive decoding, a model stores key and value vectors for every earlier token. With many attention heads and a long conversation, that cache can dominate memory bandwidth and limit how many requests a server can run at once.
03 · Mechanism
How GQA groups heads
Multi-head attention gives every query head its own key and value head. Multi-query attention shares one KV head across all queries. GQA is the middle ground: several query heads form a group and read from one shared key/value head.
04 · Mechanism
What changes and what stays separate
The query projections remain separate, so heads can retain distinct attention patterns. Only the cache is shared. That is why GQA can deliver most of the memory benefit without collapsing all heads into one reader.
05 · Mechanism
When GQA helps
The benefit is strongest at inference, especially for long contexts and batch-heavy serving. Fewer KV heads mean less cache storage and less data moved from memory for each generated token; the trade-off is choosing enough groups to retain quality.
Source · Original paper