Search

Search papers and lessons

Weight Normalization: A Simple Reparameterization to Accelerate Training

Tim Salimans, Diederik P. Kingma · 2016

Salimans and Kingma (2016) split each neuron's weight vector into a length and a direction and train those two parts, which speeds up gradient descent without tying examples in a batch together.

On this page

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

TL;DR

Salimans and Kingma (2016) propose weight normalization. Each neuron's weight vector is written as a length times a direction, and the network trains those two parts instead of the raw weights. The paper shows that this makes gradient descent converge faster on image classification, generative modelling and reinforcement learning, at almost no extra cost, and without the cross-example coupling that batch normalization introduces.

Builds on: Weight Normalization, Batch Normalization, Gradient Descent · Leads to: Deep Q-Network and Variational Autoencoder, two of the settings the paper tests.

Why it mattered

The idea became a standard tool in research code, and modern deep-learning frameworks ship a weight-norm wrapper. The paper's own test cases are a deep Q-network for games and a variational autoencoder for generative modelling, two settings where batch statistics were a poor fit. Its practical appeal is that it is one line per layer and adds one scalar per neuron, so people reach for it when batch statistics are awkward: recurrent networks, small or correlated batches, and reinforcement learning where batches come from a changing stream of experience.

The paper also made a conceptual point that outlived the method. The way a model is parameterized changes how hard it is to optimize, even when the set of functions the model can represent is exactly the same. That is the "reparameterization" in the title.

The problem

Training a deep network with Stochastic Gradient Descent works well when the loss surface is well-behaved. The speed of gradient descent depends on how the loss curves in different directions, a property captured by the Hessian. When the curvature is steep in some directions and flat in others, plain gradient steps zig-zag and make slow progress.

Two families of fixes were known in 2016. Natural-gradient methods precondition the gradient with an approximate inverse of the Fisher information matrix, which is accurate but expensive. Batch normalization instead changes the network: it normalizes each neuron's pre-activation using statistics of the current mini-batch (a small group of training examples used for one gradient step). It improves conditioning, but the statistics depend on the other examples in the batch, which adds noise and is awkward for recurrent or reinforcement-learning models.

The question the paper asks is whether the conditioning benefit can come from a plain reparameterization of the weights, with no dependence on the batch and no extra memory.

How it works

Take one neuron with input x\mathbf{x}, weight vector w\mathbf{w}, bias bb, and output y=ϕ(w⋅x+b)y = \phi(\mathbf{w}\cdot\mathbf{x} + b). Here ϕ\phi is a nonlinearity such as the rectifier. The pipeline below runs one training step with weight normalization.

  1. Input. A minibatch of examples enters the network. The network has parameters v\mathbf{v} (a direction-like vector), a scalar gg (a length), and a bias bb. The effective weight w\mathbf{w} is not stored; it is built from v\mathbf{v} and gg.
  2. Build the weight. Compute w=g∥v∥v\mathbf{w} = \frac{g}{\lVert\mathbf{v}\rVert}\mathbf{v}. Tiny check: with v=(3,4)\mathbf{v} = (3, 4) and g=2g = 2, ∥v∥=5\lVert\mathbf{v}\rVert = 5, so w=(1.2,1.6)\mathbf{w} = (1.2, 1.6), whose length is 2=g2 = g.
  3. Forward pass. Use w\mathbf{w} as an ordinary weight. The neuron's output is ϕ(w⋅x+b)\phi(\mathbf{w}\cdot\mathbf{x} + b). No statistics are computed across examples, so each example is handled on its own.
  4. Loss. A loss LL is computed from the outputs, as in any supervised or reinforcement-learning setup.
  5. Backward pass. Gradients are taken with respect to gg and v\mathbf{v}, not w\mathbf{w}. The paper derives these in closed form from the gradient ∇wL\nabla_{\mathbf{w}} L that ordinary backpropagation already gives. Check: if ∇wL=(1,0)\nabla_{\mathbf{w}} L = (1, 0) at the example above, then ∇gL=(1⋅3+0⋅4)/5=0.6\nabla_g L = (1 \cdot 3 + 0 \cdot 4)/5 = 0.6.
  6. Update. A gradient step changes gg (the length) and v\mathbf{v} (the direction). Because the length of w\mathbf{w} is exactly gg whatever v\mathbf{v} is, the step on v\mathbf{v} changes the direction and not the size of the weight.
  7. Output. After training, the network is used with the weights w\mathbf{w} built from the final v\mathbf{v} and gg.

The paper adds two ideas that matter in practice. Step 2 of the above is cheap: the norm of v\mathbf{v} is one number per neuron, while batch normalization needs statistics over every activation in the batch. And the initialization of gg and bb is set from one data pass, which the paper calls data-dependent initialization (see "The math").

flowchart LR
    V[Direction v] --> N[Normalize: v over norm v]
    G[Length g] --> W[w = g times unit v]
    N --> W
    W --> F[Forward pass: phi of w dot x plus b]
    F --> L[Loss L]
    L -->|grad wrt g| G
    L -->|grad wrt v, projected| V

