Pre-LN and Post-LN are two conventions for where to place Layer Normalization relative to the residual connection in each layer of a Transformer.
- Post-LN: Normalizes after adding the residual to the output of the sublayer (attention or feed-forward). This is the arrangement of the original Transformer and BERT.
- Pre-LN: Normalizes before the input enters the sublayer, and adds the residual unchanged. One more Layer Normalization is placed after the last layer.
The only difference is the position of the normalization, but it greatly changes how easy the model is to train. The paper by Xiong et al. (2020) showed, both theoretically and experimentally, that in Post-LN the gradients of layers near the output are large at the start of training, so training breaks down without warmup that gradually raises the learning rate, whereas in Pre-LN the gradients are uniform across layers, so it can train from a large learning rate without warmup, and trains faster.
The figure at the top of the article shows one layer of Post-LN (left) and Pre-LN (right). Both flow from bottom to top, and the blue lines are residual connections. In Post-LN, Layer Normalization sits on the main residual path, so the values on the main path are normalized each time they pass through a layer. In Pre-LN, Layer Normalization sits inside the branch to the sublayer, and the main path passes straight through with additions only.

