﻿# LayerNorm: computing statistics across features rather than examples

LayerNorm normalizes features within an example rather than estimating batch statistics. A small arithmetic example explains centering, scaling and learned affine parameters.

Author: Retrivium editorial team
Updated: 2026-11-03
Canonical URL: https://retrivium.ai/journal/layernorm-feature-axis-statistics/
Language: en

Normalization is useful to understand as a computation over a declared set of coordinates. LayerNorm obtains its statistics within a case rather than from a batch of different examples. This distinction explains why both the normalization shape and its placement in a model matter.

## Select the feature set before computing statistics

For a common language-model hidden state, LayerNorm can operate across the hidden feature axis independently at each token position. Its mean and variance then describe those selected coordinates, not all users in the batch and not necessarily the entire sequence. Other normalized shapes are possible when explicitly configured. The original Layer Normalization paper motivates normalization within a training case. Reading the selected axes is essential because changing them changes which values influence the normalization applied to any particular coordinate.

## Work through a centered arithmetic example

Take the illustrative feature vector [1, 1, 3, 3]. Its mean is 2, and its population variance is 1. Ignoring the stabilizing epsilon and learned affine transform only for this hand calculation, centering and scaling gives [-1, -1, 1, 1]. The example shows a relative pattern within the selected feature set. It does not assign a semantic meaning to negative coordinates. Adding another unrelated example to the batch does not change this particular calculation when the selected normalization axes remain the same.

## The learned affine transformation restores useful freedom

A normalization layer can include learned per-feature scale and bias after the standardized computation. Those parameters allow the model to adapt the normalized representation rather than be restricted to a fixed output distribution. The epsilon term contributes numerical stabilization when variance is small. Consequently, the teaching calculation without these terms is not the full implementation contract. A practical reference comparison includes the actual affine values, epsilon, data type and variance convention before assessing whether another implementation computes the intended layer.

## Connect local normalization to the surrounding block

LayerNorm’s placement relative to a residual branch changes which representation is standardized. Pre-norm and post-norm architectures can therefore behave differently despite using the same normalization name. RMSNorm makes a related but distinct choice by changing the statistics used. These comparisons become clearer once the feature axis is understood. A small repeatable fixture can first verify the local arithmetic, then place the operation inside the complete block. This builds an explanation from exact input coordinates to architectural behavior instead of treating normalization as a universal automatic improvement.

## Primary research and implementation references

- [Layer Normalization](https://arxiv.org/abs/1607.06450).

- [Root Mean Square Layer Normalization](https://arxiv.org/abs/1910.07467).

- [On Layer Normalization in the Transformer Architecture](https://arxiv.org/abs/2002.04745).

## Related engineering context

[Reproducible inference stacks: preserving a GPU pilot’s result](/journal/software-stack-reproducibility/); [A GPU inference benchmark you can trust](/journal/inference-benchmark-method/).
