Search

Search papers and lessons

Weight Normalization

Level 3 · 11 min read

Weight normalization writes each neuron's weight vector as a length times a direction, so training changes the direction and the length separately, which makes gradient steps better behaved.

On this page

  • Colour = topic mix
  • Calculus
  • Discrete math
  • Linear algebra
  • Neural network basics
  • ReadReady to readNot yet

TL;DR

Weight normalization changes how a neuron's weights are stored. Instead of learning the weight vector w\mathbf{w} directly, the network learns a direction v\mathbf{v} and a scalar length gg, and uses w=g v/∥v∥\mathbf{w} = g\,\mathbf{v}/\lVert\mathbf{v}\rVert. Training then adjusts the size of the weights and their direction separately, and the gradient steps on the direction stay well scaled. The method adds only one extra number per neuron.

Builds on: Vector Norm, Chain Rule, Gradient · Leads to: the 2016 weight normalization paper

Where it's used

Training small and medium convolutional networks. Salimans and Kingma (2016) reported faster convergence on image classification and generative models, such as deep convolutional networks trained on CIFAR-10, with the method applied to each layer's weights. It is most useful in research code where batch statistics are awkward.

Reinforcement learning and generative models. Because weight normalization does not use statistics from a batch, it works when batches are small, when examples in a batch are correlated, or when the batch is not the right unit, as in some reinforcement learning, generative and sequential models. Those settings are where Batch Normalization is least reliable.

Built into deep-learning frameworks. Libraries such as PyTorch provide a weight-norm wrapper that applies the reparameterization to a layer's weight, so a practitioner can add it with one line. It is a tool for changing how a layer is parametrised, not a separate block in the network.

How it works

Take a single neuron with a 2-number weight vector and no bias. Its output for an input x\mathbf{x} is w⋅x\mathbf{w}\cdot\mathbf{x}. Start with the learned direction v=(3,4)\mathbf{v} = (3, 4) and the learned length g=2g = 2.

  1. Compute the length of v\mathbf{v}: ∥v∥=32+42=5\lVert\mathbf{v}\rVert = \sqrt{3^2 + 4^2} = 5.
  2. Divide v\mathbf{v} by its length to get a unit direction: v/5=(0.6,0.8)\mathbf{v}/5 = (0.6, 0.8). Check: 0.62+0.82=10.6^2 + 0.8^2 = 1.
  3. Multiply the unit direction by the learned length: w=2×(0.6,0.8)=(1.2,1.6)\mathbf{w} = 2 \times (0.6, 0.8) = (1.2, 1.6).
  4. Check the length of the actual weight: 1.22+1.62=4=2\sqrt{1.2^2 + 1.6^2} = \sqrt{4} = 2. The weight's length is exactly gg, whatever v\mathbf{v} was.
  5. Use the weight as usual. For input x=(1,0)\mathbf{x} = (1, 0) the output is 1.21.2.
  6. During training, the gradient of the loss is taken with respect to gg and v\mathbf{v}, not w\mathbf{w}. Each gradient step moves gg to change the length, and moves v\mathbf{v} to change the direction. Because a step on v\mathbf{v} changes its direction without changing its length much, the length of the neuron's weights is controlled by gg alone.

The picture is simple: one knob sets how big the weights are, and the other sets which way they point.

flowchart LR
    G[Learned length g] --> W[Weight w = g times v over norm v]
    V[Learned direction v] --> W
    W --> O[Output w dot x]
    O --> L[Loss]
    L -->|gradient| G
    L -->|gradient| V

The diagram shows that the loss feeds gradients into both learned quantities, and the weight is rebuilt from them at every forward pass.

The math

Write v∈Rn\mathbf{v} \in \mathbb{R}^n for the direction parameter, g∈Rg \in \mathbb{R} for the length parameter and w∈Rn\mathbf{w} \in \mathbb{R}^n for the effective weight vector of one neuron.

Step 1 in symbols: the reparameterization

The effective weight is

w=g∥v∥ v,\mathbf{w} = \frac{g}{\lVert\mathbf{v}\rVert}\,\mathbf{v},

