12/29
Part 2 of 5 · The blockLearn and do
Why the norm goes before each step
The original transformer put LayerNorm after each add. GPT-2 moved it to the start of each step, and that's the version you write. Switch the picture between the two:
- Norm after (original):
x = LayerNorm(x + step(x)) - Norm before (GPT-2):
x = x + step(LayerNorm(x))
The stream: each token's C numbers, (B, T, C). It runs through every block and is never replaced. Each step only adds to it.
The difference is in what happens to the stream.
- Norm before: the stream is a plain sum. Each block adds its changes, and nothing else touches the stream. During training, the gradient from the loss flows straight back along that sum to every block, however deep the model is.
- Norm after: a LayerNorm sits on the stream itself after every step, so the gradient must pass through all of them on the way back. Research on this (Xiong et al., 2020) showed that this makes the gradients near the output large at the start of training. That's why those models needed a slow warm-up of the learning rate. With the norm before each step, they trained without it.
Norm before each step: x = x + step(LayerNorm(x)). If both steps output 0, what does the block do to the stream?
Pick an answer above to see the rest