Pick the formula that defines head_dim from hidden_size and num_heads.
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
head_dim = hidden_size / num_heads, integer divide. hidden_size must be divisible by num_heads or the per-head reshape errors out.
Imagine a 12-pack of soda you want to split evenly into smaller packs. If you want 4 packs, each gets 3 cans. If you want 6 packs, each gets 2. The arithmetic is just: 12 / number of packs = cans per pack. Multi-head attention does the same with a flat hidden vector: split the hidden_size into num_heads chunks, each chunk has head_dim entries, and the math is head_dim = hidden_size / num_heads. If your split does not divide evenly, the soda example breaks the same way the model does: leftover cans, errored reshape.
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.
60s: state the formula head_dim = hidden_size / num_heads, note the divisibility requirement, explain that the multi-head reshape enforces it, give worked examples (GPT-2 small: 768/12 = 64, Llama-2 7B: 4096/32 = 128), mention parameter-count preservation as the original Transformer's motivation.
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.
Treating head_dim as a free hyperparameter independent of hidden_size and num_heads. It is locked: head_dim = hidden_size / num_heads, with hidden_size % num_heads == 0 required.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.