where ∥v∥=∑ivi2\lVert\mathbf{v}\rVert = \sqrt{\sum_i v_i^2} is the Euclidean length defined in Vector Norm. The length of w\mathbf{w} is ∥w∥=∣g∣\lVert\mathbf{w}\rVert = |g|, as the walkthrough checked.

Step 2 in symbols: the direction is a unit vector

Let v^=v/∥v∥\hat{\mathbf{v}} = \mathbf{v}/\lVert\mathbf{v}\rVert. Then ∥v^∥=1\lVert\hat{\mathbf{v}}\rVert = 1, and w=gv^\mathbf{w} = g\hat{\mathbf{v}}. The scale of v\mathbf{v} cancels: if you multiply v\mathbf{v} by any positive number cc, v^\hat{\mathbf{v}} does not change. This is why the effective weights are unchanged by a rescaling of v\mathbf{v}.

Step 3 in symbols: the gradients

Let LL be the loss, and write u=∂L/∂w\mathbf{u} = \partial L/\partial \mathbf{w} for the gradient with respect to the effective weights, computed as usual by Backpropagation, which applies the Chain Rule. Then the gradient for the length is the dot product of u\mathbf{u} and v\mathbf{v}, divided by the length of v\mathbf{v}:

∂L∂g=u⋅v∥v∥,\frac{\partial L}{\partial g} = \frac{\mathbf{u}\cdot\mathbf{v}}{\lVert\mathbf{v}\rVert},

and the gradient for the direction parameter is

∂L∂v=g∥v∥(u−(v^⋅u) v^).\frac{\partial L}{\partial \mathbf{v}} = \frac{g}{\lVert\mathbf{v}\rVert}\left(\mathbf{u} - (\hat{\mathbf{v}}\cdot\mathbf{u})\,\hat{\mathbf{v}}\right).

The second expression subtracts from u\mathbf{u} its component along v^\hat{\mathbf{v}}. Thus the gradient on v\mathbf{v} is perpendicular to v\mathbf{v}. A small step along it changes the direction but barely changes the length of v\mathbf{v}, to first order. This is the mechanism behind the claim in the walkthrough.

Step 4 in symbols: the training step

Gradient descent (see Gradient Descent, or its stochastic version on minibatches) updates both parameters with the same learning rate η\eta:

g←g−η ∂L∂g,v←v−η ∂L∂v.g \leftarrow g - \eta\,\frac{\partial L}{\partial g}, \qquad \mathbf{v} \leftarrow \mathbf{v} - \eta\,\frac{\partial L}{\partial \mathbf{v}}.

Each step changes gg by a scalar and changes v\mathbf{v} in a direction orthogonal to itself.

Worked examples

Example
Example 1: check that the length equals g (tiny)

Take v=(3,4)\mathbf{v} = (3, 4) and g=2g = 2.

  1. The length of v\mathbf{v} is 9+16=25=5\sqrt{9 + 16} = \sqrt{25} = 5.
  2. The scale factor is g/∥v∥=2/5=0.4g / \lVert\mathbf{v}\rVert = 2/5 = 0.4.
  3. The weight is w=0.4×(3,4)=(1.2,1.6)\mathbf{w} = 0.4 \times (3, 4) = (1.2, 1.6).
  4. The length of the weight is 1.44+2.56=4=2\sqrt{1.44 + 2.56} = \sqrt{4} = 2, which equals gg.
  5. Interpret. The direction of w\mathbf{w} is the direction of v\mathbf{v}, and its length was set by gg rather than by the size of v\mathbf{v}.
Example
Example 2: one gradient step (standard)

