What it is used for

Diffusion models are used to create new images from nothing. Unlike a model that selects or copies existing images, a diffusion model composes an image that has never existed by cleaning noise stage by stage, and its arrangement of pixels emerges slowly from coarse to detailed while that cleaning runs.

Because its skill is restoring structure from damaged material, the same working method is also used to blend and reconstruct images. The 2020 paper that anchors this article shows two face images melted into a smooth in-between image, with gradual changes in pose, skin tone, hairstyle, and expression. For general readers, the most concrete place to meet this model class is inside named image making products, such as Stable Diffusion, which is covered in its own article; this article explains the working engine that makes such products possible.

How to use it

End users do not use a diffusion model directly. What people use is a product inside which a diffusion model works, and inside such a product the user usually writes a description and adjusts things such as the number of steps used to make the image. This article does not teach the use of any single product; for that, read the product's own article.

For builders, the recipe follows the anchor paper and consists of two directions trained as one whole. The first direction, called the forward process, is fixed and not learned: training images are damaged by adding noise in small amounts at each step according to a schedule set in advance. The second direction, called the reverse process, is the part the neural network learns: guessing the noise added at a given step, so that the noise can be removed. Once training is finished, making an image means running the reverse process from pure noise, one small step at a time, until the last step yields an image.

Real examples

The following examples are not invented for this article. Both are recorded in the Denoising Diffusion Probabilistic Models paper itself, the 2020 paper by Ho, Jain, and Abbeel that anchors this article, and both are experiments its researchers actually ran.

The first experiment used CIFAR10, a collection of small 32 by 32 pixel images that serves as a standard test bed for image generation research. The diffusion model the researchers trained made new images without being given any starting image and without any condition beyond the patterns it had learned from the collection. Its quality was measured on 50,000 generated images: the Inception score reached 9.46 and the FID score reached 3.17. The FID score measures how close the spread of generated images is to the spread of real images, and smaller is better. That value of 3.17 was the best of its time, beating most other image generation models in the literature, including models that were given the image class label. The network used for this result had 35.7 million parameters.

The second experiment raised the image size to 256 by 256 pixels on the LSUN collection, which contains photos of rooms, cats, and churches, and on the CelebA-HQ face collection. The paper states that the results on LSUN reached sample quality similar to ProgressiveGAN, a well known image generation model of that period. The training scale is measured: the room model was trained for 2.4 million steps, the cat model for 1.8 million steps, the church model for 1.2 million steps, and the face model for 0.5 million steps, all on TPU v3-8 hardware. Its speed cost is also recorded honestly in the same paper and discussed in the Limits and risks section: making 128 images at 256 by 256 pixels took 300 seconds.

Practitioner level

The two directions in the How to use it section have very different natures, and that difference is the key to understanding this model family. The forward process is not learned at all; it is only a destruction schedule set by the researchers. In the anchor paper's experiments, the number of steps was 1000, and the amount of noise added grew in a straight line from 0.0001 at the first step to 0.02 at the last step. Because each step adds only a little noise, the matching reverse step is also simple, and the network only has to learn one repeated skill: guessing the noise that was just added at a given step.

The training method is clever because it breaks one large problem into many small problems of the same shape. The network is shown an image that has been damaged up to a randomly chosen step, then asked to guess exactly the noise that was added to that image. The anchor paper shows that this simplified training objective resembles a technique called denoising score matching, and that its image making process resembles Langevin dynamics, the gradual random walk method physics uses to reach a desired distribution. The network used in the experiments is a U-Net, an image processing network that shrinks then re-expands the image while carrying detail from large sizes to small ones, with the time step announced through a sinusoidal position marker like the one in the Transformer model, and with self-attention at the 16 by 16 feature map size. The model for 256 by 256 pixel images had 114 million parameters.

One practical consequence builders should know: because the forward process is fixed and can be computed directly, a training image can be damaged straight to any step without simulating all the steps before it. Training is therefore efficient, and what makes image making slow is not the training but the making itself, which must run the network once for every reverse step.

Expert level

Example of denoising in a diffusion model, by MrAlanKoh, CC BY-SA 4.0

Formally, the anchor paper defines a diffusion model as a latent variable model: its latent variables are the series of ever noisier versions of the image, with the same dimensionality as the original data, and their joint distribution is called the reverse process, a Markov chain with learned Gaussian transitions, starting from pure standard normal noise. Its abstract reads exactly: "We present high quality image synthesis results using diffusion probabilistic models, a class of latent variable models inspired by considerations from nonequilibrium thermodynamics."

Training is done with variational inference. Its variational bound can be split into terms that each compare one reverse step against a forward process posterior, and that posterior can be computed exactly when the original image is known, so every reverse step has a closed form training target. The same paper proves an equivalence between the noise predicting parameterization and denoising score matching over many noise scales at once, and reads the whole sampling procedure as a progressive lossy decompression scheme that can be interpreted as a generalization of autoregressive decoding: the image arrives little by little in a bit order far more flexible than the fixed order of ordinary autoregressive models. Interpolation in its latent space is also shown to work: two images are damaged to the same step, their latents are mixed in a straight line, and the mixture is cleaned back into a plausible in-between image.

Its historical standing deserves an honest note. The diffusion idea for data generation had been in writing since 2015, but the 2020 paper itself opens by admitting that before its work, there had been no demonstration that diffusion models could generate high quality samples. Its sentence reads exactly: "Diffusion models are straightforward to define and efficient to train, but to the best of our knowledge, there has been no demonstration that they are capable of generating high quality samples." So this family is not an idea born in 2020; 2020 is the year its old idea was proven to work at a quality that changed its field, and from that proof the family spread into the working engine behind many later image makers, including the named product covered in its own article in this corpus.

Limits and risks

The first weakness is making speed. Because an image is built through 1000 sequential reverse steps and each step runs the network once, making an image is far slower than a one pass image generation model. The anchor paper's own numbers: 300 seconds for 128 images at 256 by 256 pixels, and 17 seconds for 256 images at 32 by 32 pixels, on TPU v3-8 class hardware. Its training is also heavy, running for millions of steps on specialised hardware.

The second weakness is admitted by the paper itself: its models do not have competitive log likelihoods compared to other likelihood based models. In other words, this family's strength lies in the quality of the images it produces, not in its ability to measure how probable a piece of data is. Quality assessment therefore rests on sample measures such as the FID score, not on neatly measured likelihoods.

Its content risk follows from its standing as a working engine. Because this class is what drives named image making products, its generated images can look like real photographs and be used to mislead, and its training images determine the bias carried into its results. The usage risks of particular products are covered in each product's own article; at the class level, what readers should hold on to is that the better a model reverses destruction, the more convincing the fabricated images it can make, so stating where an image came from becomes more important, not less.