What is multi-query attention?
Multi-query attention is an attention layout in which all query heads in multi-head attention share a single key head and a single value head, minimising the key and value data stored at inference and read at every step.
Unlike grouped-query attention, which keeps several key and value heads, multi-query attention keeps just one. Query heads remain many, so it is not the same as single-head attention.
- Topic
- Machine learning, models and training
- Also known as
- MQA
- Origin
- 2019, Shazeer
How multi-query attention works
- Each query head computes its own query projection.
- Only one key and one value projection are computed, shared by all query heads.
- The KV cache stores data for one head whatever the query head count; calculation: in a 32-head model it is 32 times smaller than with classic multi-head attention.
- During decoding, less data is read from memory per new token, so generation speeds up.
In more detail
Different effects in prefill and decode
Unlike decoding, which is memory-bandwidth-bound and benefits directly from MQA's smaller KV cache, the prefill phase is compute-bound because all prompt tokens are processed in parallel. As a result, MQA noticeably improves token-generation throughput and reduces inter-token latency (ITL), while its impact on time-to-first-token (TTFT) for long prompts is modest.
Commonly confused terms
| Term | How it differs |
|---|---|
| Multi-head latent attention | Multi-head latent attention compresses key and value matrices into a shared low-rank latent vector stored in the KV cache and reconstructs them on the fly, achieving even smaller KV caches than GQA and MQA while preserving multi-head expressivity. |
Why multi-query attention matters for on-premises AI
The decode phase of text generation is often limited by memory reads rather than compute; multi-query attention speeds it up by reducing key and value data to read, freeing room on the same GPU for more concurrent requests. The cost can be some quality loss and training instability. Many recent models therefore prefer grouped-query attention, which balances quality and memory, or multi-head latent attention, which compresses the KV cache; which layout a model uses enters the hardware plan.
To cut response latency in an in-house model summarising call centre notes in real time, a telecoms operator tries a small multi-query attention model, measuring concurrent sessions per GPU alongside summary quality.
Common questions
Is multi-query attention the same as single-head attention?
No. Query heads remain many; only the key and value head is single and shared by all query heads.
Why does multi-query attention speed things up?
Less key and value data is read from memory at each decoding step. Since this phase is often memory-bound, generation gets faster.
Related terms
Sources
- Shazeer, Fast Transformer Decoding: One Write-Head is All You Need, 2019
- Ainslie et al., GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints, 2023
In the glossary: Glossary, M to Q