Destroy the image in known steps, then learn to undo one
- : the variance of the noise added at step , following a fixed schedule.
The forward process is not learned. It adds a little Gaussian noise at a time until, after steps, nothing of the image remains.
Because Gaussians compose, any step can be reached in one jump, so training never has to run the chain.
That line is the whole training data generator: pick an image, pick a , pick a noise, and you have an input and its answer.
The objective is a regression
The network is given a noisy image and the timestep, and asked to predict the noise that was added.
It is mean squared error. There is no adversary, no divergence and no sampling inside the loss, which is why diffusion trains stably where GANs do not.
Predicting the noise rather than the clean image is a reparameterisation of the same problem, and it happens to be far better conditioned across the range of .
Sampling, in order
- Start from pure noise .
- Predict the noise in the current image with the network.
- Subtract a scaled portion of it to get a slightly cleaner image.
- Add a small amount of fresh noise, except at the last step.
- Repeat down to .
Step four is not a mistake. The reverse process is stochastic, and removing all the noise at once lands on a blurred average rather than a sample.
The cost, and what removed it
Generation is a loop over the network, which is why a diffusion model is thousands of times slower per sample than a GAN.
Faster samplers such as DDIM need only 20 to 50 steps.
Deterministic samplers reinterpret the same trained model as an ordinary differential equation and solve it in far fewer, larger steps.
The other halving of cost is running the whole process inside an autoencoder's latent space, which is what Stable Diffusion is and why it fits on one card.
Conditioning, in one line
Classifier-free guidance runs the network twice, once with the prompt and once without, and extrapolates away from the unconditional prediction.
The guidance scale is the dial every image tool exposes. Higher follows the prompt harder and loses diversity, and past about 15 it produces oversaturated, broken images.