Robots Atlas>ROBOTS ATLAS
Architecture

GQA

2023ActiveUpdated: 28 September 2026Published
Key innovation
Resolves the trade-off between Multi-Head Attention (quality) and Multi-Query Attention (inference speed) by grouping Q heads to share K and V within each group, reducing KV-cache memory without significant quality loss.
Category
Architecture
Abstraction level
Building block
Operation level
LayerArchitecture block
Use cases
Efficient inference of large language modelsGPU/TPU memory reductionLong-context modelsLLaMA 2/3, Mistral, Gemma — standard architecture componentDeployment on memory-constrained hardware

How it works

Instead of one KV pair per head (MHA) or one for the whole model (MQA), GQA groups query heads — each group shares one KV pair. E.g., 8 heads in 2 groups of 4 → only 2 KV pairs instead of 8.

Problem solved

Multi-Head Attention requires a separate key-value pair per head, which is memory-intensive. GQA reduces KV cache memory usage by grouping query heads.

Components

Query headsProduce H separate query representations, later partitioned into G groups.

H independent query projections, as in Multi-Head Attention.

Grouped Key/Value headsReduce KV cache size from scaling with H to scaling with G.

G key-value pairs (1 < G < H); each pair is shared by all query heads in its group.

KV head grouping (mean-pool conversion)Enables converting existing MHA models to GQA without training from scratch.

Uptraining procedure: the K/V heads of the original MHA checkpoint are mean-pooled within each group, then the model is further trained for about 5% of the pre-training budget.

Official

Implementation

Implementation pitfalls
Choosing group count G requires experimentationMedium

G=1 is MQA (maximum savings, quality loss), G=H is MHA (no savings). Optimal G depends on task and model size — no universal rule exists.

Incompatibility with MHA checkpoints during fine-tuningHigh

Models pre-trained with MHA cannot be directly fine-tuned as GQA without converting KV head weights (e.g. by averaging or pruning). Requires a dedicated conversion step.

Evolution

Original paper · 2023 · EMNLP 2023 · Joshua Ainslie
GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints
Joshua Ainslie, James Lee-Thorp, Michiel de Jong, Yury Zemlyanskiy, Federico Lebrón, Sumit Sanghai
2019
Multi-Query Attention (MQA) — direct precursor

Noam Shazeer introduces MQA: a single K/V pair for all heads, speeding up decoding at the cost of quality.

2023
GQA published (Ainslie et al., EMNLP 2023)
Inflection point

GQA introduced as a generalization of MQA, together with a recipe for uptraining MHA checkpoints at ~5% of pre-training compute.

2023
Adoption in Llama 2 (70B) and Mistral 7B

GQA enters production open-weight LLMs, including Llama 2 70B and Mistral 7B.

2024
Standard in Llama 3, Gemma, DBRX, Qwen

GQA becomes the default attention mechanism across most new LLM families.

Hyperparameters (configurable axes)

Number of K/V heads / groups (G)Critical

Number of K/V pairs. G = num_attention_heads → MHA; G = 1 → MQA; 1 < G < H → GQA. The main knob controlling the quality/memory trade-off.

8Llama 2 70B, Llama 3
1extreme case = MQA
Number of query heads (H)High

Number of query heads; must be divisible by the number of K/V groups.

Head dimensionMedium

Dimension of a single attention head (d_head), typically hidden_size / num_attention_heads.

Computational complexity

Time complexity: O(n² · d). Space complexity: O(n · d_head · G).

Compute bottleneck

KV cache memory bandwidth during decoding

Autoregressive decoding is memory-bound: the dominant cost is repeatedly loading the KV cache from memory. GQA shrinks the KV cache, reducing this memory traffic.

Execution paradigm

Primary mode
Dense

GQA is a dense attention mechanism — all heads are active for every token; there is no routing (unlike Mixture of Experts).

Activation pattern
All paths active
Routing mechanism

Parallelism

Parallelism level
Fully parallel

Attention computation remains parallel across heads and positions; sharing K/V introduces no sequentiality. Autoregressive decoding is sequential across tokens — as in any decoder — independently of GQA.

Scope
TrainingInference

Hardware requirements

Primary

GQA reduces KV cache size — particularly valuable on GPUs with limited VRAM for long contexts (128k+ tokens). Natively supported by FlashAttention-2 and vLLM, among others.

Good fit

GQA was developed at Google with efficient inference in mind; the KV memory and bandwidth reduction is beneficial on TPU as well.