Use the same v=(3,4)\mathbf{v} = (3, 4) and g=2g = 2. Suppose the loss gradient with respect to the effective weight is u=(1,0)\mathbf{u} = (1, 0). Find the gradients with respect to gg and v\mathbf{v}, then take one step with η=0.1\eta = 0.1.

  1. The unit direction is v^=(0.6,0.8)\hat{\mathbf{v}} = (0.6, 0.8).
  2. The gradient for gg is u⋅v/∥v∥=(1×3+0×4)/5=0.6\mathbf{u}\cdot\mathbf{v}/\lVert\mathbf{v}\rVert = (1 \times 3 + 0 \times 4)/5 = 0.6.
  3. The component of u\mathbf{u} along v^\hat{\mathbf{v}} is v^⋅u=0.6\hat{\mathbf{v}}\cdot\mathbf{u} = 0.6. Subtracting 0.6 v^=(0.36,0.48)0.6\,\hat{\mathbf{v}} = (0.36, 0.48) from u\mathbf{u} gives (0.64,−0.48)(0.64, -0.48).
  4. Multiply by g/∥v∥=2/5=0.4g/\lVert\mathbf{v}\rVert = 2/5 = 0.4: the gradient for v\mathbf{v} is (0.256,−0.192)(0.256, -0.192).
  5. Check orthogonality: 0.256×3+(−0.192)×4=0.768−0.768=00.256 \times 3 + (-0.192) \times 4 = 0.768 - 0.768 = 0. The gradient is perpendicular to v\mathbf{v}.
  6. Update: g←2−0.1×0.6=1.94g \leftarrow 2 - 0.1 \times 0.6 = 1.94. And v←(3,4)−0.1×(0.256,−0.192)=(2.9744,4.0192)\mathbf{v} \leftarrow (3, 4) - 0.1 \times (0.256, -0.192) = (2.9744, 4.0192).
  7. The new squared length of v\mathbf{v} is 2.97442+4.01922=25.0010242.9744^2 + 4.0192^2 = 25.001024, so the length is 25.001024≈5.0001\sqrt{25.001024} \approx 5.0001. The squared length grew by η2∥gradient∥2=0.01×0.1024=0.001024\eta^2 \lVert\text{gradient}\rVert^2 = 0.01 \times 0.1024 = 0.001024, a tiny change.
  8. Interpret. The step turned v\mathbf{v} slightly and shortened the length gg. The size of v\mathbf{v} barely changed, so the next forward pass depends on gg far more than on v\mathbf{v}'s length.
Example
Example 3: scale invariance in a trained unit (realistic)

A unit has three inputs. Its direction is v=(1,−2,2)\mathbf{v} = (1, -2, 2) and its length is g=1.5g = 1.5. Take an input x=(2,1,1)\mathbf{x} = (2, 1, 1).

  1. The length of v\mathbf{v} is 1+4+4=3\sqrt{1 + 4 + 4} = 3.
  2. The weight is w=(1.5/3)(1,−2,2)=(0.5,−1,1)\mathbf{w} = (1.5/3)(1, -2, 2) = (0.5, -1, 1).
  3. The output is w⋅x=0.5×2+(−1)×1+1×1=1−1+1=1\mathbf{w}\cdot\mathbf{x} = 0.5 \times 2 + (-1) \times 1 + 1 \times 1 = 1 - 1 + 1 = 1.
  4. Suppose a later update makes v\mathbf{v} ten times larger, v=(10,−20,20)\mathbf{v} = (10, -20, 20), and leaves g=1.5g = 1.5 unchanged. The length of v\mathbf{v} is now 3030, and w=(1.5/30)(10,−20,20)=(0.5,−1,1)\mathbf{w} = (1.5/30)(10, -20, 20) = (0.5, -1, 1).
  5. The weight, and so the output 11, is unchanged.
  6. Interpret. Growing the raw parameters did not change what the unit computes, so the optimizer cannot inflate the weights simply by taking large steps.

Try it: A unit has v=(1,−2,2)\mathbf{v} = (1, -2, 2) and g=3g = 3, and the same input x=(2,1,1)\mathbf{x} = (2, 1, 1). What is the output, as a number?

Answer: The length of v\mathbf{v} is 33, so w=(3/3)(1,−2,2)=(1,−2,2)\mathbf{w} = (3/3)(1, -2, 2) = (1, -2, 2). The output is 1×2+(−2)×1+2×1=21 \times 2 + (-2) \times 1 + 2 \times 1 = 2. Doubling gg from 1.51.5 to 33 doubled the output from 11 to 22, because the output is linear in gg.

Common mistakes and tradeoffs

