Compare hidden_size, d_model, and embedding_dim, three names for the same thing or three different things?
Three names, one number. d_model (papers), hidden_size (HF config), embedding_dim (PyTorch nn.Embedding) all refer to the per-token residual-stream width.
Imagine three different stores selling the exact same product but with different labels: one calls it a 'large coffee', another 'a 16-ounce', the third 'one of the bigger sizes'. The drink is the same drink. d_model, hidden_size, and embedding_dim are like that, the same vector width, just named differently depending on whether you are reading a research paper, a Hugging Face config file, or PyTorch source code. The number behind all three labels is one quantity: how wide each token's vector is as it flows through the transformer.
Detailed answer & concept explanation~10 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 three names refer to the same residual stream width, name where each is used (papers, HF config, PyTorch), explain why they must be equal (residual addition requires matching shapes), give a worked example (Llama-2 7B: 4096), distinguish from head_dim and intermediate_size which are different quantities.
Real products, models, and research that use this idea.
- Llama-2 7B config.json: hidden_size = 4096. Same value as d_model in any paper about the model and as embedding_dim in any PyTorch implementation.
- GPT-2 small: hidden_size = 768, the canonical small-transformer reference value.
- Llama-2 70B: hidden_size = 8192, larger residual stream for the larger model.
- Mistral 7B: hidden_size = 4096, matches Llama-2 7B for infrastructure reuse.
- Llama 4 Maverick and DeepSeek V4 expose hidden_size in their configs as the residual stream width; the value scales with model class.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy does the residual stream width have to stay constant through every block of the model?
QWhat is the relationship between d_model and head_dim, and why is it different from d_model and intermediate_size?
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.
Treating these as three different hyperparameters you can set independently. They are always the same value, the residual stream width must match the embedding output which must match every block's input.
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.