Count the groups before counting the parameters
shape▲▲△Exact expressions first; four decimal places unless stated otherwise.
STATEMENT
Audit the axes, statistics and parameter shapes of batch and layer normalisation. An output tensor with the expected shape is not sufficient evidence that the intended axes were used.
GIVEN
First a dense matrix of shape . Then a channels-first image tensor of shape . Use learned affine parameters. Compare spatial batch normalisation, layer normalisation over all , and channel-only layer normalisation performed separately at each spatial position.
FIND
The number of groups, entries per group, learned parameters and stored running-statistic scalars. Identify an implementation that silently normalises the wrong axis.
STRATEGY
Statistics have one value per reduction group. Learned affine parameters have one value per specified feature position and need not have the same shape as the statistics. Count mean and variance separately from gamma and beta.
SOLUTION
For the dense matrix:
| Rule | Groups | Entries per group | Gamma and beta | Running mean and variance |
|---|---|---|---|---|
| Batch normalisation | columns | scalars | scalars | |
| Layer normalisation over | rows | scalars | none |
Both return shape . Their identical parameter counts hide different dependencies.
For the image tensor:
| Rule | Reduced axes | Groups | Entries per group | Learned scalars | Running scalars |
|---|---|---|---|---|---|
| Spatial batch normalisation | |||||
| Layer normalisation over | |||||
| Channel-only layer normalisation | at each location |
These layer-normalisation counts use an independent affine parameter for each position of the normalised shape, shared over the non-normalised axes. A deliberately tied affine parameterisation would have different counts.
The broadcast shapes of the spatial batch statistics and affine parameters are . For full-example layer normalisation, the computed statistics have shape , but gamma and beta each have shape . For channel-only layer normalisation, move channels to the last axis, normalise that axis with shape , then restore the original axis order.
Applying a last-axis normalisation of width directly to channels-first data instead computes a mean across each row of pixels. It returns the same overall tensor shape. Nothing about that successful return makes it channel normalisation.
Every entry participates in a constant number of reductions and elementwise operations, so forward and efficient backward arithmetic are . The full dense Jacobian is unnecessary.
Answer
All three image rules return . They have respectively , , and learned scalars, with , , and running-statistic scalars. Their group sizes are , , and .
Check — sanity
Groups multiplied by entries per group must equal the tensor’s entries for each rule. Running-statistic buffers are not learned parameters, and a framework’s bookkeeping counter is separate from the mean and variance counted here.
Where this breaks
“Layer normalisation on an image” does not uniquely specify a reduction or an affine parameterisation. A model may normalise channels, channels and spatial dimensions, or a reshaped token dimension. The API arguments and layout must be read together.
Variation
Change the image to shape . Spatial batch normalisation still has six learned scalars, full-example layer normalisation has , and channel-only layer normalisation still has six. Explain which rule ties its parameter count to the spatial resolution.