LABS · 08  /  DIFFUSION

Out of the Static.

A diffusion model doesn't paint — it un-noises. Start with a screen of pure random pixels and, step by step, wipe away a little of the noise. Do it enough times and a picture climbs out of the static. Watch a shape appear from nothing.

THE GIST · 20 SECONDS

Training teaches a model to reverse a noising process: add a little Gaussian noise to real images over and over until they're pure static, and learn to undo one step. To generate, start from noise and run it backward — each step the model predicts the noise and removes a bit, revealing a cleaner image. After all steps, a picture emerges. That's DDPM.

  • Forwardadd noise (fixed)
  • Reverseremove noise (learned)
  • Schedulenoise: high → 0
  • Samplenoise → image

Hit Step to remove one round of noise — or Play and watch the picture climb out of the static.

UNDER THE HOOD

What you just played, written down

Corruption is easy and fixed; restoration is hard and learned. Diffusion trains a network to reverse noise one small step at a time — then runs that reversal from pure static to make something new.

How diffusion works — four moves

  1. Forward (training only). Take a real image and add a little Gaussian noise, over and over, until it's pure static.
  2. Learn to undo one step. Train a network to look at a noisy image and its timestep and predict the noise that was added.
  3. Start from noise. To generate, begin with a fresh screen of random Gaussian noise — no image at all.
  4. Denoise to a sample. Repeatedly predict and remove a bit of noise; after all timesteps, a coherent image emerges.
WHY NOISE, OF ALL THINGS?

Turning an image into noise is trivial and needs no learning — so it's a free source of training pairs. All the intelligence goes into the reverse step, and running that reverse process from scratch is how new images are born.

The reverse step in code

x = torch.randn(shape)              # start from pure noise
for t in reversed(range(T)):
    eps = model(x, t)               # predict the noise
    x = remove_noise(x, eps, t)     # take one step cleaner
    if t > 0:
        x = x + sigma(t) * torch.randn_like(x)
return x                            # a fresh sample
TRAININGpredict εthe noise added
SAMPLINGT stepsnoise → image
WHY IT'S SLOW — AND THE FIX

One network call per step, dozens to hundreds of steps per image. DDIM samplers cut the steps; latent diffusion (Stable Diffusion) runs the whole process in a compressed space to make it affordable.

⚠ This is a simplification

Here the noise simply fades toward a fixed target so you can see the emergence. A real model doesn't know the target — it learns to predict noise, and each denoise is a genuine neural-network step, not a scripted fade.

↔ How you steer it

Add a text prompt and the denoiser is conditioned on it (via cross-attention), so the image that emerges matches the words. That's text-to-image generation.

★ Where it's used

Stable Diffusion, DALL·E, Midjourney, and modern video and audio generators — diffusion is the dominant way to generate high-fidelity media.

QUICK CHECK

Did it stick?

FAQ

Diffusion, answered

How do diffusion models generate images?

By reversing a noising process: start from pure Gaussian noise and, at each step, a network predicts a little noise to remove, revealing a cleaner image. After all steps, a coherent image emerges from the static.

Forward vs reverse process?

Forward (fixed): gradually add noise to real images until they're static — used only in training. Reverse (learned): a network undoes one noising step at a time; generation runs this from noise.

What does the model predict?

In DDPM it predicts the noise that was added to a noisy image at a given timestep. Subtracting a scaled version of that noise gives a slightly cleaner image.

What is the noise schedule?

How much noise is present at each timestep — high near the start, dropping to zero at the end. It paces both the corruption and the denoising.

Why are diffusion models slow?

They call the network once per step, over many steps. DDIM cuts the step count and latent diffusion runs in a compressed space to speed things up.

RESULT

Next → condition the denoiser on a text prompt and run it in a compressed latent space, and you've got Stable Diffusion — text to image.

Finished this one? 0 / 12 Labs done

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Labs