Grouped-Query Attention (GQA)
What is Grouped-Query Attention (GQA)?
In one sentence: Grouped-query attention is a middle ground where groups of heads share keys and values, balancing speed and quality.
Instead of every head having its own keys and values, or all heads sharing one set, heads are split into groups that each share a set. This keeps most of the quality of full attention while saving a lot of memory.
What does Grouped-Query Attention (GQA) look like?
A model with 32 query heads might use 8 key-value groups, so every 4 heads share one set.
Why does Grouped-Query Attention (GQA) matter?
GQA is used in many modern models like Llama to run faster and handle longer context.
Grouped-Query Attention (GQA) vs. Multi-Head Attention (MHA)
MHA gives every query head its own key and value heads; GQA lets a group of query heads share one key/value pair, which shrinks the KV cache a lot at long context.
| Dimension | Grouped-Query Attention (GQA) | Multi-Head Attention (MHA) |
|---|---|---|
| KV heads | 1 KV pair shared per group of Query heads | 1 KV pair per Query head |
| KV cache memory | Several times smaller (e.g., 8× with 8 query heads per group), usually with little quality loss | Large—a bottleneck for long-context serving |
| Adoption | Common in modern open models such as Llama 3, Qwen and Mistral | Original Transformer and many earlier LLMs |
Last updated · Fact-checked by The AI Math
Linking to this page from a lesson or article? <a href="https://getaimath.com/dictionary/grouped-query-attention-gqa/">Grouped-Query Attention (GQA), explained simply</a> (The AI Math Dictionary)