Layer normalization does the same rescaling as batch normalization, along a different axis.
It normalises across the features of one example, using only that example.
No other row in the batch is involved at any point.
That single difference is what makes it suit sequences and small batches.
It works identically with a batch size of one, which batch normalization cannot manage.
It behaves the same in training and inference, so there are no running averages to drift.
Sequences of different lengths cause it no trouble, since positions are handled independently.
Like batch normalization it learns a scale and a shift to restore whatever it removed.
It is applied at every block of a transformer, usually twice.
Pre-norm places it before the attention and feed-forward parts, which trains more stably.
Post-norm, in the original paper, places it after and needs careful warmup to survive.
RMSNorm is a lighter variant that divides by the root mean square and skips the mean.
It is slightly cheaper and works about as well, so large recent models tend to use it.
Choose layer normalization for sequence models and batch normalization for convolutional vision models.
Both exist to keep the numbers flowing through a deep network within a sane range.