Zenaique

Define d_model and name three architecture knobs that scale with it

Flashcard·Easy·4.0 · 0·~30s·Asked atAi4bharatModal LabsOla·Relevant atMistral AI
Attempt it
TL;DR

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.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

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.

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).
The four scaling targets
Why d_model is 'the' width knob
Inference-cost consequence: KV cache memory
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.
QuantityFormulaLlama 3 70B value
d_model(set directly)8192
Attention Q/O matrixd_model x d_model8192 x 8192
Attention K/V matrix (GQA 8x)d_model x d_model/88192 x 1024
FFN hidden d_ff3.5 * d_model28672
FFN matrix shaped_model x d_ff8192 x 28672
Per-head attention d_headd_model / n_heads8192 / 64 = 128
Embedding tablevocab_size x d_model128256 x 8192
KV cache per token (bf16)2 * n_layers * n_kv_heads * d_head * 2320 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.
Sign in to see more production examples.

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?
A

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.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

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.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • d_model = width of the residual stream

  • Attention Q, K, V, O scale with d_model (matrices of size d_model x d_model in full MHA)

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Explain scaled dot product attention.
Short answer·Medium