Grouped-Query Attention (GQA) cuts autoregressive decoding time by more than 5x while keeping quality within 0.1 points of full multi-head attention, using only 5% of original pretraining compute to convert existing checkpoints. Joshua Ainslie, James Lee-Thorp, Michiel de Jong, Yury Zemlyanskiy, Federico Lebrón, and Sumit Sanghai at Google Research introduced GQA as a middle ground between Multi-Head Attention (MHA) and Multi-Query Attention (MQA): query heads are partitioned into G groups, and every query head in a group shares a single key and value head.

Autoregressive decoding is bottlenecked not by matrix-multiply FLOPs, but by memory bandwidth: loading model weights and every prior token’s cached keys and values from HBM at every generated token. Standard MHA duplicates those keys and values across every head, while MQA collapses them all to a single head that hurts quality, diverges on long-context training, and gets replicated across tensor-parallel GPUs anyway. GQA solves both sides of that tradeoff and has since become the default attention layout in modern open-weight models like Llama 3, Qwen, and Mistral.

  • 5.4x faster decoding at near-identical quality: uptrained T5-XXL GQA-8 drops inference time from 1.51s to 0.28s per sample on 8 TPUv4 chips while scoring 47.1 average across seven benchmarks versus 47.2 for MHA-XXL.
  • Two-step checkpoint uptraining: mean-pool each group’s original key and value projection matrices, then continue pretraining for alpha = 0.05 (5%) of original steps (~600 TPUv3 chip-days for T5-XXL).
  • Mean pooling edges out alternatives: on T5-Large uptrained to MQA (alpha = 0.05, 3-task subsample), mean-pooling K/V heads scores ~55.5 versus ~55.45 for copying the first head and ~55.22 for random initialization, a modest ~0.32-point margin over random init.
  • Avoids MQA’s training instability and sharding waste: MQA trained from scratch suffered frequent loss spikes and immediate divergence on long-input fine-tuning (Appendix A), whereas uptrained GQA stayed stable and aligns cleanly with multi-chip sharding.
Three attention layouts across the head-sharing spectrum
Multi-Head GQA-H
H query heads, H K/V heads (64 pairs on T5-XXL).

Highest capacity (47.2 avg), but every token step loads 64 K/V heads from memory, pushing T5-XXL decode time to 1.51s per sample.

Grouped-Query GQA-8
H query heads split into 8 groups, 8 K/V heads.

Cuts KV traffic 8x on a 64-head model, matches 8-way tensor parallelism with zero replication waste, and hits 47.1 avg in 0.28s.

Multi-Query GQA-1
H query heads sharing 1 single K/V head.

Fastest decode (0.24s), but drops score to 46.6, diverges in long-input from-scratch runs, and replicates that 1 head across tensor shards.

Architecture comparison and T5-XXL metrics from Ainslie et al. (2023), Section 2.2 and Table 1.

Why KV-cache bandwidth bottlenecks decoding

In standard Transformer multi-head attention, each of the H query heads maintains its own key and value projection matrices. During prompt prefill, the model processes all input tokens in parallel, so arithmetic intensity is high and compute cores stay busy. During autoregressive decoding, however, the model generates one token at a time and must load all decoder weights plus the entire history of cached keys and values for every layer on every step.

Consider a concrete decoder with 32 query heads, head dimension 128, 32 layers, and 2-byte bfloat16 elements. Storing 32 key and value heads per token requires 512 KiB per token across the model, or 4 GiB for a single 8,192-token sequence before accounting for allocator overhead. With GQA-8 (8 KV heads instead of 32), that per-token cache drops fourfold to 128 KiB, or 1 GiB for 8,192 tokens. Smaller caches both speed up memory-bound decoding and let serving engines fit more concurrent sequences on the same GPU.

The naive existing fix was Multi-Query Attention (MQA), which collapses all H key and value heads into a single shared K/V pair. MQA shrinks the cache dramatically, yet Ainslie et al. identify three structural flaws when scaling it up:

  1. Aggressive capacity loss: larger models scale up their head count H, so reducing H all the way to 1 cuts representational capacity much harder on a 64-head XXL model than on a smaller base model.
  2. Training instability: in Appendix A, multiple T5-Large MQA models trained from scratch suffered frequent loss spikes during pretraining and diverged immediately when fine-tuned on long-input tasks. Even uptrained MQA exhibited high variance across fine-tuning runs.
  3. Tensor-parallel replication waste: when a large model is sharded across P accelerator partitions, a single K/V head cannot be split further and must be replicated P times across every partition. Keeping G >= P groups (such as G = 8 on 8-way sharded hardware) gives every chip its own distinct K/V heads with zero wasted memory traffic.

Notice also where GQA is not applied: the authors convert decoder self-attention and cross-attention, leaving encoder self-attention untouched because encoder tokens are processed in parallel rather than step-by-step.

Uptraining existing checkpoints in two steps

Instead of spending 100% of a pretraining budget to train a fast model from scratch, Ainslie et al. adapt sparse upcycling ideas (Komatsuzaki et al., 2022) to attention heads and show that public MHA checkpoints (like T5.1.1) can be converted with a 5% compute tail.

First, partition the H query heads into G contiguous groups of H / G heads each. Construct each group’s single key projection matrix and value projection matrix by mean pooling (averaging) the original H / G projection matrices inside that group, while keeping all H query projections separate. Two query heads in the same group still compute different attention maps because their queries differ; they simply attend over a shared K/V subspace.

Second, continue pretraining the converted model for a fraction alpha of its original pretraining steps using the exact same pretraining dataset, Adafactor optimizer, and learning-rate schedule. For T5-XXL, alpha = 0.05 took roughly 600 TPUv3 chip-days. Crucially, Figure 5 shows that GQA-8 already achieves strong quality at alpha = 0 immediately after mean-pooling conversion, whereas MQA starts broken and requires uptraining just to become usable. Both converge quickly by alpha = 0.05 with diminishing returns at alpha = 0.10.

