Multi-Query Attention (MQA) is an architectural modification to the standard Transformer that eliminates the per-head Key and Value weight matrices. Instead of learning h distinct sets of Key and Value projections, all Query heads attend to the same shared Key and Value tensors. This design drastically reduces the size of the KV cache during autoregressive decoding, slashing memory bandwidth requirements and accelerating inference latency with minimal degradation in model quality.
Glossary
Multi-Query Attention (MQA)

What is Multi-Query Attention (MQA)?
Multi-Query Attention (MQA) is a variant of the multi-head attention mechanism where all attention heads share a single set of Key and Value projection weights, while maintaining separate Query projections.
The primary trade-off in MQA is between memory efficiency and representational capacity. While sharing Keys and Values removes the model's ability to attend to information in h different representation subspaces, the memory savings are substantial, often cutting the KV cache size by a factor equal to the number of heads. This makes MQA critical for deploying large language models in memory-constrained environments. Grouped-Query Attention (GQA) later emerged as an interpolation between MQA and standard Multi-Head Attention to recover some of this lost capacity.
Key Characteristics of MQA
Multi-Query Attention (MQA) is defined by a radical simplification of the standard multi-head attention mechanism, specifically targeting the memory bandwidth bottleneck during autoregressive decoding.
Shared Key-Value Projections
The defining architectural change in MQA is that all attention heads share a single set of Key and Value projection weights. Unlike standard Multi-Head Attention where each head has distinct K and V linear layers, MQA collapses them into one. The Query projections remain independent per head, allowing the model to still attend to different representation subspaces while drastically reducing the number of parameters and the size of the KV cache.
KV Cache Memory Reduction
The primary motivation for MQA is to slash the memory footprint of the Key-Value (KV) cache during inference. In a standard model with h heads, the cache stores h sets of keys and values per token. MQA stores only 1 set.
- Memory Savings: Reduces KV cache size by a factor of h (e.g., 96x reduction for a 96-head model).
- Bottleneck Relief: Shifts the inference bottleneck from memory bandwidth to compute, enabling much faster token generation.
Inference Speedup vs. Quality Trade-off
MQA offers a significant speedup in autoregressive decoding by reducing the data that must be loaded from GPU memory at each step. However, this aggressive sharing can lead to a minor degradation in model quality compared to standard Multi-Head Attention.
- Throughput: Enables much higher batch sizes during inference.
- Quality: The capacity constraint from shared K and V can slightly reduce the model's ability to capture fine-grained syntactic or semantic nuances.
Relationship to Grouped-Query Attention (GQA)
MQA represents one extreme of the attention spectrum, while Grouped-Query Attention (GQA) is a direct interpolation between MQA and standard Multi-Head Attention. GQA partitions Query heads into G groups, with each group sharing a single Key and Value head.
- MQA: G = 1 (all heads share one K/V).
- GQA: 1 < G < h (balances speed and quality).
- MHA: G = h (no sharing, maximum quality).
GQA was adopted by models like Llama 2 to recover the quality lost by MQA while retaining most of the speed benefits.
Adoption in Production Models
MQA was popularized by Google's PaLM model and the original Chinchilla paper, which demonstrated its effectiveness at scale. It is a critical technique for serving large language models in latency-sensitive applications.
- PaLM: Used MQA to achieve state-of-the-art few-shot results with efficient serving.
- Chinchilla: Showed MQA had minimal performance degradation compared to MHA when trained on an optimal compute budget.
- Legacy: While foundational, many newer open-source models have migrated to GQA for a better quality-speed Pareto frontier.
Training and Kernel Implications
MQA requires custom attention kernels for maximum efficiency. Standard FlashAttention implementations must be adapted to handle the asymmetric shape where Query heads outnumber Key/Value heads.
- Training: MQA trains faster than MHA due to reduced FLOPs in the attention calculation.
- Kernel Design: The 'multi-query' pattern requires tiling strategies that broadcast the single K and V tensors across all Query heads to fully utilize GPU SRAM and avoid redundant HBM reads.
MQA vs. MHA vs. GQA: Attention Variant Comparison
Comparison of memory bandwidth requirements and quality trade-offs between standard Multi-Head Attention, Multi-Query Attention, and Grouped-Query Attention during autoregressive decoding.
| Feature | Multi-Head Attention (MHA) | Multi-Query Attention (MQA) | Grouped-Query Attention (GQA) |
|---|---|---|---|
Key/Value Head Count | H (one per Query head) | 1 (shared across all heads) | G (1 < G < H) |
KV Cache Size (Relative) | 100% (baseline) | 1/H (e.g., 3.1% for H=32) | G/H (e.g., 12.5% for G=4, H=32) |
Memory Bandwidth Bottleneck | High (bound by KV cache reads) | Low (significantly reduced reads) | Medium (tunable reduction) |
Inference Speedup vs. MHA | 1x (baseline) | 3-5x faster decoding | 1.5-3x faster decoding |
Model Quality Impact | Highest (full expressivity) | Minor degradation | Negligible degradation (matches MHA) |
Training Throughput | Baseline | Faster (reduced KV projection compute) | Slightly faster than MHA |
Uptraining Compatibility | |||
Adopted By | Original Transformer, BERT | PaLM, Falcon | Llama 2 70B, Llama 3, Mistral |
Frequently Asked Questions
Clear, technical answers to the most common questions about Multi-Query Attention (MQA), its mechanisms, and its role in optimizing large language model inference.
Multi-Query Attention (MQA) is a variant of the multi-head attention mechanism where all attention heads share a single set of Key and Value projection weights, while retaining distinct Query projection weights for each head. In standard multi-head attention, each head has its own independent linear projections for Q, K, and V. MQA fundamentally alters this by collapsing the K and V projections into one shared pair. During computation, the distinct Query heads all interact with this single shared Key-Value pair. This architectural change directly targets the memory bottleneck during autoregressive inference. Because the KV cache stores only one set of Key and Value vectors per token instead of one per head, the cache size is reduced by a factor equal to the number of heads. This dramatically lowers memory bandwidth requirements, enabling faster token generation and larger batch sizes on memory-constrained hardware.
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 architectural variants and optimization techniques that build upon or contrast with Multi-Query Attention's core principle of sharing Key and Value projections.
Multi-Head Attention (MHA)
The standard attention mechanism where each head has its own Query, Key, and Value projection weights. This allows the model to jointly attend to information from different representation subspaces at different positions.
- KV Cache Size: Scales linearly with the number of heads (h × d_k per token)
- Memory Bandwidth: High, as the full per-head KV cache must be loaded during autoregressive decoding
- Quality: Generally highest expressivity, serving as the upper bound for attention fidelity
MHA is the baseline against which MQA and GQA trade-offs are measured.
Grouped-Query Attention (GQA)
An interpolation between MHA and MQA that partitions Query heads into groups, with each group sharing a single set of Key and Value heads.
- Groups: Typically 2-8 groups, balancing quality and speed
- KV Cache Reduction: Reduces KV cache size by a factor equal to the number of groups
- Adoption: Used in Llama 2 70B, Llama 3, and Mistral models
GQA recovers most of the quality lost by MQA while maintaining significant memory bandwidth savings, making it the practical sweet spot for large-scale deployment.
Key-Value (KV) Cache
An inference optimization that stores previously computed Key and Value vectors for all generated tokens, preventing redundant re-computation during autoregressive decoding.
- Problem Solved: Without caching, each new token would require re-computing attention over the entire sequence
- Memory Footprint: Grows linearly with batch size, sequence length, and number of heads
- MQA Impact: MQA's single KV head reduces cache size by a factor of h compared to MHA
The KV cache is the primary bottleneck that MQA and GQA are designed to alleviate, making them critical for high-throughput serving.
FlashAttention
An IO-aware exact-attention algorithm that minimizes high-bandwidth memory (HBM) reads and writes by fusing operations in a tiled manner within GPU SRAM.
- Tiling: Computes attention in blocks that fit in fast SRAM, avoiding materializing the full N×N attention matrix in HBM
- Recomputation: Recomputes attention statistics during the backward pass rather than storing them
- Compatibility: Works with MHA, MQA, and GQA, providing orthogonal speedups
FlashAttention addresses the memory bandwidth bottleneck from a different angle than MQA, and the two techniques are complementary in production inference stacks.
Quadratic Complexity Bottleneck
The inherent computational limitation of standard self-attention where both memory and time complexity scale as O(n²) with respect to input sequence length n.
- Cause: The attention score matrix requires computing pairwise interactions between all tokens
- Impact: Makes processing long documents (>8K tokens) prohibitively expensive
- Solutions: MQA addresses the memory bandwidth dimension of this problem, while sparse attention and linear attention variants tackle the compute dimension
MQA does not reduce the quadratic compute complexity but significantly reduces the memory bandwidth required to load the KV cache during decoding.
Attention Head Pruning
A model compression technique that identifies and removes redundant or low-importance attention heads from a trained Transformer.
- Motivation: Many attention heads learn overlapping or trivial patterns
- Methods: Magnitude-based pruning, Taylor expansion scoring, or learned masking
- Relationship to MQA: Pruning permanently removes heads, while MQA structurally shares KV projections without discarding Query diversity
Head pruning can be applied on top of MQA models to further reduce parameters, though MQA's already-shared KV heads leave fewer redundant heads to prune compared to MHA.

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