Modern 7B-class LLMs, fill in typical head counts and the resulting per-head dimension
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Llama-2 7B and Mistral 7B both use d_model = 4096 with 32 query heads, giving d_head = 128. Smaller 1-3B models typically use around 16 heads.
Picture splitting a wide highway into lanes. The highway has 4096 lanes total (that is d_model). Llama-2 7B and Mistral 7B both cut it into 32 lanes of lanes, so each one is 128 wide. That count, 32, is the number of attention heads. Smaller cars (1-3B models) make do with about 16 lanes of lanes because they have less traffic to route. The arithmetic is just d_model = num_heads x d_head, and 4096 = 32 x 128 is the standard split that lots of open-weight LLMs settled on.
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 7B standard (d_model = 4096, num_heads = 32, d_head = 128), give the arithmetic identity, note both Llama-2 7B and Mistral 7B use the same config, mention smaller models drop to ~16 heads when keeping d_head = 128, explain why d_head = 128 is the kernel-preferred default.
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.
Assuming the head count is set freely. It is constrained by d_model = num_heads x d_head, so picking a head count fixes d_head and vice versa, and you cannot pick arbitrary combinations.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.