Notes

Multi-Query Attention (MQA)

Generating text one token at a time is not limited by arithmetic — it is limited by how fast the GPU can read memory. Multi-Query Attention attacks exactly that bottleneck, by deleting most of what has to be read.

One set of keys for every head

Standard multi-head attention gives each head its own queries, keys and values. During generation the keys and values of every past token sit in the KV cache, so the cache is proportional to the number of heads — and each new token requires reading the whole thing. MQA keeps the separate query projections but has all heads share a single key head and a single value head. With 32 heads, that shrinks the KV cache roughly 32-fold. The weight matrices barely change size; the win is in the cache and in the memory traffic per step.

What it buys and what it costs
  • Decoding gets dramatically faster at long context lengths, and far more concurrent requests fit in GPU memory, which is throughput on a serving box.
  • Quality drops slightly and training can become less stable — the original work measured a small but real degradation on translation.
  • Grouped-Query Attention was introduced to sit between the two extremes: several groups of heads, each sharing one key-value pair, recovering most of the quality at most of the speed.

Falcon and PaLM shipped with MQA, and it is a large part of why a long conversation with those models stays affordable to serve. Most newer open models choose GQA instead, which is best read as MQA's compromise rather than its replacement.

Multi-Query Attention is an attention variant in which all query heads share one key head and one value head instead of each head keeping its own. This shrinks the KV cache and the memory traffic per generated token by roughly the head count, so long-context decoding runs far faster and more requests fit on a GPU. The cost is a small quality loss, the trade that Grouped-Query Attention later softened.

When an assistant writes a reply, it keeps notes on everything said so far, so it does not have to re-read the whole conversation for every new word. Normally it keeps dozens of parallel sets of those notes — one for each internal reader inside the model. Multi-Query Attention is the decision to keep a single shared set instead. The notes become far smaller, so the assistant writes faster and one computer can serve many more people at the same time. The trade-off is a slight loss of nuance, which is why a middle-ground version keeping a few sets became more popular.