True or false: swapping a single-head attention layer for a 12-head one (same d_model) raises the parameter count.
False. Multi-head attention reshapes the existing d_model-wide projections into h smaller blocks; the parameter count is identical to single-head at the same d_model.
Picture a giant table you can either use as one large workspace or partition with movable dividers into 12 smaller workspaces. The wood is the same; the dividers are free. Multi-head attention is the partitioned version of the same table, no extra material spent. What you gain is the ability for 12 people to work in parallel on different problems, not a bigger workspace.
Detailed answer & concept explanation~6 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.
4m: the projection shape accounting, why multi-head is a reshape and not new parameters, the parallel-specialization inductive-bias argument, the distinction between parameter count and capacity, and the KV cache asymmetry.
Real products, models, and research that use this idea.
- BERT-base (h=12, d_model=768) and a hypothetical single-head BERT-base (h=1, d_model=768) would have identical parameter counts.
- Llama-3 70B has 64 heads at d_model=8192; collapsing to h=1 at the same d_model keeps the same projection parameters.
- Probing studies on BERT and GPT consistently find head specialization (induction heads, coreference heads) at fixed parameter counts.
- When papers report 'increasing num_heads' as an ablation, they usually keep d_model fixed and show the parameter count line is flat.
- GQA changes num_kv_heads independently of num_heads, decoupling cache size from query-side parameter structure.
What an interviewer would ask next. Try answering before peeking at the approach.
QIf multi-head adds no parameters, why does it consistently outperform single-head at the same d_model?
QHow does num_heads affect KV cache size even though it does not affect parameter count?
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.
Assuming each head adds its own full-width (d_model x d_head) projection on top of the existing one. The heads slice the existing matrix; they do not add to it.
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.