Define d_model and name three architecture knobs that scale with it
d_model is the hidden size of the residual stream. Attention head dim, FFN hidden dim, KV cache, and the embedding table all scale with d_model.
Picture the transformer as a highway with a fixed number of lanes. d_model is how many lanes the highway has. Wider highway, more cars per cross-section, more bridges that have to be built wider too. The bridges in this picture are the attention machinery, the per-word processing layer, the word to numbers lookup phone book, and the running notebook of past attention values that decoders carry around at answer time. Every one of them scales with the lane count. Pick d_model = 4096 for a 7B-class model, d_model = 8192 for a 70B-class model, and every other width number in the architecture follows.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
d_model is the single most-referenced constant in transformer code. Every config file lists it. Every parameter-counting calculation starts from it. Every scaling-law analysis parameterizes width through it. Knowing what it is and what depends on it is non-negotiable for anyone claiming to understand transformer architecture.
This card defines d_model precisely as the width of the residual stream, walks through the four major architectural quantities that scale with it, and connects them to the parameter-counting and inference-cost consequences at production scale.
What d_model actually means
d_model is the dimensionality of the residual stream, which is the working-memory buffer that flows from block to block in a transformer. At every layer and every sequence position, the model carries a d_model-dimensional vector representing that token's running state.
Other names for the same quantity:
hidden_size(Hugging Face configs).embedding_dim(PyTorch tutorials, especially for input embeddings).n_embd(the original GPT-2 codebase).- Just 'the hidden size' in casual discussion.
It is a deliberate architectural choice, set in the config file before training begins. It does not change layer to layer; the residual stream width is constant throughout the stack (this is structurally important, since residual connections require the input and output of each sublayer to have the same shape).
Typical values in 2026:
- 768 to 1024 for small models (GPT-2 small, BERT-base).
- 4096 for 7B-class LLMs (Llama, Mistral, Qwen, DeepSeek small).
- 8192 for 70B-class LLMs (Llama 3 70B, DeepSeek V3 671B).
- 12288+ for very large models (GPT-3 175B, presumed similar for frontier closed models).
Situations where this technique stops working.
2–4 min · Everything important, quickly.
| Quantity | Formula | Llama 3 70B value |
|---|---|---|
| d_model | (set directly) | 8192 |
| Attention Q/O matrix | d_model x d_model | 8192 x 8192 |
| Attention K/V matrix (GQA 8x) | d_model x d_model/8 | 8192 x 1024 |
| FFN hidden d_ff | 3.5 * d_model | 28672 |
| FFN matrix shape | d_model x d_ff | 8192 x 28672 |
| Per-head attention d_head | d_model / n_heads | 8192 / 64 = 128 |
| Embedding table | vocab_size x d_model | 128256 x 8192 |
| KV cache per token (bf16) | 2 * n_layers * n_kv_heads * d_head * 2 | 320 KB |
Real products, models, and research that use this idea.
- Llama 3 8B: d_model = 4096. d_ff = 14336 (3.5x). vocab = 128256. Embedding table: 525M params. Per-head dim: 128 (32 heads). Block param: ~202M.
- Llama 3 70B: d_model = 8192. d_ff = 28672 (3.5x). vocab = 128256. Embedding table: 1.05B params. Per-head dim: 128 (64 heads). Block param: ~855M.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy is d_head almost universally 128 across modern open-weight LLMs?
FlashAttention's tile size for head dim is 128, so 128 is the highest d_head that fully saturates the kernel. Smaller d_head wastes capacity per head; larger d_head requires a non-trivial kernel rewrite. Once d_head = 128 was confirmed empirically as a quality-respecting choice, the entire field standardized on it. Llama 1/2/3/4, Mistral, Qwen, DeepSeek all use d_head = 128. This is a hardware-driven architectural convergence.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Confusing d_model with the FFN hidden dim or with the per-head attention dim. d_model is the *residual stream* width; the FFN hidden dim is a multiple of it; the per-head dim is d_model divided by the number of heads.
60 second bullets to scan on the way to the call.
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.