Skip to main content
issue 2026-08-05Inference40 minEMNLP 2023interactive

GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints

This research paper explains how sharing one key/value head per group of query heads, plus a cheap mean-pool uptraining recipe, turns existing multi-head checkpoints into fast decode models.

Grouped-query attention shares key-value heads inside query groupsA central grouped-query block shows two shared key-value cubes feeding four query heads in two groups. A multi-head reference keeps a private KV per query, and a multi-query reference collapses every query onto one KV, locating GQA between quality and decode bandwidth.MHAQ1Q2KV1KV2PRIVATE KVGQAENTER GROUP · SHARE KV · LOAD LESSQGROUP AQGROUP AQGROUP BQGROUP BSHARED KVFOR GROUP ASHARED KVFOR GROUP BMQAQ*Q*ONE KVALL QUERIESSINGLE KVQUERY HEADS STAY WIDE · KEY/VALUE HEADS COLLAPSE BY GROUPGQA INTERPOLATES MHA QUALITY AND MQA DECODE BANDWIDTHGROUP A SHARES KV A · GROUP B SHARES KV BGrouped-query attention shares KV heads per query groupMobile layout: multi-head keeps a private KV per query, grouped-query shares one KV inside each query group, and multi-query collapses every query onto one KV.ENTER GROUP · SHARE KV · LOAD LESSMHA · PRIVATE KVeach query keeps its own K/VGQA · SHARE IN GROUPSgroup A queries → shared KV Agroup B queries → shared KV BH queries · G key/value headsMQA · SINGLE KVevery query reads the same K/VQUALITY NEAR MHA · SPEED NEAR MQA

Autoregressive decoding is often limited less by FLOPs than by memory bandwidth: every new token reloads model weights and the growing key/value (KV) cache. Multi-query attention (MQA) attacks that cost by keeping many query heads but only one key head and one value head. The catch is quality — and the practical annoyance that you may already own a strong multi-head (MHA) checkpoint you do not want to retrain from scratch.

This paper’s move is twofold. First, a cheap uptraining recipe converts an MHA checkpoint into MQA (or GQA) with about 5% of original pre-training compute. Second, grouped-query attention (GQA) interpolates the two extremes: query heads are partitioned into GG groups, and each group shares a single key head and value head. GQA-1 is MQA; GQA-H (groups equal to heads) is MHA.

What this paper explains

Decoder inference repeatedly reads keys and values for every past token. With multi-head attention you store and load HH key heads and HH value heads. MQA collapses that to one of each, cutting KV traffic by roughly a factor of HH — which is why Shazeer’s multi-query work (2019) and systems like PaLM leaned on it.

Ainslie et al. ask two engineering questions that matter if you ship models:

  1. Can we retrofit existing MHA checkpoints instead of training a separate fast model?
  2. Is there a better point on the tradeoff curve than “all heads” vs “one KV head”?

GQA is the architectural answer to (2). Mean-pooling KV projections and continuing pre-training for a small fraction α\alpha of original steps is the recipe for (1).

Quality versus decode bandwidth spectrumMulti-head attention on the left keeps private KV heads. Multi-query attention on the right uses one KV head. Grouped-query attention sits in the middle.MHAGQAMQAquality ↑KV traffic ↓
Going from MHA to MQA reduces KV heads by H. GQA keeps a proportional number of KV heads so memory-bandwidth savings stay large without collapsing to a single KV pathway.

Prior limits

  • MHA preserves capacity per head but makes the KV cache large; long-context decode pays for it on every step.
  • MQA shrinks the cache aggressively, but the paper notes quality degradation and training instability risks, and many public models (T5, early LLaMA) were released as MHA.
  • Training a second full model only for faster inference is expensive. Checkpoint surgery without adaptation also fails: the paper finds mean-pooling KV heads beats keeping a single head or random re-init, but still needs follow-on pre-training.

The mechanism

Grouped-query attention. Split HH query heads into GG groups. Inside a group, every query head attends using the same key head and value head for that group. Attention math stays familiar; only the KV multiplicity changes.

  • G=1G = 1 → MQA (one shared KV for all queries)
  • 1<G<H1 < G < H → GQA (the useful middle)
  • G=HG = H → MHA (each query keeps its own KV)

Going from MHA to MQA reduces KV heads by HH. Larger models often scale HH up, so that cut becomes brutal. GQA keeps a proportional number of KV heads so memory-bandwidth savings stay large while representation capacity does not collapse to a single KV pathway.

Interactive

