The Design Space of Diffusion Models
Noise schedules, preconditioning, samplers and diffusion transformers.
DDPM, score-based SDEs and DDIM were derived from different theories, and their code tangled together choices that have nothing to do with each other. Karras et al. (2022) rewrote them as one recipe with independent dials: the coordinates of the ODE, the scaling of the network's inputs and outputs, the weighting of noise levels, the sampler. Setting each dial deliberately cut the network evaluations needed per sample by factors of 3 to 300 and set new benchmark records.
What you’ll learn
- Write any Gaussian diffusion model as a denoiser and a probability-flow ODE in , and explain why the noise schedule changes only the ODE's coordinates, not its solutions.
- Derive EDM's preconditioning and loss weight from unit-variance requirements, and relate them to -, - and -prediction.
- Compare noise schedules and loss weightings through the log-SNR, including the cosine schedule, the shift with image resolution and zero terminal SNR.
- Implement EDM's Heun sampler, derive the exponential-integrator form behind DPM-Solver, and compare U-Net and transformer backbones.
One ODE in many coordinates
Write the noisy sample in the variance-exploding coordinates of Diffusion Models, , so that the data blurred to noise level is . The trained network is a denoiser , the minimizer of , and Tweedie's formula turns it into the score, which gives the probability-flow ODE in its simplest form (Karras et al., 2022):
Earlier models used other clocks and rescaled : a variance-preserving model works with on its own schedule. EDM's general ODE has a noise schedule and a scale , and Karras et al. show that every such choice is a reparameterization of the same canonical ODE: relabels time and rescales space. With an exact denoiser and exact integration, all of them carry a given noise sample to the same output. The choices matter only through the errors a numerical solver makes, which grow with the curvature of the trajectories in the chosen coordinates. That separation is what made a systematic search possible:
| Dial | What it controls | Typical earlier choice | EDM |
|---|---|---|---|
| Schedule , scale | coordinates of the ODE, hence its curvature | VP: from a ramp with shrinking ; VE: | , |
| Time steps | where the solver spends its evaluations | uniform in (VP), geometric in (VE) | , , |
| Solver | error per network evaluation | Euler | Heun's second-order method, optionally with added noise |
| Preconditioning | what the raw network sees and outputs | -prediction | (next step), |
| Training noise and weight | where training effort goes | uniform in (VP) or in (VE); | , |
Why ? Then , so one Euler step from any to lands exactly on : the tangent always points at the current denoised estimate. That estimate barely moves at high noise, where it sits near the dataset mean, or at low noise, where the image is settled, so trajectories are nearly straight at both ends and curve only in a middle band of . EDM's sketch with data at shows exactly this, whereas variance-preserving trajectories flatten out at large and variance-exploding ones curve everywhere. DDIM already used these coordinates. Together with Heun's method and the step schedule, they reduced the evaluations needed for high-quality samples by 7.3 times for a VP model, 300 times for a VE model and 3.2 times for DDIM-style sampling of ADM.
Preconditioning and the loss
A network asked to output directly would see inputs whose scale ranges from the data's, for images in , to over a hundred times larger. Noise prediction writes instead, which at large multiplies every error of the network by and forces it to cancel the input's noise almost exactly. EDM mixes a skip connection and the network's output with -dependent coefficients:
Assume each coordinate of the data has variance and the noise is independent of the data. Require the network's input to have unit variance:
Require the effective target to have unit variance too. Its numerator is :
Any error of reaches multiplied by , so choose to make as small as possible. Setting the derivative to zero:
Finally, give every noise level the same effective weight, , which also equalizes the initial loss across :
At the noise level , what is the skip coefficient , the weight on the noisy input in the denoiser's output?
Show the answer
0.5
, and for . Below this level and the network only predicts a small correction, essentially the noise; above it and , so the network predicts the clean image itself. The parameterization slides between noise and data prediction according to which is easier.
The familiar parameterizations are corners of this family. -prediction is , ; predicting outright is , ; and with , EDM's coefficients reproduce, up to the sign of the output, -prediction (Salimans & Ho, 2022), which Continuous Flows & Flow Matching identifies with flow matching on the variance-preserving path.
Where to train. With these weights the loss starts out equal at every , but after training it can be pushed well below its initial value only at intermediate noise levels: at very low the noise is vanishingly small and irrelevant, and at very high the best answer is close to the dataset average and far from any single example. EDM therefore draws , centered near . These training changes plus a non-leaky augmentation scheme took the class-conditional CIFAR-10 FID from 2.48 to 1.79 at 35 evaluations.
Noise schedules and the signal-to-noise ratio
Every schedule is a map from time to the log-SNR , which in EDM's coordinates is simply . Once the weighting is fixed, the schedule decides where training examples and sampling steps fall along .
DDPM's linear schedule spends them badly at low resolution: as the predict in Diffusion Models showed, half of the signal variance is gone a quarter of the way through, and the last third of the chain is almost pure noise. Nichol & Dhariwal (2021) found that a ImageNet model trained with it barely lost FID when the first 20% of the reverse process was skipped. Their cosine schedule , , makes fall almost linearly in the middle and change little near both ends; without the small offset its log-SNR is . The same paper learned the reverse variances, interpolating between and in log space with a small weight () on the true ELBO, which kept FID near its best with 100 sampling steps of a model trained with 4,000.
Average-pool a noisy image over blocks. The signal of a block is times the average of its pixels; its noise is the average of independent noises, with variance :
The network's downsampling layers work with such pooled images. On a large image, the coarse structure, which is decided at those resolutions, is therefore far less corrupted at a given step than on a small image, and much of the chain is spent after the global layout is fixed. Hoogeboom et al. define the schedule at a reference resolution of and shift it for a image:
By what factor must the SNR be divided at every step so that a image, viewed at the scale, sees the same noise as a image does under the reference schedule?
Show the answer
64
Pooling down to averages blocks, multiplying the SNR by , so the schedule must divide it by 64, a log-SNR shift of . Chen (2023) reached the same conclusion empirically: the best schedule becomes noisier as images grow, and simply scaling the input data down by a constant works across sizes.
Samplers: step placement, order and noise
EDM's step schedule interpolates between and uniformly in . With the levels are uniform in ; larger crowds them toward small . For levels, puts 7 of them below , against 1 for uniform spacing. Karras et al. found that nearly equalizes the truncation error of every step, yet between 5 and 10 gives clearly better images: errors made near , where detail forms, cost the most. The solver is Heun's method, an Euler step followed by a trapezoidal correction, with local error instead of Euler's at the cost of a second evaluation per step:
import torch
@torch.no_grad()
def edm_sample(D, shape, N=18, sigma_min=0.002, sigma_max=80.0, rho=7.0):
i = torch.arange(N)
sig = (sigma_max ** (1 / rho) + i / (N - 1) * (sigma_min ** (1 / rho) - sigma_max ** (1 / rho))) ** rho
sig = torch.cat([sig, torch.zeros(1)]) # sigma_N = 0
x = torch.randn(shape) * sig[0]
for s, s_next in zip(sig[:-1], sig[1:]):
d = (x - D(x, s)) / s # dx/dsigma at s
x_next = x + (s_next - s) * d # Euler step
if s_next > 0: # Heun's correction
d_next = (x_next - D(x_next, s_next)) / s_next
x_next = x + (s_next - s) * 0.5 * (d + d_next)
x = x_next
return x # 2N - 1 evaluations of DD(x, sigma) is the preconditioned denoiser. The last step, to , has no correction, so costs the 35 evaluations of EDM's CIFAR-10 results. With the exact denoiser of a small mixture of Gaussians in place of a network, this loop reproduces the mixture.
Adding noise back. EDM's stochastic sampler first raises the noise level of the current sample by a factor , with fresh noise, and then takes the ODE step down. Injecting and removing noise lets later steps correct earlier errors, in the manner of Langevin dynamics, but too much of it erodes detail and drifts colors toward oversaturation, which Karras et al. attribute to learned denoisers being slightly non-conservative. So they add noise only within a band of noise levels, never more than is already present (), and inflate it slightly. With their improved training, deterministic sampling was best on CIFAR-10, while ImageNet still gained: FID 1.36 at 511 evaluations, a record at the time.
What the last step does. The widget's sampler ends, like DDPM's and EDM's, by jumping from the smallest noise level straight to the denoised estimate. Watch what that costs:
In EDM's coordinates the ODE is , the predicted noise. Integrate exactly from down to and change variables to , half the log-SNR (Lu et al. call it ):
In variance-preserving coordinates , with signal scale , this is Lu et al.'s exact solution: the linear part of the ODE, , is handled exactly and only an exponentially weighted integral of the network remains.
Freeze at its value at . The integral becomes , and the step is Euler's method in , which is exactly deterministic DDIM; in variance-preserving coordinates, with , it is Lu et al.'s DPM-Solver-1:
Keeping terms of a Taylor expansion of in , with intermediate evaluations to estimate the derivatives, gives DPM-Solver-, whose error at the end of sampling is under regularity assumptions on the network (Lu et al., Theorem 3.2, proved for ). On CIFAR-10 it reached FID 4.70 with 10 evaluations and 2.87 with 20. Heun's method assumes smooth in ; exponential integrators assume it smooth in .
Guided sampling is harder on high-order solvers: large guidance scales amplify the network's output and its derivatives, which shrinks the step sizes at which those solvers stay stable, and early high-order samplers did worse than DDIM at strong guidance. DPM-Solver++ (Lu et al., 2022b) solves the ODE with the data prediction instead of , uses thresholding and a multistep variant, and reports high-quality guided samples in 15 to 20 steps.
Backbones: U-Nets and transformers
The U-Net, refined. Dhariwal & Nichol (2021) ablated DDPM's U-Net on ImageNet and settled on attention at the , and resolutions instead of only, more attention heads (64 channels per head), BigGAN-style residual blocks for up- and downsampling, and adaptive group normalization, which alone lowered FID from 15.08 to 13.06 in their ablation. This ADM architecture, with classifier guidance, beat BigGAN-deep's FID on ImageNet at several resolutions, and matched it with as few as 25 DDIM steps.
Transformers. DiT (Peebles & Xie, 2023) cuts the latent of a pretrained autoencoder into patches, giving tokens, adds sine–cosine position embeddings, and applies standard transformer blocks conditioned by adaLN-Zero (Guidance & Conditioning). Across 12 configurations of size and patch size, FID tracked forward-pass compute closely, with a correlation of with Gflops: higher compute, whether from depth, width or more tokens, consistently gave lower FID. Halving quadruples the tokens and the compute while barely changing the parameter count. DiT-XL/2, at 118.6 Gflops, reached FID 2.27 on class-conditional ImageNet with guidance.
| Backbone | Strengths | Costs |
|---|---|---|
| U-Net (DDPM, ADM, latent diffusion) | multi-scale features and skip connections suit dense, image-shaped outputs; strong at moderate compute | many hand-designed choices; attention only at low resolutions |
| Diffusion transformer (DiT and successors) | uniform blocks that scale predictably with compute; text and image tokens can share one sequence | attention cost grows with the square of the token count, so it relies on a compressive latent space and patches |
Key takeaways
- Every Gaussian diffusion model is a denoiser plus the ODE ; schedules and scalings reparameterize it, leaving exact solutions unchanged and altering only discretization error. With trajectories are nearly straight at both ends.
- EDM's preconditioning follows from unit-variance inputs and targets plus minimal error amplification: , , , ; -, - and -prediction are special cases.
- Training effort belongs at intermediate noise levels (EDM: ); every common objective is a weighted integral of ELBOs, and only the weight on each log-SNR matters.
- Schedules are maps to log-SNR: the cosine schedule fixes the linear schedule's wasted noisy tail, larger images need the SNR divided by the square of the downsampling factor, and the last step should reach zero SNR.
- Heun's method with steps crowded toward low noise () and exponential integrators such as DPM-Solver, whose first-order case is DDIM, sample well in tens of evaluations; DiT's FID tracks forward-pass compute.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Under EDM's preconditioning, what does the raw network effectively predict at very high noise, ?
- The noise , scaled by
- The clean image, scaled by : and
- Nothing: its output is multiplied by zero
- The noisy input itself
Show the answer
B. The clean image, scaled by : and
As , and , so : the network outputs the (normalized) clean image, and its errors are not amplified by as they would be under noise prediction.
Two samplers use the same trained denoiser but different schedules and scalings , and both integrate the probability-flow ODE exactly from the same noise. How do their outputs compare?
- They differ, because each schedule defines a different target distribution
- The variance-preserving one is more accurate, because it keeps the scale fixed
- They are identical: every choice reparameterizes time and space in the same canonical ODE, so only discretization errors depend on it
- They differ by a random amount, because the ODE is stochastic
Show the answer
C. They are identical: every choice reparameterizes time and space in the same canonical ODE, so only discretization errors depend on it
Karras et al. show that relabels time and rescales space in one canonical ODE. Exact solutions coincide; what the schedule changes is the curvature of trajectories in the solver's coordinates, and so the truncation error of a finite number of steps.
In EDM's step schedule, nearly equalizes the truncation error of each step, yet between 5 and 10 gives better images. What does that suggest?
- Errors at low noise levels, where fine detail is formed, matter more for image quality than errors of the same size at high noise
- Larger uses more network evaluations
- Truncation error is irrelevant to image quality
- High-noise steps should be shortened instead
Show the answer
A. Errors at low noise levels, where fine detail is formed, matter more for image quality than errors of the same size at high noise
Larger shortens the steps near at the expense of longer steps near . That it helps although it makes per-step errors unequal means errors made late in sampling are costlier, as Karras et al. concluded.
Further reading
- T. Karras, M. Aittala, T. Aila & S. Laine, "Elucidating the design space of diffusion-based generative models," NeurIPS (2022).
- A. Nichol & P. Dhariwal, "Improved denoising diffusion probabilistic models," ICML (2021).
- E. Hoogeboom, J. Heek & T. Salimans, "simple diffusion: End-to-end diffusion for high resolution images," ICML (2023).
- C. Lu, Y. Zhou, F. Bao, J. Chen, C. Li & J. Zhu, "DPM-Solver: A fast ODE solver for diffusion probabilistic model sampling in around 10 steps," NeurIPS (2022).
- W. Peebles & S. Xie, "Scalable diffusion models with transformers," ICCV (2023).