Grouped-Query Attention (GQA) is an attention mechanism that divides query heads into a smaller number of groups, where each group shares a single Key and Value head while maintaining separate Query projections. This architecture directly addresses the memory bandwidth bottleneck of the Key-Value (KV) cache during autoregressive decoding by reducing the number of stored KV heads, achieving inference speeds close to Multi-Query Attention (MQA) while preserving model quality comparable to standard Multi-Head Attention (MHA).
Glossary
Grouped-Query Attention (GQA)

What is Grouped-Query Attention (GQA)?
Grouped-Query Attention (GQA) is an interpolation between multi-head and multi-query attention that partitions query heads into groups, with each group sharing a single set of key and value heads, balancing inference speed and model quality.
GQA generalizes the trade-off between MHA and MQA by introducing a configurable number of KV head groups. When the number of groups equals the number of query heads, GQA is equivalent to MHA; when there is a single group, it reduces to MQA. Intermediate group counts, such as 8 query heads sharing 4 KV heads, provide a practical sweet spot that significantly decreases KV cache memory requirements without the severe representational capacity loss observed in pure MQA, making it a critical optimization for deploying large language models like Llama 2.
Key Features of GQA
Grouped-Query Attention (GQA) interpolates between Multi-Head and Multi-Query Attention by partitioning query heads into groups that share a single key-value head, optimizing the trade-off between inference speed and model quality.
The Interpolation Spectrum
GQA sits precisely between Multi-Head Attention (MHA) and Multi-Query Attention (MQA) on the speed-quality curve.
- MHA (G = H): Each query head has its own unique key-value head. Highest quality, largest KV cache.
- MQA (G = 1): All query heads share a single key-value head. Fastest inference, potential quality degradation.
- GQA (1 < G < H): Query heads are partitioned into G groups. Each group shares one key-value head.
This provides a tunable knob to balance memory bandwidth and representational capacity.
KV Cache Reduction
The primary engineering motivation for GQA is reducing the size of the Key-Value (KV) Cache during autoregressive decoding.
- The KV cache size scales with the number of distinct key-value heads.
- For a model with H query heads and G groups, the cache is reduced by a factor of H/G compared to standard MHA.
- This directly reduces the memory bandwidth bottleneck that plagues large-batch inference, allowing for higher throughput and lower latency on memory-constrained hardware.
Uptraining from MHA Checkpoints
GQA models can be efficiently bootstrapped from existing Multi-Head Attention checkpoints through a process called uptraining.
- Mean Pooling: The key and value projection matrices for a group are initialized by mean-pooling the weight matrices of the original heads assigned to that group.
- Continued Pre-training: The converted model is trained for a small fraction (typically <10%) of the original pre-training steps.
- This allows practitioners to convert a high-quality MHA model to GQA without training from scratch, drastically reducing compute cost.
Adoption in Frontier Models
GQA has become the standard attention mechanism for large-scale production models due to its favorable inference characteristics.
- Meta Llama 2 70B: Used GQA with 8 key-value heads for 64 query heads.
- Google PaLM 2: Employed multi-query attention, the extreme endpoint of the GQA spectrum.
- Mistral 7B: Adopted GQA alongside Sliding Window Attention for efficient long-context processing.
- The technique is now a default architectural choice for models targeting deployment at scale.
Quality Retention
Empirical evaluations demonstrate that GQA maintains model quality remarkably close to MHA while approaching the speed of MQA.
- On benchmarks like MMLU and HellaSwag, GQA models with a moderate number of groups (e.g., G=8) show negligible perplexity degradation compared to MHA baselines.
- The quality gap between MHA and MQA widens on tasks requiring fine-grained attention to multiple distinct contexts.
- GQA effectively closes this gap, recovering most of the lost representational power while retaining the memory savings.
Batch Inference Optimization
GQA's benefits are most pronounced during high-throughput, batched inference rather than single-stream generation.
- In single-sequence decoding, the compute is dominated by matrix multiplications, and KV cache size is less critical.
- In large-batch serving (e.g., 256+ concurrent requests), memory bandwidth for reading the KV cache becomes the primary bottleneck.
- GQA reduces the total bytes read from memory per decoding step, directly translating to higher throughput and lower cost-per-token in production serving environments.
MHA vs. MQA vs. GQA
Structural comparison of Multi-Head, Multi-Query, and Grouped-Query Attention mechanisms, highlighting the trade-offs between model quality, inference speed, and memory bandwidth.
| Feature | Multi-Head Attention (MHA) | Multi-Query Attention (MQA) | Grouped-Query Attention (GQA) |
|---|---|---|---|
Key-Value Head Count | Equal to Query head count (H) | 1 (shared across all Query heads) | G (1 < G < H) |
Query Head Count | H | H | H |
KV Cache Size | 2 × H × d_k × L | 2 × 1 × d_k × L | 2 × G × d_k × L |
Memory Bandwidth Load | High | Low | Medium |
Inference Throughput | Baseline | Highest | High |
Model Quality | Highest | Degraded | Near-MHA quality |
Training Throughput | Baseline | Slightly faster | Comparable to MHA |
Upscaling from MQA Checkpoint |
Frequently Asked Questions
Clear, technical answers to the most common questions about Grouped-Query Attention (GQA), an interpolation between Multi-Head and Multi-Query Attention that balances inference speed and model quality.
Grouped-Query Attention (GQA) is an attention mechanism that partitions the Query heads into groups, with each group sharing a single set of Key and Value projection weights. It works by dividing the total number of Query heads (H) into G groups, where each group contains H/G Query heads. All Query heads within a single group attend to the same Key and Value vectors, while different groups use distinct Key and Value projections. This design interpolates between Multi-Head Attention (MHA), where every Query head has its own unique Key and Value heads (G = H), and Multi-Query Attention (MQA), where all Query heads share a single Key and Value head (G = 1). By choosing an intermediate number of groups, GQA achieves a balance: it significantly reduces the size of the KV cache compared to MHA, cutting memory bandwidth requirements during inference, while retaining more representational capacity than MQA, which can suffer from quality degradation. The shared Key and Value heads are computed once per group, and the attention output for each Query head within the group is computed using the standard scaled dot-product attention formula against the shared K and V.
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
Grouped-Query Attention (GQA) sits at the intersection of several critical Transformer optimization techniques. These related concepts define the trade-offs between inference speed, memory bandwidth, and model quality.
Multi-Head Attention (MHA)
The foundational mechanism where each attention head has its own distinct Query, Key, and Value projection weights. MHA provides maximum representational capacity by allowing heads to attend to different representation subspaces simultaneously. However, this design results in a KV cache size that scales linearly with the number of heads, creating a significant memory bandwidth bottleneck during autoregressive decoding. GQA directly addresses this overhead by sharing Key and Value heads across Query groups.
Multi-Query Attention (MQA)
An extreme optimization where all attention heads share a single set of Key and Value projection weights, while maintaining independent Query projections. MQA dramatically reduces the KV cache size and memory bandwidth requirements, leading to faster inference. The trade-off is a measurable degradation in model quality and training stability compared to MHA. GQA was developed as an interpolation between MHA and MQA to recover most of the quality loss while retaining significant speed gains.
Key-Value (KV) Cache
An inference optimization that stores previously computed Key and Value vectors for all generated tokens to avoid redundant recomputation during autoregressive decoding. The memory footprint of the KV cache grows with:
- Batch size × Sequence length × Number of KV heads × Head dimension GQA reduces the number of KV heads, directly shrinking the cache size and alleviating the memory bandwidth bottleneck that often dominates inference latency in large language models.
FlashAttention
An IO-aware exact attention algorithm that computes attention in tiles using GPU SRAM instead of repeatedly reading and writing the full attention matrix to HBM. FlashAttention is orthogonal to GQA—both can be combined for compounding speedups. GQA reduces the total data that must be moved, while FlashAttention optimizes how that data movement occurs. Together, they represent the state-of-the-art in efficient Transformer inference.
Attention Head Pruning
A post-training compression technique that identifies and removes redundant or low-importance attention heads to reduce computational cost. Unlike GQA, which modifies the architecture before or during training by grouping Query heads to share KV projections, pruning operates on a fully trained MHA model. GQA is a structural design choice that bakes efficiency into the architecture from the start, avoiding the potential quality loss associated with ablating heads after training.
Quadratic Complexity Bottleneck
The inherent limitation of standard self-attention where both memory and time complexity scale as O(n²) with sequence length. GQA does not address this quadratic scaling—it targets the KV cache memory bandwidth bottleneck during inference, not the computational complexity of the attention score matrix itself. For long-context efficiency, GQA is often paired with techniques like Sparse Attention or Sliding Window Attention to tackle both the memory bandwidth and quadratic compute challenges simultaneously.

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