Normalization in Neural Networks
Batch normalization normalizes across the batch dimension, pooling values across different inputs.
The Question Hidden Inside Normalization
Suppose you already know batch normalization, the traditional normalization method used in many neural networks. A natural question follows: if you want to normalize the activations inside a large language model, is there another option, and how does it differ? The answer depends on one decision that is easy to overlook. Normalizing always involves choosing a set of values to summarize together.
What do you think happens?
Before reading on: if the set of values being summarized changed, what would change about the normalization result?
Reveal answer
The statistics computed from those values change, so every value that gets normalized using them also changes.
Normalization works by summarizing a group of values and then rescaling values relative to that summary. Change the group and you change the summary, which changes the output. This is the single idea the rest of the article builds on.
Reading a Training Batch as a Grid
Think of a training step as a grid. Each row is one input from the batch, and each column is one feature of that input. Normalization needs statistics, and the direction in which you gather those statistics is the whole difference between the two methods. The grid below shows three inputs, each with three features, so you can see the two directions of gathering side by side.
Each cell holds one activation value. Each column is a feature, and each row is an input. Batch normalization and layer normalization differ only in which of these cells they treat as belonging to the same group when they compute their statistics.
Two Directions for Gathering Statistics
The source describes the two methods as moving in opposite directions across this grid. Each method has its own pooling pattern, and that pattern determines what the statistics depend on.
Why Batch Size Changes the Answer
The practical pressure behind this comparison is resources. LLMs often require significant computational resources, and the available hardware and the specific use case can dictate how large a batch you are able to use, both during training and during inference. When the batch is limited, the set of values that batch normalization pools together is limited too. A method whose behavior depends on how many inputs are processed together will therefore behave differently when the batch changes.
Layer normalization avoids this dependence. Because it normalizes each input independently of the batch size, the behavior for one input does not depend on which other inputs are sitting beside it. The source identifies this as offering more flexibility and stability in scenarios where resources are constrained, and it is particularly useful for distributed training or when models are deployed in environments with limited resources.
Choosing a Method for Your Situation
Given an input layout and a batch situation, the choice follows from which direction of gathering suits the constraint. The flowchart below captures the decision the source points toward: when the batch is limited, constrained, or spread across devices, the method that works within each input is the safer choice.
Applying the choice to two situations
Situation A: a training run where each device holds only a small slice of the batch. Situation B: a run on one machine where the batch is large and the same features are compared across many inputs. Which method fits each?
- 1Identify the constraint in Situation A
Each device holds only a small slice of the batch, so batch statistics would have to be built from a small, split set of inputs. The source notes that layer norm can avoid the step of sharing batch statistics across devices.
- 2Choose for Situation A
Layer normalization fits, because each input's statistics come from its own features and no cross-device sharing is needed.
- 3Identify the situation in Situation B
The batch is large and available on one machine, so the batch-direction statistics are well defined and batch normalization is an available option.
- 4Choose for Situation B
Batch normalization fits, since it pools each feature across the inputs in the batch.
Constrained or distributed training points toward layer normalization. A large batch on one machine leaves batch normalization as a natural choice.
Common mistake Assuming layer normalization pools values across the batch
What it looks likeComputing the statistics for feature A from x1A, x2A, and x3A and calling it layer normalization.
Why it failsThat is the column direction, which is batch normalization. Layer normalization works along the row.
Do this insteadFor layer normalization, gather the statistics from one input's features only.
Common mistake Thinking the choice of method does not depend on the batch
What it looks likeUsing batch normalization on a device that holds only one or two inputs per step.
Why it failsBatch normalization's behavior depends on how many inputs are processed together, so a small or split batch changes its results.
Do this insteadWhen the batch is limited or spread across devices, consider the method whose statistics do not depend on the batch.
Where GELU Fits in the Transformer Block
Normalization is only one part of the story in a transformer block. The source moves on to a small neural network submodule that is used as part of the transformer block in LLMs, called the feed forward submodule. Its first step is implementing the GELU activation function, which the source describes as playing a crucial role in this submodule.
Practice Choosing the Right Direction
A training run uses a batch of two inputs spread across two devices, one input per device. Which normalization method avoids needing batch statistics shared across the devices, and along which dimension does it gather its statistics?
Hints
- Ask which method's statistics depend on the other inputs in the batch.
- Layer normalization gathers its statistics along one input's own features, which means it looks along the row.
Summary of Normalization Directions
- 1Normalizing always involves choosing a set of values to summarize together, and that choice determines the result.
- 2Batch normalization pools values across the batch dimension, down each feature column across different inputs.
- 3Layer normalization pools values across the feature dimension, along each input's row, so it does not depend on batch size.
- 4Layer normalization offers more flexibility and stability when resources are constrained or training is distributed.
- 5GELU is the activation function that plays a crucial role in the feed forward submodule of a transformer block in LLMs, separate from the normalization step.
At a glance
- Normalizing always involves choosing a set of values to summarize together, and that choice determines the result.
- Batch normalization pools values across the batch, while layer normalization pools values across the features of each input.
- Because layer normalization does not depend on batch size, it offers more flexibility and stability for constrained or distributed training.
- GELU is the activation function that plays a crucial role in the feed forward submodule of a transformer block in LLMs.