Part IX — Deep Learning Regularization, Normalization & Training Dynamics · Chapter 4

Layer normalization & Group normalization

Hook

Batch normalization needs a batch — it measures a mean and variance across examples. What happens the moment your batch has one example in it, or your model processes one sequence position at a time?

Intuition

Same idea as batch norm — force a healthy mean and variance — but measured across a completely different axis: not across examples in a batch, but across this one example's own channels. No batch required, no matter how many examples you're processing at once.

Formalize

Split a layer's output channels into groups, then normalize each group independently using only that group's own statistics:

h^i=hiμgσg2+ϵ,igroup g\hat h_i = \frac{h_i - \mu_g}{\sqrt{\sigma_g^2 + \epsilon}}, \quad i \in \text{group } g
  • hih_i — channel ii's raw output, for this one example.
  • μg\mu_g, σg2\sigma_g^2 — the mean and variance of only the channels in group gg, for this one example.
  • h^i\hat h_i — channel ii after normalization.
  1. One group (LayerNorm)

    Every channel lands in the same group — μg\mu_g and σg2\sigma_g^2 are the mean and variance across all of this example's channels at once.

  2. Several groups (GroupNorm)

    Channels split into smaller groups, each normalized against only its own members — a middle ground between one giant group and every channel alone.

  3. One channel per group (InstanceNorm, the degenerate limit)

    Each group has exactly one member, so that member's "mean" is itself — every value normalizes to exactly 00, which is why this extreme is rarely useful on its own.

Play

Slide from one group up to six. The channels get shuffled into smaller and smaller clusters, each computing its own mean and variance — completely independent of whatever else is in the batch, or whether there's a batch at all.

Worked example
  1. Six raw activations

    [2,1,0.5,3,2.5,1][2, -1, 0.5, 3, -2.5, 1]: mean =(21+0.5+32.5+1)/6=3/6=0.5=(2-1+0.5+3-2.5+1)/6=3/6=0.5. Squared deviations from that mean:

    • 1.52=2.251.5^2=2.25
    • (1.5)2=2.25(-1.5)^2=2.25
    • 02=00^2=0
    • 2.52=6.252.5^2=6.25
    • (3)2=9(-3)^2=9
    • 0.52=0.250.5^2=0.25

    These sum to 2020, so variance =20/63.33=20/6\approx3.33.

  2. One group (LayerNorm)

    Dividing by σ=3.331.826\sigma=\sqrt{3.33}\approx1.826 after subtracting the mean 0.50.5 from each value:

    • (20.5)/1.8260.82(2-0.5)/1.826\approx0.82
    • (10.5)/1.8260.82(-1-0.5)/1.826\approx-0.82
    • (0.50.5)/1.826=0(0.5-0.5)/1.826=0
    • (30.5)/1.8261.37(3-0.5)/1.826\approx1.37
    • (2.50.5)/1.8261.64(-2.5-0.5)/1.826\approx-1.64
    • (10.5)/1.8260.27(1-0.5)/1.826\approx0.27

    Averaging these six gives mean 0\approx0 and variance 1\approx1 for the whole vector — the same guarantee batch norm gives, just measured across channels instead of across a batch.

  3. Three groups of two

    Splitting into consecutive pairs (2,1)(2,-1), (0.5,3)(0.5,3), (2.5,1)(-2.5,1) — each pair's two values happen to sit equally far from their own mean:

    • (2,1)(2,-1): mean 0.50.5, half-spread 1.51.5, normalizing to 1.5/1.5=11.5/1.5=1 and 1.5/1.5=1-1.5/1.5=-1
    • (0.5,3)(0.5,3): mean 1.751.75, half-spread 1.251.25, normalizing to 1-1 and 11
    • (2.5,1)(-2.5,1): mean 0.75-0.75, half-spread 1.751.75, normalizing to 1-1 and 11

    Every one of the six outputs lands at exactly +1+1 or 1-1, regardless of how spread out the original six numbers were.

Checkpoint

Pick the group size where every one of the 6 normalized values comes out at exactly +1 or -1.

Pick a group size to try it
Summary
h^i=hiμgσg2+ϵ,igroup g\hat h_i = \frac{h_i - \mu_g}{\sqrt{\sigma_g^2 + \epsilon}}, \quad i \in \text{group } g

Batch norm normalizes across examples; layer and group norm normalize across channels, for one example at a time. That single change in axis is what makes them usable with a batch size of 1, inside a recurrent step, or across variable-length sequences — exactly the settings where batch norm's batch-level statistics either don't exist or don't mean anything stable. The next chapter takes this same idea and strips it down even further, dropping the mean-centering step entirely.