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.
Detailed answer & concept explanation~5 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.
3 min: define residual stream width, name the four scaling targets (attention, FFN, embedding, per-head dim), give Llama 3 70B as a concrete example, mention KV cache as the inference-time consequence.
| 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.
- Mistral 7B: d_model = 4096. d_ff = 14336. vocab = 32000 (smaller than Llama 3). Per-head dim: 128 (32 heads).
- GPT-2 small: d_model = 768. d_ff = 3072 (4x). vocab = 50257. Per-head dim: 64 (12 heads). Block param: ~7M.
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?
QHow does scaling d_model interact with scaling depth (n_layers) at fixed compute budget?
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 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.
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.