C.W.K.
Stream
Lesson 06 of 12 · published

Depth vs Width: Where to Spend Parameters

~10 min · depth, width, scaling

Level 0Token
0 XP0/94 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

Given a fixed parameter budget, should you stack more layers (deeper) or widen each layer (larger d_model)? Empirically, both matter, but the right ratio is non-obvious.

ModelLayersd_modelParamsLayers / d_model
Transformer Base651265M1/85
GPT-212768117M1/64
GPT-39612,288175B1/128
Llama 3 (8B)324,0968B1/128
Llama 3.3 (70B)808,19270B1/102
DeepSeek-V361671B (37B active, MoE)

The pattern: as models scale, depth and width grow together. The d_head per layer stays around 64-128, and roughly d_model ≈ 64-128 × n_layers across most modern architectures. This isn't a theorem but a strong empirical regularity.

Why both matter: deeper models can express more compositional functions (each layer composes its predecessors). Wider models have richer per-token representations. Practical evidence suggests depth is somewhat more important for language understanding, but with diminishing returns past ~80 layers — at which point widening or sparsifying (MoE) is more productive than going deeper still.

Code

Param budget split·python
def transformer_total(vocab, d, n_layers, d_ff_mul=4):
    embed = vocab * d
    attn  = 4 * d * d * n_layers
    ffn   = 2 * d * (d_ff_mul * d) * n_layers
    return embed + attn + ffn

# Same total budget, different shapes:
budget = 8_000_000_000
# Deep+narrow: 64 layers, d_model=2048
deep   = transformer_total(128_000, 2048, 64)
# Shallow+wide: 16 layers, d_model=4096
wide   = transformer_total(128_000, 4096, 16)
print(deep/1e9, wide/1e9)
# Both ~8B, but train very differently.

External links

Exercise

Train three small Transformers with identical total parameters but different shapes: (32 layers × d=64), (16 × 128), (8 × 256). Use the same data and tokens. Plot final loss for each. Where does the deep+narrow shape win? Where does the shallow+wide shape win?

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.