What does multi-head attention give you that a single attention head with the same total parameters cannot?
Multi-head produces N parallel attention distributions per layer instead of one, letting different heads specialize in syntax, position, and coreference at the same parameter and FLOP budget.
Imagine reading a sentence with only one highlighter, you can mark one kind of relationship at a time, say which word goes with which verb, and you have to choose what to track. Multi-head attention is like having twelve different-coloured highlighters and using them all at once: one tracks verbs, one tracks pronouns, one tracks adjacent words. You see all the structures at the same time instead of being forced to pick one. The total amount of ink is the same as one big highlighter; you just spread it across colours.
Detailed answer & concept explanation~4 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
5 min: reshape not parameter add; one distribution versus N distributions; emergent specialization (induction, syntactic, positional heads); prunability and training time diversity; modern variants MQA/GQA/MLA preserving query side diversity.
# Multi-head attention is a reshape, not extra parameters.
# d_model = n_heads * d_head
import math
import torch
import torch.nn.functional as F
B, T, d_model, n_heads = 2, 16, 512, 8
d_head = d_model // n_heads
x = torch.randn(B, T, d_model)
W_q = torch.nn.Linear(d_model, d_model, bias=False)
W_k = torch.nn.Linear(d_model, d_model, bias=False)
W_v = torch.nn.Linear(d_model, d_model, bias=False)
W_o = torch.nn.Linear(d_model, d_model, bias=False)
q = W_q(x).view(B, T, n_heads, d_head).transpose(1, 2)
k = W_k(x).view(B, T, n_heads, d_head).transpose(1, 2)
v = W_v(x).view(B, T, n_heads, d_head).transpose(1, 2)
scores = (q @ k.transpose(-2, -1)) / math.sqrt(d_head)
attn = F.softmax(scores, dim=-1)
out = (attn @ v).transpose(1, 2).reshape(B, T, d_model)
out = W_o(out)Real products, models, and research that use this idea.
- GPT-5.5 and Claude Opus 4.7 both ship deep transformer stacks with many parallel heads per layer, combined with grouped-query attention to shrink the KV cache at long context.
- Llama 4 Maverick uses many query heads per layer with a small number of grouped K/V heads: query side diversity preserved, K/V side compressed for inference.
- DeepSeek V4 ships multi-head latent attention, which keeps multiple query heads while compressing the K/V cache into a smaller latent space.
- Olsson et al. 2022 'In-context Learning and Induction Heads' is the canonical example of emergent head specialization driving in context learning behavior.
- The original Vaswani et al. 2017 transformer used 8 heads with d-model 512 and head dim 64.
What an interviewer would ask next. Try answering before peeking at the approach.
QIf many heads are prunable post-training, why train with so many in the first place?
QHow do MQA, GQA, and MLA preserve the multi-head win while saving inference memory?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Many candidates claim multi-head adds parameters or reduces compute. It does neither, it is a reshape that buys parallel attention patterns at constant cost.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.