Mistake: "Weight normalization normalises the activations." It is tempting to think it works like Batch Normalization, which rescales the outputs of a layer. In fact it rescales the weights, not the activations. It does not compute any statistics over the data, so it does not fix shifts in the activation distribution in the same way.

Mistake: "It removes the need for a learning rate." It is tempting to think the length and direction parameters adjust themselves. In fact the learning rate still matters, and a poor choice can still destabilise training.

Mistake: "The stored parameters are just the old weights under a new name." It is tempting to think the parameters are just a new name for the old ones. In fact the stored parameters are gg and v\mathbf{v}, and the gradients flow through the division by ∥v∥\lVert\mathbf{v}\rVert, which is why the update to v\mathbf{v} is perpendicular to v\mathbf{v}.

When to use it. Use weight normalization when batch statistics are unavailable or unreliable, such as with very small batches, or when you want a cheap change that does not depend on the batch at all. It adds only one parameter per neuron.

When not to use it. Avoid relying on it as the only normalisation in a network whose activations drift a lot, because it does not control activation scale. Layer-style normalisation or batch normalisation may handle that better.

Alternatives. Batch Normalization normalises activations using batch statistics, and is the usual choice when batches are large. Layer normalisation normalises over features of one example. Both act on activations, so they address a different issue from weight normalization.

History

By the mid-2010s, batch normalization had shown that normalising the signals inside a deep network could speed up training, but it depended on batch statistics, which made it awkward for small batches and some sequential models. In 2016 Tim Salimans and Diederik Kingma asked whether the weights themselves could be normalised instead. Their answer was to reparameterise each weight vector as a length and a direction, and to show that the gradients behave well in that form.

The paper showed faster training on several image and generative benchmarks, and it was adopted in research codebases, where it was simple to add. It did not replace batch normalization in most large-scale vision work, but it remains a standard example of reparameterising a model to make optimisation easier.

Recap

  • A weight vector is rebuilt as a learned length gg times the unit vector in the learned direction v\mathbf{v}.
  • The length of the effective weight is exactly gg, and rescaling v\mathbf{v} leaves the weight unchanged.
  • The gradient on v\mathbf{v} is perpendicular to v\mathbf{v}, so direction changes do not inflate the length.
  • The method uses no batch statistics, which is its main practical advantage.
  • It normalises weights, not activations, so it is a different tool from batch normalization.

What to read next: Batch Normalization shows the activation-based alternative, and Reparameterization Trick shows another use of rewriting a parameter to make gradients usable.

Check yourself

QuestionRecall: what are the two learned quantities in weight normalization, and what does each control?Show answer

The learned quantities are the direction parameter v\mathbf{v} and the scalar length gg. The effective weight is g v/∥v∥g\,\mathbf{v}/\lVert\mathbf{v}\rVert, so v\mathbf{v} controls which way the weight points and gg controls its length.

QuestionComputation: a neuron has v=(6,8)\mathbf{v} = (6, 8) and g=5g = 5. What is its effective weight w\mathbf{w}, and what is its length?Show answer

The length of v\mathbf{v} is 36+64=10\sqrt{36 + 64} = 10. The weight is (5/10)(6,8)=(3,4)(5/10)(6, 8) = (3, 4). Its length is 9+16=5\sqrt{9 + 16} = 5, which equals gg.

QuestionWhy: why is the gradient with respect to v\mathbf{v} perpendicular to v\mathbf{v}, and what does that mean for training?Show answer

The gradient removes from u\mathbf{u} its component along v^\hat{\mathbf{v}}, so what remains is orthogonal to v\mathbf{v}. A small step perpendicular to v\mathbf{v} changes its direction but adds only a second-order change to its length. So the size of the weight is controlled by gg, and gradient steps on v\mathbf{v} mostly rotate it.

QuestionApplied: you train a small recurrent model whose batches contain only 4 correlated sequences, and batch normalization gives noisy results. Would weight normalization be a sensible replacement, and what is one thing it would not fix?Show answer

It is a sensible choice, because it does not use batch statistics, so the batch size and the correlation between sequences do not affect it. It would not fix activations that drift in scale or shift across time, because it normalises the weights, not the activations. A layer-level normalisation of the activations would be needed for that.

Sources