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-8drops 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 forMHA-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.
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:
- Aggressive capacity loss: larger models scale up their head count
H, so reducingHall the way to 1 cuts representational capacity much harder on a 64-head XXL model than on a smaller base model. - 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.
- Tensor-parallel replication waste: when a large model is sharded across
Paccelerator partitions, a single K/V head cannot be split further and must be replicatedPtimes across every partition. KeepingG >= Pgroups (such asG = 8on 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.
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.
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 boundKeeping 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.
Multi-query attention (MQA-XXL and from-scratch)
Capacity and stabilityCollapsing all query heads onto 1 K/V head cuts T5-XXL decode time to 0.24s, yet introduces quality drops, loss spikes, and sharding waste.
- Where quality slips
- 5% uptrained MQA-XXL drops from 47.2 to 46.6 average (CNN 43.0 vs 43.8, arXiv 45.0 vs 45.6, PubMed 46.9 vs 47.5, TriviaQA 81.3 vs 81.9).
- Long-input divergence
- Appendix A reports that from-scratch T5-Large MQA suffered frequent pretraining loss spikes and diverged immediately on long-input fine-tuning.
- Sharding overhead
- When sharded across P model-parallel chips, a single K/V head must be replicated P times, discarding potential memory savings below P heads.
- Uptrained takeaway
- Despite its flaws, 5% uptrained MQA-XXL still beats MHA-Large in both latency (0.24s vs 0.37s) and quality (46.6 vs 46.0).
Grouped-query attention (GQA-8-XXL)
Sweet spotEight K/V groups recover nearly full MHA accuracy while keeping MQA-class decoding speed and clean 8-way hardware partitioning.
- Speed vs quality
- At 0.28s per sample (5.4x faster than MHA-XXL, only +0.04s above MQA-XXL), GQA-8-XXL reaches 47.1 average across all seven benchmarks.
- Long-document wins
- GQA-8-XXL matches or slightly beats MHA-XXL on PubMed (47.7 vs 47.5) and MultiNews (47.2 vs 46.9), while hitting 81.6 on TriviaQA.
- Group count scaling
- Figure 6 (2048 in / 512 out) shows G = 1 to 8 adds minimal latency overhead, whereas 16, 32, and 64 groups push sample time steeply upward.
- Why 8 groups fit
- Eight K/V heads eliminate tensor-parallel replication on 8-way sharded pods and remain stable across fine-tuning without multi-run variance.
Checkpoint initialization and uptraining schedule
Conversion ablationAveraging original K/V projection matrices edges out copying a head or random initialization, and 5% continued pretraining saturates most gains.
- Why random init lags
- Randomly initializing new K/V matrices resets pre-trained key-value alignment with existing query heads, scoring lowest in Fig 4 (~55.22, a modest ~0.32 points behind mean pooling after 5% MQA uptraining).
- Mean vs First head
- Mean-pooling original group heads preserves signal from every head (~55.5 on T5-Large 3-task eval), slightly ahead of copying only the first head (~55.45).
- Zero-shot after merge
- In Figure 5, GQA-8 already retains usable quality at alpha = 0 right after mean pooling, while MQA needs uptraining before it works well.
- Compute budget
- Uptraining for alpha = 0.05 (5% of original steps) captures most gains at ~600 TPUv3 chip-days on XXL, with diminishing returns at alpha = 0.10.
How GQA composes with modern decoders and kernels
Serving stackAlthough tested only on T5 encoder-decoder models, GQA maps directly onto decoder-only LLMs and orthogonal inference optimizations.
- Decoder-only prediction
- Paper Section 5 predicted GQA's advantage over MQA would be stronger in decoder-only models lacking separate encoder cross-attention.
- Llama 3 validation
- Llama 3 adopted GQA with 8 KV heads from scratch across 8B (32Q), 70B (64Q), and 405B (128Q) models, scaling KV capacity independently.
- Orthogonal kernels
- GQA reduces physical KV bytes stored per token, stacking directly with PagedAttention block allocation and FlashAttention-2 tiling.
- Next-step compression
- Architectures like DeepSeek-V2 push KV reduction further via low-rank Multi-Head Latent Attention when 8 KV heads remain too large.
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.


