Home Knowledge Base Grouped-Query Attention (GQA)

Grouped-Query Attention (GQA) is an attention architecture that provides a tunable middle ground between Multi-Head Attention (MHA) and Multi-Query Attention (MQA) — using G groups of KV heads (where each group serves multiple query heads) to achieve near-MQA inference speed with near-MHA quality, making it the recommended default for new LLM architectures as adopted by Llama-2 70B, Mistral, Gemma, and most modern open-source models.

What Is GQA?

Architecture Visualization

MHA:  Q₁ Q₂ Q₃ Q₄ Q₅ Q₆ Q₇ Q₈   (8 query heads)
      K₁ K₂ K₃ K₄ K₅ K₆ K₇ K₈   (8 KV heads — one per query)

GQA:  Q₁ Q₂ Q₃ Q₄ Q₅ Q₆ Q₇ Q₈   (8 query heads)
      K₁ K₁ K₂ K₂ K₃ K₃ K₄ K₄   (4 KV groups — shared pairs)

MQA:  Q₁ Q₂ Q₃ Q₄ Q₅ Q₆ Q₇ Q₈   (8 query heads)
      K₁ K₁ K₁ K₁ K₁ K₁ K₁ K₁   (1 KV head — shared by all)

KV-Cache Comparison

MethodKV HeadsKV-Cache SizeMemory vs MHAQuality vs MHASpeed vs MQA
MHAH (e.g., 64)H × d × seq_len1× (baseline)BaselineSlowest
GQA-888 × d × seq_len1/8× = 12.5%~99%~90% of MQA
GQA-444 × d × seq_len1/16× = 6.25%~98%~95% of MQA
MQA11 × d × seq_len1/H× = 1.6%~95-98%Baseline (fastest)

Converting MHA Checkpoints to GQA

One key advantage: existing MHA models can be converted to GQA by mean-pooling the KV heads within each group and continuing training (uptraining). This avoids training from scratch.

# Convert 64 KV heads → 8 groups
# Each group = mean of 8 consecutive KV heads
group_1_K = mean(K_1, K_2, ..., K_8)
group_2_K = mean(K_9, K_10, ..., K_16)
...
# Then uptrain for ~5% of original training tokens

Models Using GQA

ModelQuery HeadsKV Heads (Groups)Ratio
Llama-2 70B6488:1
Mistral 7B3284:1
Gemma161-8 (varies by size)Varies
Llama-3 8B3284:1
Llama-3 70B6488:1
Qwen-22847:1

Grouped-Query Attention is the recommended default attention architecture for modern LLMs — providing a configurable KV-cache reduction (4-8× typical) that preserves near-full MHA quality while approaching MQA inference speeds, with the additional advantage of being convertible from existing MHA checkpoints through mean-pooling and uptraining rather than requiring training from scratch.

grouped-query attention (gqa)grouped-query attentiongqallm architecture

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.