Learn AI Math

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.

DimensionGrouped-Query Attention (GQA)Multi-Head Attention (MHA)
KV heads1 KV pair shared per group of Query heads1 KV pair per Query head
KV cache memorySeveral times smaller (e.g., 8× with 8 query heads per group), usually with little quality lossLarge—a bottleneck for long-context serving
AdoptionCommon in modern open models such as Llama 3, Qwen and MistralOriginal Transformer and many earlier LLMs

Last updated · Fact-checked by The AI Math

Linking to this page from a lesson or article?

Like this explanation? Get one every week.

The AI Math newsletter turns confusing AI news into plain English. No hype, no jargon walls.