2018 · decoder-only
GPT (124M)
How a piece of text becomes a guess at the next token
How to read this page
- Start at the bottom: input text → tokens → embeddings.
- Climb the main column through one transformer block (it repeats ×12).
- Red residual arrows are the shortcuts that keep gradients alive.
- After the sketch, read the desk notes — especially why the MLP opens to 4×.
Whole sketch in view — zoom in to read labels
Desk notes
same pad on every sketch
Two jobs inside one block
Attention
Look sideways. Which other tokens should colour this one?
Feed-forward
Look inward. Rethink this token alone — on a wider desk — then write back.
The 4× scratchpad
Same token. Bigger desk for a moment. Then back to the shared width so the residual + still lines up.
arrive (768)
768-d
open wide (3072)
3072-d
return (768)
768-d
GELU does not change the length — it only turns features up or down inside the wide vector. The first Linear creates the 4× room; the last Linear folds useful work back into 768.
Stream rule
The residual stream stays 768-wide on purpose. Widen only inside the MLP; shrink before you add. That is why twelve blocks can stack without reshaping the story.
Choice, not law
4× is a GPT / classic-Transformer habit — more room to compute, paid for in FLOPs. Other families pick different ratios (LLaMA-style FFNs often sit nearer ~2.7×). The pattern that matters is widen → nonlinear → shrink, not the exact number.
Attention mixes the room; the MLP rethinks one seat. Both hand the same 768-d shape back so the red + can keep working.