Grouped-Query Attention (GQA) is an interpolation between Multi-Head Attention (MHA) and Multi-Query Attention (MQA). In GQA, query heads are divided into groups, and each group shares a single key and value head. This architecture significantly shrinks the KV-Cache size, reducing the memory bottleneck during autoregressive decoding while preserving model quality closer to MHA than the more aggressive MQA approach.
Glossary
Grouped-Query Attention (GQA)

What is Grouped-Query Attention (GQA)?
Grouped-Query Attention (GQA) is an attention mechanism variant that reduces memory bandwidth requirements during inference by sharing a single key-value head across multiple query heads.
GQA is a critical inference optimization for large language models. By reducing the number of unique key and value tensors that must be stored in memory, GQA decreases the memory bandwidth required per generated token. This allows for higher batch sizes and lower latency during serving, making it a standard component in models like Llama 2 and Mistral.
GQA vs. MHA vs. MQA: Attention Mechanism Comparison
A technical comparison of Multi-Head Attention, Multi-Query Attention, and Grouped-Query Attention across memory footprint, quality retention, and inference speed metrics.
| Feature | Multi-Head Attention (MHA) | Multi-Query Attention (MQA) | Grouped-Query Attention (GQA) |
|---|---|---|---|
KV-Head Count | Equal to query heads (H) | 1 shared head | G groups (1 < G < H) |
KV-Cache Size | H × sequence_length × d_head | 1 × sequence_length × d_head | G × sequence_length × d_head |
Memory Bandwidth Load | High | Low | Medium |
Quality Retention vs. MHA | Baseline (100%) | Moderate degradation (95-98%) | Near-identical (99-100%) |
Inference Throughput | Memory-bandwidth bound | Compute-bound; highest speedup | Near-MQA speedup with MHA quality |
Training Stability | Stable | Can be unstable; requires tuning | Stable; minimal adaptation needed |
Uptraining from MHA Checkpoint | N/A (original checkpoint) | Requires full uptraining | Requires ~5% of original training budget |
Adopted By | Original Transformer; GPT-3 | PaLM; Falcon | LLaMA 2 (70B); LLaMA 3; Mistral |
Key Features of Grouped-Query Attention
Grouped-Query Attention (GQA) interpolates between Multi-Head Attention and Multi-Query Attention by sharing a single key-value head across a small group of query heads. This design preserves model quality while drastically reducing the memory footprint of the KV-Cache.
KV-Cache Memory Reduction
GQA reduces the size of the KV-Cache by a factor equal to the number of query heads per key-value head. In standard Multi-Head Attention, each query head has a dedicated key and value head, causing the cache to grow linearly with the number of heads. By sharing a single key-value pair across a group of query heads, GQA slashes the memory bandwidth required during autoregressive decoding. For a model with 32 query heads and 8 key-value groups, the KV-Cache size is reduced by 4x, directly lowering the hardware cost of serving long sequences.
Quality Interpolation Between MHA and MQA
GQA acts as a tunable trade-off between Multi-Head Attention (MHA) and Multi-Query Attention (MQA). MHA provides the highest model quality but the largest KV-Cache. MQA uses a single key-value head for all queries, minimizing memory but often degrading quality on tasks requiring fine-grained attention. GQA generalizes both: setting the number of key-value groups equal to the number of query heads recovers MHA; setting it to one recovers MQA. Intermediate group counts achieve near-MHA quality with near-MQA efficiency.
Uptraining from Existing Checkpoints
GQA models can be efficiently created from pre-trained MHA checkpoints through a process called uptraining. The original key and value head weight matrices are mean-pooled into the target number of groups, initializing a GQA model. This converted model is then fine-tuned for a small fraction (typically 5-10%) of the original training steps. This avoids the prohibitive cost of training a GQA model from scratch and preserves the knowledge already learned by the base model.
Adoption in Production LLMs
GQA has been widely adopted in state-of-the-art production models due to its favorable memory-quality trade-off:
- Llama 2 70B uses GQA with 8 key-value heads
- Llama 3 and Llama 3.1 use GQA across all model sizes
- Mistral models leverage GQA for efficient inference
- Gemma and other open-weight models incorporate GQA The technique is now a standard architectural choice for large-scale autoregressive decoders.
Impact on Inference Throughput
The primary bottleneck in LLM inference for long sequences is memory bandwidth, not compute. The KV-Cache must be read from GPU HBM for every new token generated. By shrinking the KV-Cache, GQA directly increases the number of tokens the system can generate per second. This improvement is most pronounced in batch inference scenarios where multiple sequences are processed simultaneously, as the aggregate KV-Cache size across the batch is the dominant memory consumer.
Relationship to Other Attention Optimizations
GQA is complementary to other attention efficiency techniques:
- FlashAttention: Reduces HBM reads/writes via tiling; GQA reduces the total data that must be stored
- Multi-Query Attention (MQA): The extreme case of GQA with one key-value group
- Multi-Head Latent Attention (MLA): Used in DeepSeek-V2, compresses KV-Cache into a low-rank latent vector, achieving even greater compression than GQA
- Sliding Window Attention: Limits attention to a local context; can be combined with GQA for further memory savings
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.
Frequently Asked Questions
Clear, technical answers to the most common questions about Grouped-Query Attention (GQA), its mechanisms, trade-offs, and role in optimizing large language model inference.
Grouped-Query Attention (GQA) is an attention mechanism variant that partitions query heads into groups, with each group sharing a single key-value head, rather than giving every query head its own dedicated key-value pair. In a standard Multi-Head Attention (MHA) configuration with H query heads, there are H corresponding key and value heads. GQA reduces this to G key-value heads, where G < H, and each key-value head is shared by H/G query heads within its group. During the attention computation, each query head within a group computes its attention scores against the group's shared key tensor and aggregates the shared value tensor. This design directly reduces the size of the KV-Cache by a factor of H/G, slashing memory bandwidth requirements during autoregressive decoding while preserving model quality significantly better than the extreme Multi-Query Attention (MQA) variant, which uses a single global key-value head for all queries.
Related Terms
Core architectural components and optimization techniques that define how Transformer models process and attend to information within the context window.
Multi-Head Attention (MHA)
The foundational attention mechanism in the original Transformer where each attention head has its own independent set of query, key, and value weight matrices. This allows each head to learn distinct relational patterns—one head might track syntactic dependencies while another captures long-range semantic links. The outputs of all heads are concatenated and linearly projected. While expressive, MHA's memory footprint scales linearly with the number of heads, making the KV-Cache a significant bottleneck for long-sequence inference.
Multi-Query Attention (MQA)
An extreme memory-saving variant where all query heads share a single key-value head. This eliminates the multi-head KV-Cache overhead entirely, dramatically reducing memory bandwidth requirements during autoregressive decoding.
- Trade-off: Significant reduction in model quality and training stability
- Use case: Deployments where memory is the absolute binding constraint
- Adoption: Used in PaLM and early efficient inference models before GQA emerged as a superior middle ground
KV-Cache Memory Analysis
The KV-Cache stores pre-computed key and value tensors to avoid redundant computation during autoregressive generation. Its size scales as:
- MHA:
2 × num_layers × num_heads × d_head × seq_len - MQA:
2 × num_layers × 1 × d_head × seq_len - GQA:
2 × num_layers × num_groups × d_head × seq_len
For a 70B model at 100k tokens, MHA requires ~140 GB just for the KV-Cache, while GQA with 8 groups reduces this to ~17.5 GB—an 8× reduction that makes long-context deployment feasible on a single GPU.
FlashAttention Integration
FlashAttention is an exact-attention algorithm that minimizes high-bandwidth memory (HBM) reads and writes by fusing attention operations in SRAM using tiling and recomputation. When combined with GQA:
- The already-reduced KV-Cache from GQA means fewer bytes to transfer from HBM to SRAM
- FlashAttention's tiling further optimizes how those key-value tensors are streamed
- Together they enable 2-4× faster attention computation for long sequences compared to MHA with standard attention implementations
- This combination is standard in modern inference engines like vLLM and TensorRT-LLM
Training Stability Considerations
GQA introduces a structural constraint that requires careful handling during training:
- Uptraining from MHA: Mean-pooling the key and value heads of a pre-trained MHA checkpoint into GQA groups provides a strong initialization, minimizing quality loss
- From-scratch training: Requires tuning the number of groups; too few groups (approaching MQA) can cause training instability and loss spikes
- Group count sweet spot: Empirical evidence from Llama 2 and Mistral shows 8 groups for a 32-query-head model preserves >99% of MHA quality while achieving near-MQA memory efficiency
- Gradient flow: The shared KV heads receive gradients from multiple query heads, effectively increasing their learning signal, which can accelerate convergence for the key-value projections
Adoption in Production Models
GQA has become the de facto standard for large-scale production LLMs due to its quality-efficiency Pareto frontier:
- Llama 2 70B: 8 KV groups across 64 query heads
- Llama 3 70B & 405B: Continued GQA adoption with optimized group ratios
- Mistral Large: GQA for efficient long-context serving
- Gemma 2: Google's open models use GQA for inference efficiency
- Command R+: Cohere's RAG-optimized model leverages GQA for 128k context windows
The pattern is clear: any model designed for real-world deployment with context windows exceeding 32k tokens overwhelmingly adopts GQA.

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