GQA

Grouped-query attention reduces key-value cache cost by letting multiple query heads share fewer key/value heads.

Metadata

FieldValue
PaperGQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints
AuthorsJoshua Ainslie, James Lee-Thorp, Michiel de Jong, Yury Zemlyanskiy, Federico Lebron, Sumit Sanghai
Year2023
VenueEMNLP 2023
arXiv2305.13245
ACL Anthology2023.emnlp-main.298
PrecursorFast Transformer Decoding: One Write-Head is All You Need
Statusfull note started

One-Line Takeaway

GQA interpolates between full multi-head attention and multi-query attention: keep many query heads for expressivity, but use fewer key/value heads to reduce autoregressive decoding memory bandwidth.

Question

Attention Is All You Need uses multi-head attention, where each head has its own query, key, and value projections:

This is expressive, but autoregressive decoding stores and reloads key/value cache tensors for every layer and generated token. The paper asks:

The route is:

Main Claim

Grouped-query attention divides query heads into groups. Query heads inside a group share one key head and one value head.

The main architecture claim is:

The paper also proposes uptraining: convert a multi-head checkpoint into an MQA/GQA checkpoint, then continue pretraining for a small fraction of the original compute.

Architecture Contract

ItemContract
Inputdecoder hidden states
Outputsame attention output shape as MHA
Query headsmany,
Key/value headsfewer,
Sharing ruleseveral query heads share one key/value head
Main benefitsmaller KV cache and lower memory bandwidth during decoding
Main riskquality loss if too few KV heads
Related variantsMHA, MQA, GQA

In a decoder-only model, cached keys and values dominate attention memory during long generation:

where:

  • is number of layers;
  • is cached sequence length;
  • is number of key/value heads;
  • is head dimension.

Reducing directly reduces KV cache size and memory bandwidth.

MHA, MQA, GQA

Let be the number of query heads and be the number of key/value heads.

Attention typeQuery headsKey/value headsReading
MHAeach query head has its own key/value head
MQAall query heads share one key/value head
GQAgroups of query heads share key/value heads

MHA:

MQA:

GQA:

For query head , define its group:

Then:

The output concatenation contract stays the same:

Why Decoding Is Different From Training

During full-sequence training, attention can be computed in parallel over tokens. During autoregressive generation, tokens are produced one at a time:

At each step, the model reuses cached keys and values from earlier tokens:

The bottleneck is often not only floating-point compute. It is reading the KV cache from memory:

MQA and GQA target the KV cache term. This is why they are architecture changes with systems consequences.

Uptraining

The GQA paper also gives a checkpoint conversion recipe. Starting from an MHA checkpoint, key/value projections can be pooled or grouped, then the model is further trained:

The stated motivation is practical:

This matters because training a new large model only to change head sharing can be expensive.

Relation to Multi-Query Attention

The precursor paper, “Fast Transformer Decoding: One Write-Head is All You Need,” introduced multi-query attention:

MQA gives the strongest KV-cache reduction, but can hurt quality. GQA is the intermediate point:

This makes GQA a more flexible design axis:

Evidence to Read

ClaimEvidence TypeWhat It SupportsCaveat
MQA speeds decodingMQA precursor experimentssharing KV heads reduces memory bandwidthquality can degrade
GQA preserves more qualityGQA comparisons against MHA/MQAintermediate KV sharing is a useful tradeoffresults depend on model size and uptraining recipe
uptraining is feasiblecheckpoint conversion plus extra pretrainingexisting checkpoints can be adaptedstill requires nontrivial compute and original recipe access
KV cache is a decoding bottleneckperformance analysisattention architecture affects serving costhardware and implementation details matter

The important reading is not just “GQA is faster.” It is:

Relation to Other Architecture Notes

PaperSimilarityDifference
Attention Is All You Needdefines multi-head attentionGQA changes key/value head sharing
FlashAttentionimproves attention efficiencyFlashAttention changes kernel scheduling; GQA changes attention head topology
LLaMAlater LLaMA-family models often care about GQA/MQA choicesLLaMA is a full model recipe, not a head-sharing paper
Transformer-XLimproves long-context useTransformer-XL adds segment recurrence; GQA reduces KV cache cost
RoFormermodifies attention internalsRoPE changes position handling; GQA changes KV sharing

Implementation Reading

In model config, watch for names like:

Config FieldMeaning
num_attention_headsnumber of query heads
num_key_value_headsnumber of key/value heads
n_headoften query heads
n_kv_headoften key/value heads
head_dimper-head feature dimension

If:

then each key/value head serves:

query heads.

The implementation must repeat or broadcast key/value heads to query-head groups before attention score computation. Bugs often come from confusing:

  • query-head count;
  • key/value-head count;
  • tensor layout order;
  • cache layout;
  • grouped broadcast semantics.

Limitations

  • GQA is not a new reasoning mechanism; it is a head-sharing and serving-efficiency design.
  • If is too small, quality may degrade.
  • Uptraining assumes access to the checkpoint and enough data/compute to adapt.
  • Speedup depends on KV cache layout, batch size, sequence length, hardware, and kernel implementation.
  • Comparisons must separate architecture effect from model size, data, tokenizer, and serving stack.

Common Misreadings

MisreadingBetter Reading
GQA changes the attention formula completelyit keeps dot-product attention but shares K/V heads
GQA is the same as FlashAttentionGQA changes tensors; FlashAttention changes computation schedule
MQA/GQA only matter for inference engineersthe architecture determines KV cache shape and deployability
fewer KV heads always means betterit trades memory bandwidth against representation capacity
uptraining is freeit is cheaper than full pretraining, but still a training procedure

What to Remember

The core axis is:

With:

The reason it matters: