Home Knowledge Base Grouped-Query Attention (GQA)

Grouped-Query Attention (GQA) is the attention architecture variant that shares Key and Value heads among groups of Query heads — reducing the KV cache memory footprint and inference cost by a factor equal to the group size, while retaining most of the quality of standard Multi-Head Attention (MHA), making it the dominant attention design in modern large language models including LLaMA 2/3, Mistral, and Gemma.

Attention Head Variants

VariantQuery HeadsKV HeadsKV Cache SizeQuality
MHA (Multi-Head)HHH × d_k × 2Best
GQA (Grouped-Query)HH/G (G groups)H/G × d_k × 2Near-MHA
MQA (Multi-Query)H11 × d_k × 2Slightly lower

How GQA Works

Standard MHA (H=32 heads):
Q: 32 heads × d_k    K: 32 heads × d_k    V: 32 heads × d_k
Head i attends using Q_i, K_i, V_i

GQA (H=32 query, G=8 KV groups):
Q: 32 heads × d_k    K: 8 groups × d_k    V: 8 groups × d_k
Query heads 0-3 share KV group 0
Query heads 4-7 share KV group 1
...up to query heads 28-31 share KV group 7

Memory and Compute Savings

Why GQA Over MQA

Models Using GQA

ModelQuery HeadsKV HeadsRatio
LLaMA-2 70B6488:1
LLaMA-33284:1
Mistral 7B3284:1
Gemma161 (MQA)16:1
Falcon 40B641 (MQA)64:1
GPT-4 (rumored)GQA variant

Training Considerations

Grouped-Query Attention is the standard attention design for modern LLMs — by offering the near-optimal quality/efficiency tradeoff for KV cache reduction, GQA enables the practical deployment of large models at long context lengths where full MHA would be prohibitively memory-intensive.

grouped query attentiongqamulti query attentionmqaattention head sharing

Explore 500+ Semiconductor & AI Topics

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