True or false: switching from 1-head to 12-head attention at the same d_model increases total parameter count.
False. Multi-head is reshape, not parameter add. The Q/K/V matrices stay d_model × d_model: just sliced into num_heads × d_head blocks.
Think of a shelf with a fixed total width holding books. One head is one giant book covering the whole shelf. Twelve heads is the same shelf width split into twelve narrower book slots side by side. The wood you used to build the shelf, the total parameters, is exactly the same. You only changed how the shelf is divided. Same lumber, different compartments, twelve mini-readers instead of one big one.
Detailed answer & concept explanation~5 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.
Walk through the reshape mechanics, confirm parameter and FLOP equivalence, contrast with GQA/MQA which DO save K/V parameters, and explain why the structural difference (parallel attention patterns) is the real reason multi-head exists.
| Configuration | d_model | num_heads | d_head | Total params (Q+K+V+O) |
|---|---|---|---|---|
| single head | 768 | 1 | 768 | 4 × 768² |
| multi-head (12) | 768 | 12 | 64 | 4 × 768² |
| multi-head (8) | 768 | 8 | 96 | 4 × 768² |
| bigger model | 1024 | 12 | 85.3 (invalid) | 4 × 1024² |
Real products, models, and research that use this idea.
- Switching BERT-base from 12 to 6 heads at fixed d_model=768 changes d_head from 64 to 128, same total params, different structural budget.
- Llama 3 8B vs Llama 3 70B differ in d_model (4096 vs 8192) not just num_heads: that's where the parameter scaling comes from.
- GQA in Llama 3 reduces K/V heads from 64 to 8, this DOES save parameters on W_K and W_V (since they shrink), unlike standard multi-head reshape.
- MQA in PaLM uses 1 shared K/V head for all query heads: substantial parameter savings on W_K and W_V.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhat's the parameter difference between standard MHA, GQA, and MQA?
QIf multi-head is parameter-neutral, why isn't d_head usually chosen very small (like 8 or 16)?
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 'has its own' projection matrices that get added on top, they're slices of the same matrix, not additions.
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.