The math

Notation: v∈Rk\mathbf{v} \in \mathbb{R}^k is the direction parameter, g∈Rg \in \mathbb{R} the length parameter, ∥⋅∥\lVert\cdot\rVert the Euclidean norm (Vector Norm), and w\mathbf{w} the effective weight.

Step 2 in symbols: the reparameterization

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

The second identity holds for every v\mathbf{v}, so gg is the length of the weight and v/∥v∥\mathbf{v}/\lVert\mathbf{v}\rVert is its direction. The paper names this decoupling: length and direction are separate learnable quantities.

Step 5 in symbols: the gradients

Differentiating through the reparameterization gives

∇gL=∇wL⋅v∥v∥,∇vL=g∥v∥∇wL−g ∇gL∥v∥2 v.\nabla_g L = \frac{\nabla_{\mathbf{w}} L \cdot \mathbf{v}}{\lVert\mathbf{v}\rVert}, \qquad \nabla_{\mathbf{v}} L = \frac{g}{\lVert\mathbf{v}\rVert}\nabla_{\mathbf{w}} L - \frac{g\,\nabla_g L}{\lVert\mathbf{v}\rVert^2}\,\mathbf{v}.

These are the standard backpropagation quantities with a small correction, which is why the paper says the change to backpropagation is minor. The gradient with respect to w\mathbf{w} is computed as usual; the two formulas above convert it.

An equivalent form shows what the update does. Let Mw=I−ww⊤/∥w∥2M_{\mathbf{w}} = I - \mathbf{w}\mathbf{w}^\top / \lVert\mathbf{w}\rVert^2, the matrix that projects onto the space perpendicular to w\mathbf{w}. Then

∇vL=g∥v∥ Mw ∇wL.\nabla_{\mathbf{v}} L = \frac{g}{\lVert\mathbf{v}\rVert}\, M_{\mathbf{w}}\,\nabla_{\mathbf{w}} L.

Two things happen. The gradient is scaled by g/∥v∥g/\lVert\mathbf{v}\rVert, and its component along w\mathbf{w} is removed. Removing that component is why the update changes only the direction at first order.

Norm growth under plain gradient descent

Let Δv\Delta\mathbf{v} be a plain (not momentum) update. Because it is perpendicular to v\mathbf{v}, the Pythagorean theorem gives, with c=∥Δv∥/∥v∥c = \lVert\Delta\mathbf{v}\rVert / \lVert\mathbf{v}\rVert,

∥v+Δv∥=1+c2 ∥v∥≥∥v∥.\lVert\mathbf{v}+\Delta\mathbf{v}\rVert = \sqrt{1 + c^2}\,\lVert\mathbf{v}\rVert \ge \lVert\mathbf{v}\rVert.

So ∥v∥\lVert\mathbf{v}\rVert never shrinks. Large gradients make it grow quickly, which lowers the effective learning rate g/∥v∥g/\lVert\mathbf{v}\rVert. This is why the paper finds training robust to the choice of learning rate. Adam and momentum break the exact identity, but the authors report the same qualitative effect.

Data-dependent initialization in symbols

Before training, v\mathbf{v} is drawn from a normal distribution with mean 0 and standard deviation 0.05. Then one minibatch X\mathbf{X} is passed forward using t=v⋅x∥v∥t = \frac{\mathbf{v}\cdot\mathbf{x}}{\lVert\mathbf{v}\rVert}, with μ[t]\mu[t] and σ[t]\sigma[t] the mean and standard deviation of tt over that minibatch. Set

g←1σ[t],b←−μ[t]σ[t].g \leftarrow \frac{1}{\sigma[t]}, \qquad b \leftarrow -\frac{\mu[t]}{\sigma[t]}.

Then g t+b=(t−μ[t])/σ[t]g\,t + b = (t - \mu[t])/\sigma[t], so every neuron starts with zero mean and unit variance on that minibatch, as in batch normalization, but only once and only for initialization.

Mean-only batch normalization

The paper also tries a cheaper variant that subtracts the minibatch mean but does not divide by the standard deviation: t~=t−μ[t]+b\tilde t = t - \mu[t] + b, with t=w⋅xt = \mathbf{w}\cdot\mathbf{x}. The gradient with respect to tt is then ∇tL=∇t~L−μ[∇t~L]\nabla_t L = \nabla_{\tilde t} L - \mu[\nabla_{\tilde t} L]. The minibatch noise that remains is smaller than in full batch normalization, and the authors report that this variant works best in their experiments.

Results

The paper runs four kinds of experiment. Each compares the standard parameterization with weight normalization.

CIFAR-10 image classification. A convolutional network on CIFAR-10. Weight normalization and batch normalization both converge faster than the standard parameterization early in training. The paper's best CIFAR-10 result comes from weight normalization combined with mean-only batch normalization, at a test error of about 7.3%, against about 8.1% for full batch normalization.

Convolutional variational autoencoder. With weight normalization, the test-set lower bound is reported to reach a better value and vary less across random seeds.

