TL;DR
Annealed Langevin dynamics is a way to produce random samples from a distribution when all you can compute is its score, the slope of its log-density. It runs a Langevin walk at several noise levels in turn, from large to small. At large noise the landscape is smooth, so the walk can cross between regions easily; at small noise the walk settles into the fine detail of the distribution. Score-based image generators use it as their sampler.
Builds on: Langevin Dynamics, Score Function · Leads to: Noise-Conditional Score Network, Diffusion Model
Where it's used
Image generation. Song and Ermon's 2019 generator learned the score of a noisy version of the image distribution at many noise levels, then sampled new images with annealed Langevin dynamics. Their paper reports generated images with quality competitive with the best generative models of that time, without training a discriminator.
Bayesian inference and sampling from large models. A posterior distribution over model parameters is often known only up to a constant. Langevin-type samplers, including stochastic gradient versions that use a mini-batch of data for each step, draw posterior samples from the score of the posterior without computing its normalising constant.
Molecular simulation. Physicists sample configurations of molecules at a fixed temperature with Langevin dynamics, a standard tool in Molecular Dynamics. Annealing the noise, or the temperature, helps a simulation escape a local arrangement of atoms and reach a more typical one.
How it works
Take a target distribution with two peaks, one at and one at , and suppose the walk starts at , between them. Plain Langevin dynamics with a small step would stay near 0 for a long time: the score at 0 is almost zero, so there is little pull toward either peak, and the walk crosses between peaks only rarely. Annealing fixes this by changing the landscape before the walk tries to settle.
- Pick noise levels from large to small. Use , and . Check: each level is about a third of the one before, so the list runs from broad to fine.
- At the first level, smooth the landscape. Adding noise of size to the target blurs the two peaks into one broad hill. The score at this level points toward the middle of the hill, so the walk is free to move between the old peaks. Check: the broad hill covers both peaks.
- Run a Langevin walk at that level. Take many small steps along the score at , each followed by a little noise. The walk spreads over the whole broad hill, so it visits both sides. Check: the walk is no longer confined to one peak.
- Move to the next level. Use the walk's current point as the starting point at . The two peaks are now clearer, but the walk is already in a sensible region, so it does not need to cross the gap by chance. Check: the start is a point the previous level produced.
- Finish at the smallest level. At the landscape shows the fine structure of the target, and the walk refines the sample within the peak where it already is. Check: the final samples follow the two-peak target, not the blurred hill.
The step size at each level is set so that the walk moves less at smaller noise, so the final levels refine rather than jump.
- target, σ = 0
- smoothed, σ = 10
The math
Each step at level is
The update is the Langevin Dynamics step, with the score taken at a particular noise level. The term is the random kick, a draw from a Gaussian (Normal) Distribution with standard deviation .
Step 1 in symbols: the noise levels
A common choice is a geometric sequence, . Each level is a fixed fraction of the previous one, so the ratio between neighbours is the same at every step.
Step 2 in symbols: why large noise helps
If the target is a mixture of two narrow bumps, blurring it with noise of variance fills the gap between the bumps. For a single bump centred at with variance , the blurred version has variance . When is large, the blurred density is spread out, and the score is not zero in the gap, so the walk is pulled toward the centre of the mass and can cross.
For a standard Gaussian target, , the blurred density is , and its score is exactly
Check: when this is , the score of the standard Gaussian.
Step 3 in symbols: step sizes
A common rule is , for a small constant . The step is largest at the broadest level and smallest at the finest, and the ratio between the first and last steps is . The rule matches the scale of the noise, so the walk moves about as far as its noise level allows.
Step 4 in symbols: why this samples the target
For a fixed noise level and a small enough step, the Langevin update has the blurred density as its approximate stationary distribution. Running the levels in order moves the samples from an easy distribution, one that is well mixed, to the hard one. The final level's samples are approximately from , which is close to the data distribution when is small. Two approximations matter: the score must be accurate at each level, and the step sizes must be small enough that the discrete walk does not drift away from its stationary distribution.
Worked examples
Let the target be the standard Gaussian , with the score at noise level 0. Take , step size , and a noise draw .
- Score at : .
- Drift: . The position moves to .
- Noise: .
- New position: .
- Check: the drift pulled the point toward 0 by 0.3, and the noise pushed it up by 0.22. The net move is small and in the direction of the peak.
Interpretation: a single update only nudges the walk. Many updates are needed before the positions look like samples from the target.
Let the target again be , so at noise level the score is . Use , so and the score is . Take , step size and noise draw .
- Score at : .
- Drift: . The position moves to .
- Noise: .
- New position: .
- Compare with the same update at : the drift would be , about ten times larger.
- Check: the broad level pulls the point back much more weakly, because the blurred density is more spread out.
Interpretation: at a large noise level, the score is weaker, so a walk far from the centre drifts back more slowly. This is the cost of the smoother landscape, and it is why the schedule must balance noise and steps.
Suppose images are scaled to values between 0 and 1. Use noise levels, geometric from down to , with Langevin steps at each level.
- The number of score evaluations is , one network call for each step.
- The ratio between the first and last noise levels is .
- With fixed, the ratio between the first and last step sizes is .
- So the walk at the broadest level takes steps ten thousand times larger than at the finest level. The broad levels move the sample across the image distribution, and the fine levels adjust detail such as edges and texture.
- Check: the step ratio is the square of the noise ratio, as the rule in step 3 requires.
Try it: if the schedule runs from down to , how much larger is the first step than the last? Answer: , the same ratio, because the ratio of the noise levels is again 100.
Interpretation: the schedule spends most of its steps at moderate noise, where the samples take their shape, and finishes with small steps that clean up detail. The total cost is set by the number of levels times the steps per level.
Common mistakes and tradeoffs
It is tempting to think that annealing is just running Langevin dynamics longer. In fact a long run at one small noise level can stay stuck in one peak, because the score there gives no reason to cross. The point of annealing is to change the landscape so that crossing becomes likely, and then to restore the fine detail.
It is tempting to think the walk at the last level alone gives the correct distribution. In fact each level's walk is only approximately correct, and the sample at the end depends on the earlier levels having put the walk in a good region. Dropping the coarse levels can give samples that look sharp but miss whole modes.
It is tempting to think the score is known exactly. In practice it is estimated, usually by a network trained with Score Matching. Errors in the estimate bias the stationary distribution, and they are largest in low-density regions, where there are few samples to learn the score from.
Annealed Langevin dynamics is useful when the score is available at several noise levels and when the target has several well-separated modes. It is slow, because each sample needs score evaluations, often thousands of network calls. Faster samplers, such as those used by diffusion models that reverse a noise process with fewer steps, trade some of the exactness for speed. For a single smooth density with a known score, plain Langevin Dynamics is simpler and usually enough.
History
In 1908 Paul Langevin wrote down a stochastic equation for the motion of a particle in a fluid, a drift toward low energy plus a random kick, the same kind of random motion as Brownian Motion. The discrete sampler built on it was studied as a way to draw from a distribution in statistics and physics in the late twentieth century, as one of the Markov chain Monte Carlo methods.
In 2011 Welling and Teh showed how to run Langevin-type updates with mini-batches of data, which made the method usable for Bayesian inference on large datasets. In 2019 Song and Ermon combined score estimation at many noise levels with annealed sampling, and showed that the procedure could generate natural images. Their work made annealing the standard way to sample from a learned score, and it led directly to the score-based generative models that followed.
Recap
- Langevin dynamics samples a distribution by stepping along its score and adding noise.
- Annealing runs the walk at a sequence of noise levels, from large to small, so the walk can cross between modes at the start and refine at the end.
- Large noise blurs the target and gives a score that pulls the walk across gaps; small noise restores the detail.
- The step size at each level scales with the square of the noise level, so the walk moves in proportion to its scale.
- The method costs many score evaluations, and its quality depends on how accurate the score is at each level.
- Read next: Noise-Conditional Score Network for the generator that uses this sampler, and Diffusion Model for the related family of generators.