Grouped-Query Attention (GQA) is an attention mechanism that partitions query heads into groups, with each group sharing a single set of key and value heads, while maintaining separate query heads per group. This design interpolates between the speed of Multi-Query Attention (MQA)—which uses a single KV head for all queries—and the expressive power of standard Multi-Head Attention (MHA).
Glossary
Grouped-Query Attention (GQA)

What is Grouped-Query Attention (GQA)?
Grouped-Query Attention is a transformer attention variant that balances computational efficiency and model quality by sharing key-value heads among groups of query heads.
GQA significantly reduces the memory bandwidth overhead of loading the KV cache during autoregressive decoding, as fewer key-value tensors must be stored and fetched. This makes it a critical optimization for self-hosted large language model inference, enabling larger batch sizes and lower latency on on-premises GPU clusters without the quality degradation often observed with pure MQA.
Key Characteristics of GQA
Grouped-Query Attention (GQA) is a hybrid attention mechanism that interpolates between the speed of Multi-Query Attention (MQA) and the quality of standard Multi-Head Attention (MHA). It achieves this by dividing query heads into groups that share a single key-value head.
The Interpolation Spectrum
GQA exists on a spectrum between two extremes:
- MHA (G=H): Every query head has its own unique key-value head. Highest quality, highest memory bandwidth.
- 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, with each group sharing one key-value head. This balances the trade-off.
KV Cache Memory Reduction
The primary motivation for GQA is reducing the size of the KV cache during autoregressive decoding. The memory footprint scales inversely with the number of groups:
- MHA stores H key-value heads per layer.
- MQA stores 1 key-value head per layer.
- GQA stores G key-value heads per layer, reducing memory by a factor of H/G compared to MHA. This allows for larger batch sizes and longer context lengths under the same memory budget.
Quality Parity with MHA
Empirical results from the original paper demonstrate that GQA achieves quality nearly indistinguishable from MHA while approaching the speed of MQA. Key findings include:
- Using G=8 for a model with H=32 (4 query heads per KV head) performs comparably to the MHA baseline on summarization and translation tasks.
- The performance gap between MQA and MHA widens with model size, but GQA closes this gap effectively.
- The shared KV heads learn to generalize, acting as a form of regularization.
Uptraining from MHA Checkpoints
GQA can be efficiently bootstrapped from existing MHA models through a process called uptraining:
- Mean Pooling: Initialize the single key-value head for a group by mean-pooling the key-value heads of all query heads in that group.
- Continued Training: Fine-tune the converted model on a small fraction (typically <10%) of the original pre-training data.
- This allows rapid conversion of existing MHA models to the GQA architecture without training from scratch, preserving the original knowledge.
Adoption in Major Models
GQA has become the standard attention mechanism for production-grade open-weight models due to its inference efficiency:
- Llama 2 70B and Llama 3 use GQA with 8 key-value heads.
- Mistral models leverage GQA alongside sliding window attention.
- Gemma and other Google-derived architectures implement GQA.
- The mechanism is a critical enabler for serving large models on commodity hardware with constrained memory bandwidth.
Computational Trade-off
While GQA reduces memory reads, the total FLOPs remain largely unchanged from MHA. The speedup comes from memory-bound operations:
- During autoregressive generation, loading the KV cache from HBM is the bottleneck.
- GQA reduces the bytes transferred per token, shifting the operation from memory-bound toward compute-bound.
- The effective throughput gain is most pronounced on hardware with limited memory bandwidth relative to compute, such as consumer GPUs and edge devices.
MHA vs. MQA vs. GQA
Structural and performance comparison of Multi-Head, Multi-Query, and Grouped-Query Attention mechanisms in transformer models.
| Feature | Multi-Head Attention (MHA) | Multi-Query Attention (MQA) | Grouped-Query Attention (GQA) |
|---|---|---|---|
KV Head Count | Equal to query heads (H) | 1 shared across all query heads | G groups (1 < G < H) |
Memory Bandwidth (KV Cache) | High (H × d_k per token) | Low (1 × d_k per token) | Medium (G × d_k per token) |
Inference Speed | Baseline | Fastest | Comparable to MQA |
Model Quality | Highest | Minor degradation | Near-identical to MHA |
Training Throughput | Baseline | Faster (reduced KV computation) | Faster (reduced KV computation) |
Uptraining Required | |||
Used In | Original Transformer, BERT | PaLM, Falcon | LLaMA 2 (70B), LLaMA 3, Mistral |
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 the GQA mechanism, its trade-offs, and its role in modern self-hosted 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. It works by interpolating between Multi-Head Attention (MHA), where every query head has its own key-value pair, and Multi-Query Attention (MQA), where all query heads share one key-value pair. In GQA, if you have H query heads, you partition them into G groups. Each group of H/G query heads shares one key head and one value head. During the attention computation, queries within the same group attend to the same key and value projections, drastically reducing the size of the KV cache during autoregressive decoding while preserving most of the model's representational quality.
Related Terms
Grouped-Query Attention sits within a broader ecosystem of transformer optimizations. These related concepts define the trade-offs between inference speed, memory footprint, and model quality.
Multi-Head Attention (MHA)
The foundational attention mechanism from the original Transformer paper. MHA uses separate key, query, and value projections for each attention head, providing maximum representational capacity at the cost of significant memory bandwidth during autoregressive decoding. The full KV cache must store unique key-value pairs for every head, making MHA the slowest option for inference but the highest quality baseline.
Multi-Query Attention (MQA)
An extreme optimization where all query heads share a single key-value head. MQA dramatically reduces the size of the KV cache and memory bandwidth requirements, leading to the fastest possible decoding speed. However, this aggressive sharing can degrade model quality and training stability, particularly on large-scale models. GQA was developed as a direct compromise between MQA's speed and MHA's quality.
KV Cache Management
The KV cache stores pre-computed key and value tensors to avoid redundant computation during autoregressive generation. Its size grows linearly with batch size, sequence length, and the number of key-value heads. GQA directly reduces the memory footprint of this cache by a factor equal to the ratio of query heads to KV heads, enabling larger batch sizes and longer context windows on memory-constrained hardware.
PagedAttention
A complementary memory management technique that partitions the KV cache into non-contiguous blocks, analogous to virtual memory paging in operating systems. When combined with GQA, PagedAttention eliminates internal fragmentation and enables near-optimal memory utilization. This pairing is a key architectural insight behind the high throughput of inference engines like vLLM.
Flash Attention
An IO-aware exact attention algorithm that fuses operations and tiles computation to minimize reads and writes to high-bandwidth memory (HBM). FlashAttention is orthogonal to GQA—it optimizes how attention is computed, while GQA optimizes what is stored. Modern implementations like FlashAttention-2 and FlashAttention-3 support GQA natively, providing compounding speedups for long-context inference.
Model Architecture Examples
GQA has been adopted by several prominent open-weight models to balance quality and efficiency:
- Llama 2 70B: Used MHA, requiring substantial KV cache memory
- Llama 3 70B: Adopted GQA with 8 key-value heads, significantly improving inference throughput
- Mistral 7B: Uses GQA alongside sliding window attention for efficient long-context processing
- Gemma 7B: Implements GQA to enable competitive performance on consumer hardware

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