How many query groups?

Split 8 query heads into G groups. Each group shares one key head and one value head. Slide G to move between multi-query and multi-head.

GQA-2: 4 query heads share each KV head — the useful middle of the tradeoff.

Uptraining. To convert an MHA checkpoint:

  1. Mean-pool the key (and value) projection matrices within each intended group into one projection per group.
  2. Continue the original pre-training recipe for α\alpha of the original step budget (main experiments use α=0.05\alpha = 0.05).
  3. Apply MQA/GQA to decoder self-attention and cross-attention (encoder self-attention stays multi-head in their T5 setup).
Uptraining converts an MHA checkpoint into GQAFour stages: multi-head checkpoint, mean-pool KV projections within groups, continue pre-training for about five percent of original steps, then a GQA or MQA model.MHA CKPTH KV headsMEAN-POOLKV per groupUPTRAINα ≈ 5% stepsGQA / MQAshared KV
Mean-pool the key/value projections inside each intended group, then continue the original pre-training recipe for a small fraction α of the original step budget (main experiments use α = 0.05).

Algorithm walkthrough

  1. Choose group count GG (paper highlights GQA-8 for large T5).
  2. Partition the HH query heads into GG contiguous groups of size H/GH/G (assume HH divisible by GG).
  3. For each group, replace the group’s key projections with their mean (same for values).
  4. Run a short continued pre-training phase with the new attention layout.
  5. At decode time, load only GG key heads and GG value heads instead of HH.

The opening figure places GQA between an MHA tower (private KV per query) and an MQA tower (one KV for everyone). The slider above lets you feel the same continuum by changing GG.

What to notice when reading

  • Where the paper draws the line between architecture (GQA) and adaptation (uptraining) — they solve different halves of the retrofit problem.
  • How aggressively MQA collapses capacity as HH grows, and why a middle GG restores most quality in their tables.
  • That encoder self-attention stays multi-head in their T5 recipe; the savings target decoder paths that dominate autoregressive cost.

Results and evidence

From the paper’s T5-XXL comparisons (their Table 1 / timing setup — treat as the authors’ reported numbers, not timeless absolutes):

VariantTime (s/sample)Avg qualityNote
MHA-XXL1.51~47.2Full private KV
GQA-8-XXL0.2847.1Near MHA quality, near MQA speed
MQA-XXL~0.24lowerFastest; quality gap vs MHA

Average aggregates their summarization (CNN/DailyMail, arXiv, PubMed, MediaSum, MultiNews; ROUGE-1), WMT En→De (BLEU), and TriviaQA (F1) dev results. Ablations show GQA needing less uptraining than MQA to recover after conversion, with diminishing returns past roughly 10% uptraining proportion.

Limitations

Stated by the authors, compressed:

  • Rouge (and similar automatic metrics) are imperfect proxies for long-form generation quality — exactly where KV bandwidth matters most.
  • They did not compare XXL GQA uptraining against an equally large GQA model trained from scratch.
  • Experiments are on encoder–decoder T5; decoder-only models may change the MQA vs GQA gap (the authors expect GQA’s relative advantage over MQA to be stronger there because there is no separate cross-attention).
  • The paper targets KV memory-bandwidth, not the full modern serving stack (paging, continuous batching, speculation).

How to read the paper

  1. Abstract + §1 — why KV bandwidth dominates decode.
  2. §2.1–2.2 — uptraining conversion and the GQA definition (Figures 1–2).
  3. §3.1–3.2 — T5 setup, Table 1, Figure 3 tradeoff plot.
  4. §3.3 ablations — uptraining proportion, group count, init choices.
  5. Limitations + conclusion — what they did not claim.

Knowledge check

In GQA notation, what do GQA-1 and GQA-H correspond to?

Why does shrinking the number of KV heads speed up autoregressive decode even if query heads stay large?

What two-step recipe turns an existing MHA checkpoint into MQA/GQA without a full retrain?

Keep reading

  1. Original paper (arXiv:2305.13245) — abstract, Figures 1–3, Table 1.
  2. Shazeer, Fast Transformer Decoding (MQA) — arXiv:1911.02150.
  3. Related Fanout Daily: FlashAttention, PagedAttention, KV cache management, Orca continuous batching.

Sources

  • Ainslie et al., GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints, EMNLP 2023 — arXiv:2305.13245
  • Shazeer, Fast Transformer Decoding: One Write-Head is All You Need (MQA), 2019 — arXiv:1911.02150

Practice this paper

All challenges