If d_model = 768 and num_heads = 12, what is d_head?
d_head = d_model / num_heads = 768 / 12 = 64. Memorize the BERT-base config; it appears constantly.
Imagine a long shelf with 768 books on it, and you want 12 librarians to each look after their own section. You'd give each librarian 768 / 12 = 64 books to manage. In multi-head attention, the shelf is the model dimension, the librarians are the attention heads, and each head's 64-book section is what we call d_head.
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.
State the formula, give the BERT-base number, explain divisibility constraint, name common configs (BERT, GPT, Llama), and mention hardware convention of d_head ∈ {64, 128} for FlashAttention compatibility.
| Model | d_model | num_heads | d_head |
|---|---|---|---|
| BERT-base | 768 | 12 | 64 |
| BERT-large | 1024 | 16 | 64 |
| GPT-2 small | 768 | 12 | 64 |
| GPT-3 175B | 12288 | 96 | 128 |
| Llama 3 70B | 8192 | 64 | 128 |
Real products, models, and research that use this idea.
- BERT-base: d_model=768, num_heads=12, d_head=64.
- BERT-large: d_model=1024, num_heads=16, d_head=64.
- GPT-3 175B: d_model=12288, num_heads=96, d_head=128.
- Llama 3 70B: d_model=8192, num_heads=64, d_head=128 (with GQA grouping 8 KV heads).
- Original Vaswani et al. 2017 transformer: d_model=512, num_heads=8, d_head=64.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy has d_head stayed at 64-128 across model scales while d_model has grown massively?
QWhat changes if d_head = 80 instead of 64 or 128?
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.
Forgetting that d_head must divide d_model evenly, pick num_heads that divides d_model cleanly, or change d_model.
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.