Multi-Query Attention (MQA) is a transformer attention mechanism where multiple query heads share a single, common key head and a single, common value head. This architectural change, introduced to optimize inference, reduces the size of the KV cache by a factor equal to the number of attention heads, significantly lowering memory footprint and the I/O cost of reading cached states during autoregressive decoding. The primary trade-off is a potential reduction in model capacity compared to standard Multi-Head Attention (MHA).
Glossary
Multi-Query Attention (MQA)

What is Multi-Query Attention (MQA)?
A transformer attention variant designed to drastically reduce the memory and bandwidth cost of the key-value cache during inference.
MQA achieves its efficiency gains by projecting the decoder hidden state into many query vectors but only one key and one value vector per layer. This contrasts with MHA, which projects separate keys and values for each head. The technique is particularly impactful for long-context and high-throughput serving, as the KV cache is often the memory-bound bottleneck. Grouped-Query Attention (GQA) is a popular generalization that provides a tunable middle ground between MQA's efficiency and MHA's expressiveness.
Key Characteristics of Multi-Query Attention
Multi-Query Attention (MQA) is a transformer attention variant designed to drastically reduce the memory and I/O cost of the key-value (KV) cache. Its core innovation is having multiple query heads share a single key head and a single value head.
Shared Key and Value Heads
The defining architectural feature of MQA. Unlike standard Multi-Head Attention (MHA), where each of the N query heads has its own dedicated key and value head, MQA uses a single, shared key head and a single, shared value head for all query heads.
- Mechanism: During the attention computation, the
Ndistinct query vectors all attend to the same, single set of key and value vectors. - Impact: This reduces the number of key and value tensors that must be stored in the KV cache from
2 * Nper layer to just2per layer (one key, one value).
Drastic KV Cache Memory Reduction
MQA's primary benefit is a linear reduction in the memory footprint of the KV cache, which is the dominant memory consumer during autoregressive decoding.
- Quantitative Reduction: For a model with
hattention heads, MQA reduces the size of the KV cache by a factor of approximatelyh. For a 32-head model, this is a ~32x reduction in the number of cached key/value vectors. - Consequence: This allows for either longer context windows within the same GPU memory budget or higher batch sizes to increase throughput, directly addressing inference cost and latency.
Reduced Memory Bandwidth Pressure
By caching fewer tensors, MQA significantly decreases the amount of data that must be read from GPU memory during each decoding step, moving the computation from a memory-bound regime towards a compute-bound one.
- The Bottleneck: In standard MHA, loading the massive KV cache for attention is often the performance limiter.
- MQA's Effect: With a smaller cache, the memory I/O volume per token is drastically lower. This reduces latency and increases the theoretical maximum tokens-per-second throughput, especially on memory-bandwidth-constrained hardware.
Trade-off: Potential Quality Degradation
The memory efficiency of MQA comes with a trade-off. Sharing keys/values across all queries can reduce the model's representational capacity and expressiveness.
- The Risk: The shared key/value projection may act as an information bottleneck, potentially leading to a drop in output quality or factual accuracy compared to the full MHA baseline, particularly on complex reasoning tasks.
- Empirical Observation: The degradation is often model and task-dependent. Some large models (e.g., certain versions of Falcon) use MQA effectively, while others require careful tuning or prefer the hybrid Grouped-Query Attention (GQA) approach.
Architectural Simplicity and Efficiency
MQA simplifies the attention computation graph and parameter count, leading to cleaner and faster kernel implementations.
- Fewer Parameters: The model has fewer linear projection matrices for keys and values, slightly reducing the total parameter count.
- Kernel Optimization: The simpler data access pattern (many queries to one key/value set) can be optimized into highly efficient GPU kernels. This contributes to lower latency beyond just the cache savings.
- Decoding Step: The autoregressive step becomes:
Attn = softmax(Q_all @ K_shared.T) @ V_shared, whereQ_allis the concatenated query tensor.
Relationship to Grouped-Query Attention (GQA)
Grouped-Query Attention (GQA) is a generalization and intermediate point between MHA and MQA, created to mitigate MQA's quality trade-off.
- How it Works: Instead of
Nquery heads sharing one key/value head (MQA) or each having its own (MHA), GQA groups queries intoGgroups. Each group shares a single key head and value head. - The Spectrum:
G = N-> Multi-Head Attention (largest cache, highest quality).1 < G < N-> Grouped-Query Attention (balanced trade-off).G = 1-> Multi-Query Attention (smallest cache, highest efficiency).
- Practical Use: GQA allows practitioners to tune the KV cache size versus model quality based on their specific deployment constraints.
MQA vs. Multi-Head Attention vs. Grouped-Query Attention
A technical comparison of three transformer attention variants, focusing on their KV cache memory footprint, computational characteristics, and typical use cases.
| Feature | Multi-Head Attention (MHA) | Multi-Query Attention (MQA) | Grouped-Query Attention (GQA) |
|---|---|---|---|
Core Architecture | Each query head has a unique, dedicated key head and value head. | All query heads share a single, common key head and a single, common value head. | Query heads are partitioned into G groups; each group shares a single key head and value head. |
KV Cache Size per Layer | 2 * Batch Size * Sequence Length * Num_Heads * Head_Dim | 2 * Batch Size * Sequence Length * 1 * Head_Dim | 2 * Batch Size * Sequence Length * Num_Groups * Head_Dim |
Memory Reduction vs. MHA | 0% (Baseline) | ~90-95% (for models with 8-32 heads) | Tunable. ~50-90% (e.g., 8 groups for a 32-head model yields 75% reduction). |
Primary Optimization Goal | Model quality and representational capacity. | Maximum memory and I/O bandwidth reduction for the KV cache. | A tunable trade-off between MQA's memory savings and MHA's model quality. |
Inference Throughput Impact | Standard baseline. KV cache I/O can become a bottleneck at scale. | Highest potential throughput for memory-bound, long-context, or high-batch scenarios. | High throughput, often closer to MQA than to MHA, while preserving more quality. |
Typical Model Quality | Highest, due to full parameterization for each attention head. | Can incur a measurable quality drop, especially on tasks requiring nuanced multi-head differentiation. | Minimal quality degradation when using a sufficient number of groups (e.g., 4-8). |
Adoption Examples | Original Transformer, BERT, T5, early GPT models. | PaLM, StarCoder, Falcon, many inference-optimized models. | Llama 2 (70B), Llama 3, Gemma, Command R, modern general-purpose models. |
Best For | Training and research where quality is the sole priority. | High-throughput production inference where latency/cost dominate and some quality loss is acceptable. | General-purpose models requiring a balanced cost-quality trade-off for production deployment. |
Models and Frameworks Using MQA
Multi-Query Attention (MQA) has been adopted by several prominent open-source and proprietary models to achieve significant reductions in memory and I/O costs. This section details key implementations and the frameworks that support them.
Frequently Asked Questions
Multi-Query Attention (MQA) is a key technique for optimizing transformer inference by drastically reducing the memory and bandwidth cost of the KV cache. These questions address its core mechanisms, trade-offs, and practical applications.
Multi-Query Attention (MQA) is a transformer attention variant where multiple query heads share a single, common key head and a single, common value head. In standard Multi-Head Attention (MHA), each of the N query heads has its own corresponding key and value head, resulting in N unique KV pairs per layer. MQA collapses this to just one shared KV pair for all query heads. During the attention operation, the shared key and value tensors are broadcast and used by all query heads in parallel. This architectural change directly reduces the size of the KV cache by a factor of N, where N is the number of attention heads, leading to significant memory and I/O savings during the autoregressive decode phase.
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
Multi-Query Attention (MQA) is one technique within a broader set of optimizations for managing the key-value cache in transformer inference. These related concepts define the trade-offs, alternatives, and complementary systems used to reduce memory and latency.
Grouped-Query Attention (GQA)
Grouped-Query Attention is a hybrid attention mechanism that serves as a middle ground between Multi-Head Attention (MHA) and Multi-Query Attention (MQA). Instead of a single key and value head for all queries (MQA) or independent heads for each query (MHA), GQA groups multiple query heads to share a single key head and value head.
- Design Trade-off: It offers a tunable parameter—the group size—allowing practitioners to balance the KV cache memory reduction of MQA against the model quality and capacity of full MHA.
- Adoption: Models like Llama 2 and Gemma use GQA, as it often recovers most of the quality of MHA while providing significant memory savings over it.
- Implementation: The grouped queries compute attention against a shared, smaller set of key and value projections, reducing the cache size proportionally to the group size.
KV Cache
A KV cache, or key-value cache, is the fundamental memory structure optimized by MQA. During the autoregressive decode phase of a transformer, the model computes key (K) and value (V) tensors for each input token.
- Purpose: Instead of recomputing these tensors for every new token, they are stored in the KV cache. For the next token, the model only computes the new query (
Q) and performs attention against the cachedKandVfrom all previous tokens. - Memory Footprint: The size of the KV cache scales with batch size, sequence length, and the number of attention heads. It is often the primary bottleneck for long-context or high-throughput inference.
- Impact of MQA: MQA directly reduces this footprint by sharing a single
KandVhead across all query heads, drastically shrinking the cache size compared to standard multi-head attention.
PagedAttention
PagedAttention is a memory management algorithm, central to the vLLM inference engine, that optimizes how the KV cache is allocated in physical memory. It treats the cache analogously to virtual memory in an operating system.
- Mechanism: The KV cache for each sequence is divided into fixed-size blocks or pages. These pages can be non-contiguous in physical GPU memory.
- Key Benefit: This eliminates internal fragmentation, a major source of memory waste in continuous batching where sequences have different lengths. It allows for near-optimal memory utilization.
- Synergy with MQA: While MQA reduces the size of the cache per head, PagedAttention optimizes its allocation and sharing across requests. They are complementary techniques for maximizing throughput.
Continuous Batching
Continuous batching (or iterative batching) is a scheduling optimization that dynamically groups incoming inference requests to maximize GPU utilization, creating a direct interaction with KV cache management.
- Dynamic Scheduling: Unlike static batching, new requests can join the batch as soon as resources are available, and finished sequences can exit independently.
- Cache Implications: This results in a heterogeneous mix of sequence lengths running concurrently. Efficiently managing the disparate KV caches for these sequences is critical; techniques like PagedAttention were invented to solve this challenge.
- System-Level Goal: The combined use of MQA (smaller caches) and advanced memory management (e.g., PagedAttention) enables continuous batching to achieve very high throughput without running out of memory.
KV Cache Quantization
KV cache quantization is a compression technique that reduces the memory footprint of the cache by storing the key and value tensors in a lower numerical precision format.
- Precision Trade-off: Common techniques involve storing cache tensors in FP8, INT8, or even INT4 precision instead of the standard FP16 or BF16 used during computation.
- Objective: The goal is to reduce memory bandwidth pressure and increase effective cache capacity, allowing for longer contexts or larger batches. This is a complementary approach to MQA.
- Challenge: Aggressive quantization can degrade model quality if not applied carefully. Quantization-aware scaling factors are often used to minimize the error introduced by the lower precision.
Memory-Bound Regime
A memory-bound regime describes the state where an inference system's performance is limited by the speed of memory accesses rather than by raw computational power (compute-bound).
- Primary Culprit: The KV cache is a major driver of memory-bound behavior. During each decoding step, the entire cached context must be read from GPU memory to compute attention scores.
- Impact of MQA: By drastically reducing the size of the KV cache, MQA directly alleviates this bottleneck. It decreases the total volume of data that must be fetched per token, improving decode latency and reducing memory bandwidth saturation.
- System Design: Understanding this regime is crucial for CTOs and systems architects. Optimizations like MQA, quantization, and kernel fusion (e.g., FlashAttention) are all targeted at moving the workload away from being memory-bound.

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