If d_model = 768 and num_heads = 12, what is d_head?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
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.
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.
What an interviewer would ask next. Try answering before peeking at the approach.
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.