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

  1. Each query head computes its own query projection.
  2. Only one key and one value projection are computed, shared by all query heads.
  3. 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.
  4. 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

TermHow it differs
Multi-head latent attentionMulti-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.

ON-PREMISES EXAMPLE

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.

Sources

In the glossary: Glossary, M to Q

What does this term mean for your infrastructure?

We can work out together in a technical assessment how it maps onto your data, hardware and security requirements.

Request a technical assessment →

This site sets no cookies. Visitor numbers are counted in aggregate using a cookieless method that does not identify anyone. See the Privacy Policy for details.