Why GPT-2 needs 48 floors to answer, and what happens inside each one
The four pieces of every Transformer layer, explained for people who use the model every day and never opened one.
Landed here from LinkedIn? This is chapter 05 of the course GPT-1 and GPT-2, taken apart. It reads on its own; if you want the beginning, it is chapter 00.
When you send ChatGPT a question, it climbs 96 floors before it becomes an answer. In GPT-2 it was 48. Every floor does the same thing. So why so many? Each floor has two rooms. In the first, the words talk to each other: that is where "it" figures out it refers to the trophy, not the suitcase. In the second, the model consults what it knows about the world: that is where knowledge lives, two thirds of everything it learned. But there is a detail that changes everything. If you stacked only the first room, a hundred floors would be worth exactly the same as one. The math does not allow more than that. What makes 48 floors worth more than one are four small pieces, and one of them is a plain sum. Without that sum, the model cannot even be trained.
The three points
- Each layer has two rooms: attention, where the words look at each other, and the MLP, where knowledge lives. Two thirds of what the model knows sit in the second room, not the first.
- Stacking attention alone gets you nowhere: a hundred layers are worth one. What changes that is a connection that adds the input back to the output, and it is what lets you train 48 layers without the training falling apart.
- GPT-2 moved each layer's "volume knob", the LayerNorm, to before attention. It looks like a detail. It is one of the four decisions that doubled quality over GPT-1.
From the chapter, the beginning
LayerNorm, GELU, MLP and the residual connection — the four pieces that let you stack 48 layers without training blowing up.
Attention solves the transport of information: it moves content from one position to another. But notice what it is, mathematically: a weighted average of V vectors. That is, a linear combination.
And there lies the problem. Stacking linear operations gains nothing: the composition of two linear transformations is another linear transformation. A hundred layers of pure attention would have exactly the same expressiveness as a single layer. You would gain nothing by stacking.
We need non-linearity. And we need a place where the model can process the information attention brought in, instead of merely transporting it. That place is the MLP.
What the chapter covers · 6 sections · 10 min
- What attention is missing
- Piece 1 — the MLP (where the knowledge lives)
- Piece 2 — the residual connection (the most important one)
- Piece 3 — LayerNorm (and the change from GPT-1 to GPT-2)
- The assembled block
- In the lab
All chapters of the course · GPT-1 and GPT-2, taken apart
- 00 · The seven fossils: why GPT-1, GPT-2 and RoBERTa are a historical cross-section, not a list
- Glossary · Course glossary: what token, layer and model mean in AI, and in the rest of IT
- 01 · Why GPT-2 sees neither letters nor words, and what that costs in Portuguese
- 02 · Embeddings: from a meaningless integer to a vector that knows king and queen are related
- 03 · Attention: the single operation that replaced twenty years of recurrent networks
- 04 · Twelve heads instead of one, and the single line of code that separates GPT from RoBERTa
- 05 · Why GPT-2 needs 48 floors to answer, and what happens inside each one
- 06 · What scale really buys: from 124 million to 1.5 billion, measured
- 07 · Temperature, top-k and top-p: the decision that changes the text more than switching models
- 08 · Perplexity: the one number that says what the model learned, without anecdotes
- 09 · GPT-1 to GPT-2: same size, half the perplexity. Four decisions explain it
- 10 · RoBERTa: when the advance is training better what already existed
- 11 · Encoder vs decoder: one line of code and every consequence that descends from it
- 12 · The detector: how a language model becomes a classifier, and why this one should decide nothing
- 13 · Reading GPT-2's original code: 174 lines against everything you learned
- 14 · Serving models: from function call to HTTP server, and what production does on top
- 15 · The lab guide: every command, every script, and everything that was measured
- 16 · The ceiling of this path: LeCun's argument, read from inside GPT-2

Writes the GPT-2 course and runs the Antivision experiment, measuring every run before publishing the number. The LinkedIn posts start here and end in the chapters.
Follow on LinkedIn →