A diffusion model generates an image by learning to remove noise. Show it pure static, and step by step it predicts the noise to subtract — until a clean image is left. The slider above walks one such denoising trajectory.
Where you meet it
- Text-to-image generators — Stable Diffusion, DALL·E, Midjourney, Imagen.
- Video and audio generation — Sora, and most modern audio/music models.
- Inpainting, super-resolution, restoration — anything that fills or sharpens an image.
What it does
It learns to invert a corruption process. There are two directions: a fixed forward process that destroys an image into noise, and a learned reverse process that reconstructs an image from noise. Only the reverse direction needs a neural network — and that is the thing you sample from to generate.
The model never paints the image — it predicts the noise, and the picture is whatever is left once that noise is subtracted.
How it works
The forward process takes a real image x₀ and adds a small amount of Gaussian noise over many steps t = 1 … T, until x_T is indistinguishable from pure noise. A useful trick: thanks to the math, you can jump straight to any step in closed form, mixing the clean image and noise by a known ratio.
x_t = √(ᾱ_t) · x₀ + √(1 − ᾱ_t) · ε ε ~ N(0, I)
# ᾱ_t shrinks with t: more t → more noise, less signal
A network (a U-Net) is trained on a deceptively simple job: given a noisy x_t and the step t, predict the noise ε that was added. The loss is just the error between predicted and actual noise.
L = || ε − ε_θ(x_t, t) ||²
To generate, you run the reverse: start from random noise x_T, and at each step use the network's noise estimate to take one small step back toward a clean image. Repeat T times.
x = randn(...) # pure noise
for t in range(T, 0, -1):
eps = model.predict_noise(x, t) # what noise is in here?
x = step_back(x, eps, t) # subtract a little, add a little
# x is now a sample
Text conditioning feeds a prompt embedding into the U-Net so the noise prediction depends on the text; classifier-free guidance then exaggerates that effect, pulling the result harder toward the prompt.
Watch out
- It predicts the noise, not the image. The clean image is what's left after the predicted noise is removed — not what the network outputs directly.
- Many steps is slow. A faithful sampler can take hundreds of forward passes. DDIM samplers and distillation cut that to dozens or even a handful.
- Latent diffusion runs in a compressed space. Stable Diffusion denoises a small latent (via an autoencoder), not raw pixels — that's why it's fast enough for a laptop.
- Not a GAN. No discriminator, no adversarial game. Diffusion trains a stable regression loss, which is a big reason it's easier to scale.
Go deeper
Ein Diffusionsmodell erzeugt ein Bild, indem es lernt, Rauschen zu entfernen. Man zeigt ihm reines Rauschen, und Schritt für Schritt sagt es das abzuziehende Rauschen voraus — bis ein sauberes Bild übrig bleibt. Der Slider oben läuft genau eine solche Entrausch-Bahn ab.
Wo es vorkommt
- Text-zu-Bild-Generatoren — Stable Diffusion, DALL·E, Midjourney, Imagen.
- Video- und Audio-Generierung — Sora und die meisten modernen Audio-/Musikmodelle.
- Inpainting, Super-Resolution, Restauration — alles, was ein Bild auffüllt oder schärft.
Was es tut
Es lernt, einen Verfälschungsprozess umzukehren. Es gibt zwei Richtungen: einen festen Vorwärtsprozess, der ein Bild zu Rauschen zerstört, und einen gelernten Rückwärtsprozess, der aus Rauschen ein Bild rekonstruiert. Nur die Rückwärtsrichtung braucht ein neuronales Netz — und genau daraus wird beim Generieren gesampelt.
Das Modell malt nie das Bild — es sagt das Rauschen voraus, und das Bild ist das, was nach dessen Abzug übrig bleibt.
Wie es funktioniert
Der Vorwärtsprozess nimmt ein echtes Bild x₀ und fügt über viele Schritte t = 1 … T jeweils etwas Gauß-Rauschen hinzu, bis x_T von reinem Rauschen nicht mehr zu unterscheiden ist. Praktischer Trick: dank der Mathematik kann man jeden Schritt in geschlossener Form direkt anspringen — sauberes Bild und Rauschen mit bekanntem Verhältnis gemischt.
x_t = √(ᾱ_t) · x₀ + √(1 − ᾱ_t) · ε ε ~ N(0, I)
# ᾱ_t fällt mit t: mehr t → mehr Rauschen, weniger Signal
Ein Netz (ein U-Net) wird auf eine täuschend einfache Aufgabe trainiert: gegeben ein verrauschtes x_t und der Schritt t, sage das Rauschen ε voraus, das hinzugefügt wurde. Der Loss ist nur der Fehler zwischen vorhergesagtem und echtem Rauschen.
L = || ε − ε_θ(x_t, t) ||²
Zum Generieren läuft man rückwärts: starte mit zufälligem Rauschen x_T und mache in jedem Schritt anhand der Rauschschätzung des Netzes einen kleinen Schritt zurück Richtung sauberes Bild. T-mal wiederholen.
x = randn(...) # reines Rauschen
for t in range(T, 0, -1):
eps = model.predict_noise(x, t) # welches Rauschen steckt drin?
x = step_back(x, eps, t) # etwas abziehen, etwas dazu
# x ist jetzt ein Sample
Text-Konditionierung speist ein Prompt-Embedding ins U-Net, sodass die Rauschvorhersage vom Text abhängt; Classifier-free Guidance verstärkt diesen Effekt und zieht das Ergebnis stärker zum Prompt.
Worauf achten
- Es sagt das Rauschen voraus, nicht das Bild. Das saubere Bild ist das, was übrig bleibt, nachdem das vorhergesagte Rauschen entfernt wurde — nicht der direkte Output des Netzes.
- Viele Schritte sind langsam. Ein treuer Sampler braucht hunderte Forward-Passes. DDIM-Sampler und Distillation drücken das auf Dutzende oder eine Handvoll.
- Latent Diffusion arbeitet im komprimierten Raum. Stable Diffusion entrauscht ein kleines Latent (über einen Autoencoder), nicht rohe Pixel — deshalb läuft es überhaupt auf einem Laptop.
- Kein GAN. Kein Diskriminator, kein adversariales Spiel. Diffusion trainiert einen stabilen Regressions-Loss — ein wesentlicher Grund, warum es sich leichter skalieren lässt.
Mehr dazu
- Ho, Jain & Abbeel — Denoising Diffusion Probabilistic Models (das DDPM-Paper)
- Lilian Weng — What are Diffusion Models? (die Mathematik, klar aufbereitet)
- Hugging Face — Diffusion Models Course, Unit 1 (Intuition + from scratch)
- Hugging Face Diffusers — Library-Doku (Pipelines & Scheduler in der Praxis)