Layer Normalization › Key Parameters

Michael BrenndoerferUpdated June 11, 20251 min read
Language AI HandbookAll chapters
Part 15 of 67Transformer Blocks
Chapter 104Layer Normalization › Key Parameters
Reading section 14 of 16 · Key Parameters · 1 minSection 14 of 16 · 1 min

Book contents

Section 14 of 16 · 1 min read

Layer Normalization › Key ParametersOne section · Sections in this chapter14 / 16 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

When using nn.LayerNorm in PyTorch, understanding the key parameters helps you configure it correctly for your architecture:

  • normalized_shape: The shape of the input over which to normalize. For transformers, this is typically the hidden dimension d_model (e.g., 768, 1024). You can also pass a list like [seq_len, d_model] to normalize over multiple dimensions, though normalizing over features only is the standard choice.

  • eps: The epsilon value added to the denominator for numerical stability. Default is 1e-5, which works well for most cases. For mixed-precision (FP16) training, you may need a larger value like 1e-4 to avoid underflow issues when variance is very small.

  • elementwise_affine: Whether to include learnable γ\gamma and β\beta parameters. Default is True. Setting to False removes the learnable parameters, reducing model size slightly but limiting the network's ability to learn optimal feature scales. Some research has found that removing the affine transform causes minimal performance degradation in very large models, suggesting that the normalization itself, not the learnable parameters, is primarily responsible for the stability benefits.