DRAW, a recurrent generative model. Weight normalization is applied to the LSTM weights with no change to initialization or learning rate, and convergence on MNIST is much faster. Batch normalization is harder to apply in a recurrent model, which is one of the paper's motivations.

Deep Q-Network on Atari. Weight normalization helps DQN learn faster on the games tested, where batch statistics were a poor fit for reinforcement learning.

Limits. The experiments are small by modern standards, with one model per setting. The paper gives no general convergence guarantee. The link to batch normalization is an analysis of a single layer, and it is an approximation for deep networks. Data-dependent initialization needs a batch of data, so it does not apply directly to recurrent models, which need a standard initialization. The gradient-projection and norm-growth arguments are exact for plain gradient descent and only qualitative for Adam and momentum.

Reading guide

Read the paper in this order, with the lessons each section needs.

  1. Motivation. Needs Gradient Descent at the level of "some directions are steep and some flat." The paper sets two families of fixes side by side: natural-gradient methods and Batch Normalization.
  2. The reparameterization. The core. Needs Weight Normalization first, then Vector Norm and the Chain Rule. Work the gradient formulas with a pencil; the projection form needs Vector Norm and orthogonality.
  3. Comparison with batch normalization. Needs Batch Normalization. The single-layer analysis is the key idea for comparing the two.
  4. Data-dependent initialization. Needs Xavier (Glorot) Initialization for the background on scale and activation functions for why the normalized pre-activation matters.
  5. Mean-only batch normalization. Optional on a first read; it gives the paper's best CIFAR-10 result, so come back to it.
  6. Experiments. Needs Stochastic Gradient Descent, Adam Optimizer, Convolutional Neural Network, Variational Autoencoder, Recurrent Neural Network, LSTM and Reinforcement Learning. Read the CIFAR-10 experiment first, since the others refer back to it.

Check yourself

QuestionIn one sentence, what does weight normalization change about how a neuron's weights are stored, and what stays fixed?Show answer

It stores the weight as a direction vector v\mathbf{v} and a scalar length gg, and builds w=g v/∥v∥\mathbf{w} = g\,\mathbf{v}/\lVert\mathbf{v}\rVert. The length of w\mathbf{w} is always gg; what stays fixed is the function class, since every weight vector is still representable.

QuestionTake v=(6,8)\mathbf{v} = (6, 8) and g=3g = 3. What is w\mathbf{w}, and what is its length?Show answer

∥v∥=36+64=10\lVert\mathbf{v}\rVert = \sqrt{36 + 64} = 10, so w=310(6,8)=(1.8,2.4)\mathbf{w} = \frac{3}{10}(6, 8) = (1.8, 2.4). Its length is 1.82+2.42=3.24+5.76=9=3=g\sqrt{1.8^2 + 2.4^2} = \sqrt{3.24 + 5.76} = \sqrt{9} = 3 = g.

QuestionWhy does the paper say that the norm of v\mathbf{v} grows under plain gradient descent, and what does that do to the effective learning rate?Show answer

A plain gradient update Δv\Delta\mathbf{v} is perpendicular to v\mathbf{v}, because the gradient with respect to v\mathbf{v} has its component along w\mathbf{w} removed. By Pythagoras, ∥v+Δv∥2=∥v∥2+∥Δv∥2\lVert\mathbf{v}+\Delta\mathbf{v}\rVert^2 = \lVert\mathbf{v}\rVert^2 + \lVert\Delta\mathbf{v}\rVert^2, so the norm cannot shrink. As it grows, the scale g/∥v∥g/\lVert\mathbf{v}\rVert falls, so the effective step size on the direction drops. Large learning rates therefore self-correct, which is why the paper finds training robust to the learning rate.

QuestionA reader says: 'Weight normalization is exactly the same as batch normalization, so it can be used in any network.' Give one reason this is wrong, using the paper.Show answer

The paper relates the two methods through an analysis of a single layer, and the correspondence is an approximation that does not carry over exactly to deep networks. Weight normalization also does not depend on the minibatch, which is why it fits settings such as reinforcement learning and recurrent models, where batch statistics are awkward. So the methods are related but not interchangeable.

QuestionScenario: you train a recurrent model whose batches are only 4 sequences long, and the batch-normalization statistics change a lot from one step to the next. What does this paper suggest you try, and what must you still handle?Show answer

Try weight normalization on the recurrent layers. Its gradient step does not use batch statistics, so the noise from small, varying batches is absent, and the paper applies it to LSTM weights (the DRAW experiment) with no change to learning rate or initialization. You still need an initialization for gg and bb. The data-dependent scheme needs a batch and does not transfer directly to recurrent models, so you would use a standard initialization for those layers, as the authors did.

Sources

  • Salimans, T. and Kingma, D. P. (2016). Weight Normalization: A Simple Reparameterization to Accelerate Training of Deep Neural Networks. arXiv:1602.07868.
  • Ioffe, S. and Szegedy, C. (2015). Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift. arXiv:1502.03167.

Read the full paper

Tim Salimans, Diederik P. Kingma, 2016. arXiv:1602.07868