Glossary · Attention
Multi-head attention (MHA)
Also: MHAattention headshead dimensionhead size
Read it at the depth you need: one sentence · a paragraph · the math · in the models here
1In one sentence
Attention run as H independent heads of size h in parallel, each with its own query, key and value, their outputs concatenated and projected back to width d.
2In a paragraph
Rather than one big attention over the whole vector, the model splits it into heads: H smaller attentions that each look for something different (one may track the previous word, another the subject of the sentence). Their outputs are glued back together. In plain multi-head attention every head has its own keys and values, which makes the KV cache large; most models since 2023 share keys and values between heads instead (GQA).
3The math, shapes and parameters
With H heads of size h (usually H × h = d), the four projections are
WQ: [H·h, d] WK: [H·h, d] WV: [H·h, d] WO: [d, H·h]
so attention has 4 × d × H·h = 4d² parameters per block when H·h = d. The head size h is 64 or 128 in nearly every model; bigger models add heads, not head size. Some decouple the two: Gemma 3 27B has H·h = 4,096 with d = 5,376.
Per token, each layer caches a key and a value for every head: 2 × H × h numbers. That is what GQA, MQA and MLA reduce.
Term by term on Notation Decoder, the sister site: Multi-head attention, decoded
4In the 96 models on this site
8 of the 96 models here still use full multi-head attention (a KV head for every query head): OLMo 2 1B 16×128 · SmolLM2 1.7B 32×64 · Phi-3 Mini 32×96 · Phi-3.5 Mini 32×96 · Llama 2 7B 32×128 · OLMo 3 7B 32×128 · OLMo 2 7B 32×128 · OLMo 2 13B 40×128.
Head sizes across the site: 64 (8 models), 96 (2 models), 128 (58 models), 256 (19 models), 512 (2 models).
Introduced in Vaswani et al., “Attention Is All You Need” (2017).
Related
Self-attention · Grouped-query attention (GQA) · Multi-query attention (MQA) · KV cache · every term