How a diffusion model turns noise into a picture

It never draws. It starts from random dots and cleans them up a little at a time. Run the process yourself, with your own drawing, and see why it takes many steps.

By ยท Published

A heart made of pink dots in the middle of a wide field of scattered grey dots, with a looser ring of dots gathering around it

The short answer

A diffusion model never draws. It starts from a screen of random dots and removes a little of the randomness, again and again, until what is left is a picture. All it has learned is how to take one small step from noisier to cleaner.

The stage below runs that process on your own screen. Watch it, change it, and give it a drawing of your own. The rest of the page explains what you are seeing.

Watch noise become a picture

The stage starts from 1,200 dots of pure noise and removes the noise in steps. It plays by itself the first time you reach it. Then drag the step slider back and forth, and tick "Show where each dot is pulled" to see where the dots are being sent at each step (it draws a line for one dot in eight). Much of what the eye can see happens in the last quarter of the steps, so the stage plays those more slowly.

One thing here is simpler than in a real image model. A real model has to guess what the clean picture is, and its guess comes from a trained neural network (Ho et al., 2020). Here the picture is known, so the best possible guess can be worked out directly: it is the average of the picture's 300 dots, each one weighted by how likely it is that noise carried it to where the noisy dot is now (Karras et al., 2022, equation 57 in the appendix). Everything else is the real thing: the noise levels and the way of stepping come from the papers cited below.

Then draw a picture of your own, and the stage will make that instead.

It begins by ruining pictures

Turning a picture into noise is easy: add a little randomness, then a little more. A 2015 paper proposed doing that slowly, on purpose, and then learning to run it backwards (Sohl-Dickstein et al., 2015). A later paper put it in one line: "Creating noise from data is easy; creating data from noise is generative modeling" (Song et al., 2020).

The 2020 paper that showed diffusion models could make high-quality images used 1,000 noise levels, each adding a little more noise than the one before (Ho et al., 2020). By the last level almost nothing of the picture is left: each dot keeps less than 1% of its own position, and the rest is noise.

Drag the slider and watch a heart made of 300 dots dissolve. To make the cloud easy to see, every dot of the heart is drawn four times, each time with different noise. Notice how early the picture is lost to the eye: by level 150, with 850 levels still to go, the heart can hardly be made out.

Then it learns to name the noise

Going from pure noise back to a picture in one move is too much to ask. So the model learns one job instead: it is shown a picture with noise mixed in, sometimes a little and sometimes almost nothing but noise, and it has to say what the noise was (Ho et al., 2020).

Knowing the noise is the same as knowing the picture: take the noise away, and what is left is the model's guess of the clean picture. Making an image uses that guess at every step. It moves the noisy image part of the way towards the guess, down to the next noise level, and asks again (Song, Meng and Ermon, 2020).

Why not do it in one step?

On the stage, set "How many steps" to 1. The run plays again by itself, and every dot lands on the same spot: the middle of the picture. For the heart, that is a place where the picture has no dot at all. From pure noise, the best single guess is the average of everything the picture could be: the more noise there is, the closer the best guess comes to the average of all the pictures (Karras et al., 2022, figure 1). And the average of everything is a blur.

With more steps, each guess starts from a slightly cleaner place, so it is a slightly sharper guess. In this simulation, a dot ends on average about six times closer to the nearest dot of the heart at 100 steps than at 20. The gain is not even: going from 10 steps to 20 brings the dots more than three times closer on average, and going from 50 to 100 less than twice.

The first models walked through all 1,000 levels (Ho et al., 2020). A different way of stepping made it possible to skip most of them, and made good images 10 to 50 times faster (Song, Meng and Ermon, 2020). The same paper describes the choice you are making with the slider: fewer steps cost less computing, more steps give a better picture.

The four squares below show it without scrolling back: the picture and the starting noise you chose on the stage, taken in 1, 5, 20 and 100 steps.

The noise decides which picture you get

Press "New noise" on the stage. The picture comes back and looks the same, but every dot has ended somewhere else. Nothing in the steps is random: this way of stepping adds no new randomness on the way down (Song, Meng and Ermon, 2020). So the starting noise decides the result. The same noise gives the same picture, every time.

It even survives a change in the number of steps. In this simulation, the same noise run with 20 steps and with 100 steps sends most dots to nearly the same place, while new noise sends them somewhere else entirely. The same paper reports this for real images: runs of different lengths from the same starting noise share their main features (Song, Meng and Ermon, 2020). A number that picks the starting noise is called a seed.

The three squares below show both. The same eight dots are drawn larger in each. The first two squares start from the same noise and take 20 and 100 steps: most or all of the marked dots end in nearly the same places. The third starts from new noise, and they end somewhere else.

The whole journey at once

Below is a run of the same kind, with the picture and the noise you chose on the stage, seen from above and to the side, in 24 steps. Time runs downwards: noise at the top, the picture at the bottom, and one thread for each dot's path. Drag it sideways to turn it.

Near the top the threads hardly move. From that far away, every guess is close to the average, so no dot knows yet where it belongs. The threads bend and gather in the lower half, where the noise is low enough for a dot to tell which part of the picture is its own. The paper that used 1,000 levels saw the same order in real images: the large shapes appear first and the details last (Ho et al., 2020).

What a real image model adds

Three things stand between this stage and a model that makes a photograph from a sentence.

  • A network in place of a formula. The formula on the stage needs the finished picture. A real model has only what it learned from its training pictures, so a neural network makes the guess (Ho et al., 2020).
  • A smaller space. Working on every pixel is expensive. Latent diffusion models first squeeze the image into a much smaller grid of numbers, take the steps there, and turn the result back into pixels at the end (Rombach et al., 2021).
  • Your words. In the same design, the network reads a text prompt while it makes each guess, so the prompt steers every step (Rombach et al., 2021).

The steps themselves stay what you saw: start from noise, guess, move a little, repeat.

Where do new pictures come from?

The stage has a limit: it cannot invent anything. Its guess is perfect, and with enough steps a perfect guess can only lead back to the picture it was given. Draw a circle and you get your circle, never an oval. Theory says the same of real models: one that learned its job perfectly could only give back its training pictures (Kamb and Ganguli, 2024).

Real models do make pictures nobody has seen. So their networks must be getting the job wrong in a useful way, and how they do it is an open research question. One proposed answer is that the networks look at small patches of the image at a time, and so end up joining patches from many training pictures into a new whole (Kamb and Ganguli, 2024). That is one theory, tested on small research image sets. The full answer is not known yet.

Sources

  1. Ho, Jain, Abbeel (2020). Denoising Diffusion Probabilistic Models. NeurIPS 2020.
  2. Karras, Aittala, Aila, Laine (2022). Elucidating the Design Space of Diffusion-Based Generative Models. NeurIPS 2022.
  3. Sohl-Dickstein, Weiss, Maheswaranathan, Ganguli (2015). Deep Unsupervised Learning using Nonequilibrium Thermodynamics. ICML 2015.
  4. Song et al. (2020). Score-Based Generative Modeling through Stochastic Differential Equations. ICLR 2021.
  5. Song, Meng, Ermon (2020). Denoising Diffusion Implicit Models. ICLR 2021.
  6. Rombach et al. (2021). High-Resolution Image Synthesis with Latent Diffusion Models. CVPR 2022.
  7. Kamb, Ganguli (2024). An analytic theory of creativity in convolutional diffusion models. arXiv.

Written by

Tarek Abdellatef and the AiBrush team

Tarek Abdellatef founded AiBrush in Gothenburg, Sweden, to give the people who make ads one studio for video, images, voice and music. He and the AiBrush team write about how AI media works and what makes ads work.