# Multi-Query Attention (MQA)

- **Canonical URL:** https://getaimath.com/dictionary/multi-query-attention-mqa/
- **Topics:** [Transformer Architecture](https://getaimath.com/dictionary/category/transformer-architecture/)
- **Last updated:** 2026-11-25

## What is Multi-Query Attention (MQA)?

**In one sentence:** Multi-query attention is a faster type of attention where all heads share one set of keys and values but keep separate queries.

Normally every head has its own keys and values, which take lots of memory during generation. Sharing one set makes the KV cache much smaller and speeds up inference, with a small loss in quality.

![Transformers & Attention: The Smart Highlighter — Simple cartoon diagram showing how a Transformer reads a whole sentence at once and shines a bright highlighter beam from the word "IT" back to "trophy" so it knows what "IT" means.](https://getaimath.com/diagrams/transformer-architecture.png)
*Napkin Diagram (Transformer Architecture): Older AI read word-by-word and often lost track of earlier words; a Transformer highlights which words connect to which.*

## What is an example of Multi-Query Attention (MQA)?

A model with 32 heads using MQA stores keys and values for just 1 head instead of 32.

## Why does Multi-Query Attention (MQA) matter?

MQA makes models cheaper and faster to run, especially with long texts.

## Related Concepts

- [Cross-Attention](https://getaimath.com/dictionary/cross-attention/): Cross-attention lets one part of a model pay attention to a different input, like a decoder looking at an encoder's output.
- [Grouped-Query Attention (GQA)](https://getaimath.com/dictionary/grouped-query-attention-gqa/): Grouped-query attention is a middle ground where groups of heads share keys and values, balancing speed and quality.
- [Masked Attention](https://getaimath.com/dictionary/masked-attention/): Masked attention is attention where some positions are hidden, so certain words cannot look at certain other words.
- [FlashAttention](https://getaimath.com/dictionary/flashattention/): FlashAttention is a clever way to compute attention on GPUs that is much faster and uses much less memory, while giving the same results.
- [Causal Attention](https://getaimath.com/dictionary/causal-attention/): Causal attention only lets each word look at the words before it, never the words after.
- [Attention Mask](https://getaimath.com/dictionary/attention-mask/): An attention mask is a pattern that tells the model which positions it may or may not attend to.

---
Source: The AI Math Dictionary (https://getaimath.com/dictionary/multi-query-attention-mqa/)
