Grouped Query Attention (GQA) is an attention mechanism that partitions query heads into groups, with each group sharing a single key-value head. This reduces the size of the KV cache during autoregressive decoding by a factor equal to the number of query heads per group, directly lowering memory bandwidth requirements and accelerating inference while preserving more representational capacity than Multi-Query Attention (MQA).
Glossary
Grouped Query Attention (GQA)

What is Grouped Query Attention (GQA)?
Grouped Query Attention is an interpolation between Multi-Head and Multi-Query Attention that balances inference speed and model quality by sharing key-value heads across multiple query heads.
GQA addresses the memory bottleneck in large language model serving by trading off between the quality of standard Multi-Head Attention (MHA) and the speed of MQA. By using an intermediate number of key-value heads—typically 4 to 8—GQA maintains near-MHA quality on benchmarks while achieving inference throughput close to MQA, making it a standard choice in production models like Llama 2 and Mistral.
MHA vs MQA vs GQA: Attention Mechanism Comparison
Structural comparison of Multi-Head, Multi-Query, and Grouped Query Attention mechanisms regarding key-value head configuration and memory footprint during autoregressive decoding.
| Feature | Multi-Head Attention (MHA) | Multi-Query Attention (MQA) | Grouped Query Attention (GQA) |
|---|---|---|---|
Number of KV heads | Equals number of query heads (H) | 1 shared KV head | G groups (1 < G < H) |
KV cache size relative to MHA | 1x (baseline) | 1/H (maximum reduction) | G/H (interpolated reduction) |
Query head grouping | One-to-one with KV heads | All query heads share one KV head | Query heads partitioned into G groups |
Quality degradation vs MHA | None (reference) | Noticeable on large models | Negligible to minimal |
Training overhead vs MHA | None (reference) | Minimal | Minimal; often converted from MHA checkpoint |
Uptraining required | |||
Used in | Original Transformer, BERT | PaLM, Falcon | LLaMA 2, LLaMA 3, Mistral |
Key Properties of Grouped Query Attention
Grouped Query Attention (GQA) is a critical architectural innovation that balances the quality of Multi-Head Attention with the memory efficiency of Multi-Query Attention, making it essential for scaling large language model inference.
The Interpolation Spectrum
GQA occupies a precise middle ground between Multi-Head Attention (MHA) and Multi-Query Attention (MQA). In MHA, the number of key-value heads equals the number of query heads (H=K=V). In MQA, all query heads share a single key-value head (K=V=1). GQA generalizes this by dividing query heads into G groups, where each group shares one key-value head. This creates a tunable knob: setting G=1 yields MQA, while G=H yields MHA. Typical configurations use G=4 or G=8, reducing the KV cache size by a factor of H/G compared to MHA while preserving most of the quality.
KV Cache Memory Reduction
The primary motivation for GQA is reducing the memory footprint of the KV cache during autoregressive decoding. For a model with H query heads, the KV cache stores 2 tensors (keys and values) per head per token. GQA with G groups reduces this to 2G tensors per token. This yields a memory reduction factor of H/G. For a 70B parameter model with 64 heads and G=8, the KV cache shrinks by 8x. This directly translates to larger batch sizes, longer context windows, and lower per-user serving costs without requiring architectural retraining from scratch.
Uptraining from Multi-Head Checkpoints
GQA models are not trained from scratch. The standard procedure is uptraining: starting from a pre-trained MHA checkpoint and converting it to GQA. This is done by mean-pooling the key and value projection weights of the heads within each group. The model then undergoes a small fraction (typically 5-10%) of the original training steps to adapt. This uptraining is remarkably sample-efficient; the model quickly recovers quality because the underlying representations are already well-formed. This allows teams to retrofit existing large models with GQA for inference savings without the cost of full pre-training.
Quality Parity with Multi-Head Attention
Empirical evaluations demonstrate that GQA achieves near-identical performance to MHA across standard benchmarks while approaching the speed of MQA. Key findings include:
- Perplexity: GQA with G=8 matches MHA perplexity on language modeling tasks.
- Downstream tasks: Negligible degradation on MMLU, HellaSwag, and reading comprehension.
- Long-context: GQA maintains quality better than MQA on sequences exceeding 10k tokens. The slight grouping constraint acts as a mild regularizer, and the shared key-value heads learn more robust representations that generalize well across the query heads within their group.
Adoption in Production Models
GQA has become the de facto standard for large-scale production language models due to its inference efficiency. Notable implementations include:
- Llama 2 70B: Uses GQA with 8 key-value heads (G=8) across 64 query heads.
- Llama 3: Continues the GQA architecture across all model sizes.
- Mistral: Employs GQA with sliding window attention for efficient long-context processing.
- Gemma: Google's open models use GQA to balance quality and serving costs. The widespread adoption validates GQA as the optimal trade-off point for models deployed at scale.
Mechanistic Implications for Attention Circuits
From a mechanistic interpretability perspective, GQA constrains the OV circuit formation. In MHA, each head can develop a specialized copy operation. With GQA, the shared value projection forces heads within a group to read from the same source representation. This encourages complementary query specialization: heads in a group learn distinct attention patterns (QK circuits) while operating on identical value information. Analysis shows this leads to more interpretable head clusters, where a group collectively represents a concept while individual heads route information to different token positions based on context.
Frequently Asked Questions
Clear, technically precise answers to the most common questions about the GQA mechanism, its trade-offs, and its role in optimizing large language model inference.
Grouped Query Attention (GQA) is an attention mechanism that divides query heads into groups, with each group sharing a single key-value head, interpolating between Multi-Head Attention (MHA) and Multi-Query Attention (MQA) to reduce the KV cache memory footprint while preserving model quality.
In standard MHA, each of H query heads has its own dedicated key and value head, requiring 2 * H key-value tensors to be cached per token during autoregressive generation. In MQA, all query heads share a single key-value head, slashing the cache size by a factor of H but often degrading quality. GQA strikes a balance: query heads are partitioned into G groups, and each group shares one key-value head. This reduces the KV cache size by a factor of H/G compared to MHA. For example, with H=32 query heads and G=4 groups, only 8 key-value heads are stored instead of 32, achieving a 4x memory reduction while retaining most of the quality benefits of MHA. The shared key-value heads are typically derived by mean-pooling the original MHA key-value heads during uptraining from an MHA checkpoint, allowing a smooth quality-speed trade-off.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Key mechanisms and concepts that contextualize Grouped Query Attention within the broader transformer architecture and KV cache optimization landscape.
Multi-Head Attention (MHA)
The standard attention mechanism where the number of query heads equals the number of key-value heads. Each head projects into its own subspace, maximizing representational capacity but producing a large KV cache proportional to num_heads × sequence_length × head_dim. MHA is the quality ceiling that GQA and MQA approximate.
Multi-Query Attention (MQA)
An extreme optimization where all query heads share a single key-value head (num_kv_heads = 1). This dramatically reduces the KV cache size by a factor of num_heads, significantly accelerating inference. However, the aggressive sharing can cause quality degradation on tasks requiring fine-grained attention patterns.
KV Cache
A memory buffer that stores the pre-computed key and value tensors from all previous tokens during autoregressive decoding. Without it, each new token would require recomputing attention over the entire sequence. The cache size scales linearly with batch size × sequence length × num_kv_heads × head_dim, making it the primary memory bottleneck in long-context inference.
Rotary Position Embedding (RoPE)
A position encoding method that applies a rotation matrix to query and key vectors based on their absolute positions. This ensures the attention dot product depends only on the relative distance between tokens. GQA models typically use RoPE because the shared key-value heads must encode position information that generalizes across multiple query heads.
Attention Sink
A phenomenon where the first few tokens of a sequence receive disproportionately high attention scores from all heads, acting as a resting place for attention mass not allocated to semantically relevant tokens. GQA's shared key-value heads can amplify this effect, making proper attention-sink management critical for maintaining quality in streaming applications.
FlashAttention
An IO-aware exact attention algorithm that computes attention in tiled blocks using online softmax rescaling, avoiding materializing the full N×N attention matrix in GPU high-bandwidth memory. FlashAttention is complementary to GQA: GQA reduces the KV cache size, while FlashAttention optimizes the compute kernel, together enabling efficient long-context inference.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us