T5 decoding latency versus 7-task quality (Table 1)
Inference time per sample in seconds (lower is faster)Avg score across 7 tasks (higher is better)
MHA-XXL
1.51s · 47.2
MHA-Large
0.37s · 46.0
GQA-8-XXL
0.28s · 47.1
MQA-XXL
0.24s · 46.6

Timed on 8 TPUv4 chips with xprof (max batch size up to 32/TPU); 5% uptrained XXL checkpoints. Source: Ainslie et al. (2023), Table 1.

Benchmark tradeoffs and ablation cases

Ainslie et al. evaluate on seven generative benchmarks where autoregressive decoding matters: five summarization suites (CNN/DailyMail, arXiv, PubMed, MediaSum, MultiNews), WMT 2014 English-to-German translation, and TriviaQA reading comprehension, using greedy decoding and omitting non-autoregressive classification suites like GLUE.

Even uptrained MQA-XXL beats MHA-Large on both speed (0.24s vs 0.37s) and quality (46.6 vs 46.0), proving that scaling up parameters and uptraining KV heads beats keeping a smaller MHA model. Switching to GQA-8-XXL recovers almost the entire gap to MHA-XXL (47.1 vs 47.2), even edging ahead on PubMed (47.7 vs 47.5) and MultiNews (47.2 vs 46.9), at just 0.04s slower per sample than MQA.

Explore the five experimental dimensions below to compare the head-sharing regimes, conversion methods, uptraining schedules, group-count scaling, and stability checks.

Five design choices and ablations in the GQA study

Select a tab (or use Left and Right arrow keys) to inspect what breaks, what the paper changes, and the measured numbers.

Multi-head attention (MHA-Large and MHA-XXL)

Memory bound

Keeping one key and value head per query head delivers top accuracy (47.2 avg) but leaves decoding severely memory-bandwidth bound.

Why inference stalls
On T5-XXL, each decoding step loads 64 K and 64 V heads across the sequence history, pushing inference to 1.51s per sample on 8 TPUv4s.
Benchmark scores
MHA-XXL hits 43.8 CNN, 45.6 arXiv, 47.5 PubMed, 36.4 MediaSum, 46.9 MultiNews, 28.4 WMT BLEU, and 81.9 TriviaQA F1 (47.2 average).
Smaller MHA comparison
MHA-Large runs faster at 0.37s per sample, but quality drops sharply to 46.0 average (including 78.2 on TriviaQA).
Serving implication
Even before hitting FLOP limits, large KV caches cap concurrent batch sizes and force expensive multi-chip serving footprints.

Source: Ainslie et al. (2023), Section 3 and Appendix A.

If you prefer the concise summary without clicking through each tab, here are the five core findings from the paper:

  • MHA baseline: full multi-head attention reaches 47.2 average score on T5-XXL but takes 1.51s per sample on 8 TPUv4s because 64 K/V heads flood memory bandwidth.
  • MQA pitfalls: shrinking to 1 K/V head cuts time to 0.24s (46.6 avg) but causes pretraining loss spikes, immediate long-input divergence from scratch, and replication across tensor shards.
  • GQA-8 sweet spot: sharing 8 K/V heads cuts latency 5.4x to 0.28s while preserving 47.1 average quality (including 47.7 on PubMed and 47.2 on MultiNews).
  • Uptraining recipe: mean-pooling grouped K/V matrices edges out first-head selection and random init, and alpha = 0.05 (5% pretraining steps) captures nearly all uptraining gains.
  • Serving synergy: GQA reduces per-token cache footprint orthogonally to kernel and allocator optimizations, making it easy to stack with modern serving runtimes.

Caveats and where attention sharing went next

Three explicit limitations from Section 5 of the paper bound what the 2023 experiments prove.

First, ROUGE is an incomplete proxy for long-output quality. Because KV-cache bandwidth matters most on long generations, five of the seven benchmarks are summarization tasks scored with ROUGE-1, which the authors acknowledge does not capture every aspect of generation quality.

Second, there is no from-scratch GQA-XXL comparison. Compute limits prevented training a fresh T5-XXL model with GQA from step zero, so the paper proves uptraining works relative to MHA-XXL and MQA-XXL, not whether uptraining matches or trails from-scratch GQA at 11B scale.

Third, all experiments ran on T5.1.1 encoder-decoder models. Decoder-only models do not have separate cross-attention layers, so the authors hypothesized GQA would matter even more there, though they left that verification to follow-up work.

Subsequent production LLMs quickly settled that open question. Meta trained Llama 3 from scratch with 8 KV heads across its 8B (32 query heads), 70B (64 query heads), and 405B (128 query heads) models, holding KV-cache bytes flat even as query heads quadrupled. At inference time, GQA stacks cleanly with PagedAttention (shrinking each physical cache block by 4x to 16x) and FlashAttention-2 (accelerating attention kernels without changing stored cache size). When even 8 KV heads consume too much memory at extreme context lengths, newer designs such as DeepSeek-V2 Multi-Head Latent Attention replace separate group heads with a single compressed low-rank KV latent vector.

For engineers configuring or serving models today, the paper’s practical rule holds: treat G (the number of KV groups) as a hardware-aligned knob rather than defaulting to H or 1. Set G to match your tensor-parallel shard count (commonly 8) when training or uptraining, measure time-to-first-token separately from inter-token decode latency at realistic sequence lengths, and verify long-context retrieval tasks alongside aggregate benchmarks so head sharing never silently erases capacity your workload relies on.