Modern 7B-class LLMs, fill in typical head counts and the resulting per-head dimension
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.
Detailed answer & concept explanation~8 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.
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.
- Llama-2 7B config: hidden_size = 4096, num_attention_heads = 32, head_dim = 128.
- Mistral 7B config: hidden_size = 4096, num_attention_heads = 32, head_dim = 128 (identical to Llama-2 7B).
- Llama-2 70B config: hidden_size = 8192, num_attention_heads = 64, head_dim = 128 (head dim held constant).
- TinyLlama 1.1B: hidden_size = 2048, num_attention_heads = 32, head_dim = 64 (head dim halved at small scale).
- Llama 4 Maverick and Mistral Large 3 continue the d_head = 128 convention across the size family.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy has d_head = 128 become so standard across model sizes?
QWhat happens if you pick d_head = 80 or some other non-standard value?
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 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.
Same topic, related formats. Practice these next.