Gemma 2
Thread (18 posts)
Thinking Summary
**Explaining pre-norm and post-norm** The user is asking about the 'Pre-norm' and 'Post-norm' columns in Table 1. In the context of transformer layers, particularly with Gemma 2, these terms indicate where normalization occurs in relation to the residual connection within each transformer block. Pre-norm applies RMSNorm before the sub-layer, while post-norm applies it after. Gemma 2 utilizes both methods by applying RMSNorm to both the input and output of each sub-layer, hence the 'yes' under both columns indicates the use of dual normalization. **Discussing normalization advantages** I'm looking to explain the benefits of pre-norm and post-norm in transformer networks. Pre-norm enhances training stability, while post-norm can improve inference calibration and performance. Using a dual normalization approach, like RMSNorm, further stabilizes training by managing both inputs and outputs. In a transformer block, pre-norm involves applying normalization to the input before the sub-layer, while post-norm applies it after adding the residual. Gemma 2 employs this "Sandwich" approach, combining both methods effectively.
In a Transformer block you have three main operations, executed in this order:
- The residual input coming from the previous layer.
- The sublayer (either self-attention or the feed-forward network, FFN).
- The residual addition that adds the sublayer output back to .
Where you place the normalisation step(s) relative to those three operations is what the paper’s Table 1 is calling “pre-norm” and “post-norm”.
• Pre-norm (a “yes” in the table) means:
i.e. the input is normalised before it is fed into the sublayer.
• Post-norm (also “yes”) means:
i.e. after the residual addition the result is normalised again.
Gemma 2 therefore uses both: every attention or FFN sub-block is wrapped in a dual / sandwich normalisation scheme
x
│
├─► RMSNorm ─► Sublayer ─► + x ─► RMSNorm
│ │
└────────────────────────────────┘
and it uses RMSNorm instead of LayerNorm for all of these normalisation steps.
Why both?
• Pre-norm is known to stabilise very deep Transformers and makes optimisation easier.
• Post-norm (the extra “sandwich” layer) helps keep the magnitude of activations bounded, improving training stability, calibration and in some cases final accuracy (ideas similar to DeepNorm, NormFormer, and Sandwich-LayerNorm).
So the two columns simply indicate that Gemma 2 applies RMSNorm both before and after each Transformer sub-layer.