Zenaique

Expand MQA and state its KV-cache cost tradeoff

Flashcard·Easy·4.0 · 0·~30s·Asked atAmdMeeshoNotion·Relevant atCloudflareGroqMeta
Attempt it
TL;DR

MQA = Multi-Query Attention: every Q head keeps its own projection but all heads share one K and one V, shrinking the KV cache by n_heads at a measurable quality cost.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Picture a meeting room with twenty people asking different questions, each consulting their own personal filing cabinet. MQA tears out nineteen of the cabinets and tells everyone to share the one that remains. The questions still vary person to person, but they all consult the same source of information. That makes the room dramatically cheaper to run, because there is only one cabinet to maintain. The catch is that the single shared cabinet has less room to specialize, so subtle answers may drop in quality. MQA is that aggressive sharing trade, useful when you need to squeeze the last byte of memory out of a deployment.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

MQA is the most aggressive KV-cache reduction available in the conventional attention family. It is also a useful pedagogical anchor: GQA was invented to fix MQA's quality regression, and multi-head latent attention in DeepSeek V4 takes the same idea further. So understanding MQA is the gateway to the modern attention-variant landscape.

The acronym expands to Multi-Query Attention. The name is slightly misleading, because the queries are not what changed; they remain multi-head exactly as in MHA. What changed is the key and value side. Every query head still has its own projection, but all query heads share a single K head and a single V head per layer. There is only one K tensor and one V tensor in the KV cache regardless of how many query heads the model has.

This deep dive walks through the mechanics, the inference-cost argument, the quality picture, the historical adopters, why the field moved on to GQA, and where MQA still makes sense in 2026.

What stays plural and what collapses

Start with a concrete model. Llama-2 7B before the GQA era had 32 Q heads, 32 K heads, and 32 V heads per attention layer. The per-token KV cache for one layer is 2 * 32 * d_head * bytes. With d_head = 128 and FP16, that is 16 KB per token per layer, and across 32 layers, 512 KB per token.

MQA changes the K and V side to a single head each. So the same model under MQA would have 32 Q heads but only 1 K head and 1 V head per layer. The per-token KV cache becomes 2 * 1 * 128 * 2 = 512 bytes per layer, 16 KB per token across the whole model. A 32x reduction in KV bytes per token.

Q projections are unchanged. The model still produces 32 distinct query vectors per token per layer. The only difference is that all 32 queries look up into the same K, weight by the same scores, and aggregate from the same V. From a code perspective MQA is a one-line change to the attention kernel: gather K and V at index 0 regardless of which query head you are computing for.

Why this works at inference time
Why the field moved to GQA
Where MQA still earns its place
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.
VariantK and V headsKV cache sizeQuality vs MHA
MHAn_headsFullBaseline
MQA11 / n_headsMeasurable regression on harder tasks
GQA (G = 8)G = 8G / n_headsWithin a fraction of a percent

Real products, models, and research that use this idea.

  • PaLM, the early Google decoder-only model, used MQA throughout to keep its KV cache small at scale.
  • Falcon-40B from TII shipped MQA, which let it serve faster decode than equivalently sized MHA models.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QWhy does collapsing K and V hurt quality more than collapsing Q would?
A

Q determines which content each token searches for; K and V determine what is stored and retrieved. Sharing K and V across heads means every query head retrieves from the same memory. Sharing Q would be far worse because it would force every head to ask the same question.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Confusing MQA with GQA. MQA shares one K and V across the entire layer; GQA shares per group of heads.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • Expansion of the MQA acronym and what stays plural versus what collapses

  • Why decode bandwidth is the metric MQA optimizes

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Explain scaled dot product attention.
Short answer·Medium