Which config token names the count of parallel attention heads in a layer?
n_heads (or num_attention_heads in HuggingFace configs, h in papers) names the number of parallel (Q, K, V) projection slices in one attention layer.
Imagine the model's config file as a recipe card. One line says how many separate burners the attention kitchen runs in parallel. That number is n_heads, the count of independent attention paths through a single layer. Modern recipes also have a second number for how many shared sauce pots feed all those burners (num_kv_heads under GQA), but the burner count itself is n_heads.
Detailed answer & concept explanation~6 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.
3m: the canonical names (n_heads, num_attention_heads, h), what they control vs do not control, the split into num_kv_heads under GQA, and concrete production examples like Llama 4 Maverick's 64 query heads with 8 KV heads.
| Token | Where it appears | What it counts |
|---|---|---|
| n_heads | Papers, casual usage | Parallel attention heads per layer |
| num_attention_heads | HuggingFace config.json | Same as n_heads |
| num_heads | Some libraries (PyTorch nn.MultiheadAttention) | Same as n_heads |
| h | Math notation in papers | Same as n_heads |
| num_key_value_heads | HuggingFace config.json (GQA/MQA models) | Number of distinct K, V heads in the cache |
Real products, models, and research that use this idea.
- Llama 4 Maverick's config has `num_attention_heads: 64` and `num_key_value_heads: 8`.
- Llama-2 7B has `num_attention_heads: 32` and `num_key_value_heads: 32` (it is MHA, not GQA).
- Mistral 7B has `num_attention_heads: 32` and `num_key_value_heads: 8` (GQA with group size 4).
- DeepSeek V4 keeps a normal n_heads on the query side and uses MLA to compress K, V into a latent that occupies a single logical KV slot per layer.
- Any HuggingFace transformers config file (`config.json`) exposes both keys for any GQA or MQA-equipped model.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow is `d_head` related to `n_heads` and `d_model`?
QWhy do modern Hugging Face configs expose num_key_value_heads as a separate key?
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.
Confusing n_heads (query side) with num_kv_heads (cache side). Under MHA they are equal; under GQA or MQA they differ and conflating them gives wrong cache math.
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.