Projects / Denoising diffusion from scratch, three schedules and three parameterizations

Denoising diffusion from scratch, three schedules and three parameterizations

Jorge Tyrakowski

Image and Video Generation, National Yang Ming Chiao Tung University

Abstract

I implement DDPM [1] from scratch, the forward noising, the reverse sampler and the training loss, first on 2D Swiss-roll data and then on AFHQ animal faces, and compare three noise schedules (linear, quadratic, cosine) with three things the network can predict: the noise, the clean image x0x_0, or the posterior mean. Predicting x0x_0 gives the best FID with every schedule (1.20 with the quadratic one), but those samples are not the most natural, and two implementation fixes, one in the cosine schedule and one in the posterior-mean loss, changed the results more than any choice of schedule.

Noise schedules and parameterizations

The forward process adds Gaussian noise over T=1000T = 1000 steps, and a network learns to undo one step at a time. Given αˉt=∏s≤t(1−βs)\bar\alpha_t = \prod_{s \le t} (1 - \beta_s), a noisy sample at any step is drawn in closed form, and the standard objective trains the network to predict the noise that was added:

xt=αˉt x0+1−αˉt ϵ,L=Et,x0,ϵ∥ϵ−ϵθ(xt,t)∥2.x_t = \sqrt{\bar\alpha_t}\, x_0 + \sqrt{1 - \bar\alpha_t}\, \epsilon, \qquad \mathcal{L} = \mathbb{E}_{t, x_0, \epsilon} \big\lVert \epsilon - \epsilon_\theta(x_t, t) \big\rVert^2 .

The same network can instead predict x0x_0 or the posterior mean of xt−1x_{t-1}, and the schedule βt\beta_t can be linear, quadratic or cosine. On the Swiss roll, the from-scratch model reaches a Chamfer distance of 21.49 to the data (Figure 1). Figure 2 shows the reverse trajectories on AFHQ for each predictor.

Scatter plot of generated 2D samples overlapping the target Swiss-roll distribution.

DDPM samples (orange) against the Swiss-roll data (blue), Chamfer distance 21.49.

Rows of images going from noise to animal faces for the noise, x0 and posterior-mean predictors, with the linear schedule.

Reverse-diffusion trajectories on AFHQ with the linear schedule, from pure noise (left) to the sample (right), for the noise, x0x_0 and posterior-mean predictors.

FID on AFHQ (lower is better) for every predictor and schedule.

PredictorLinearQuadraticCosine
Noise8.379.0013.94 (fixed)
x0x_03.151.205.94
Posterior mean54.26 (SNR-weighted)64.4190.21

Two fixes mattered. The cosine schedule first failed completely with the noise predictor (FID 74.58): the usual clipping of βt\beta_t at 0.9999 affected 111 of the 1,000 steps, and clipping at 0.02, the linear schedule’s maximum, brought it to 13.94. The posterior-mean predictor was the weakest in every setting, and weighting its loss by the signal-to-noise ratio improved it from 87.40 to 54.26.

Eight generated animal faces from the x0 predictor with the quadratic schedule.

Samples of the x0x_0 predictor with the quadratic schedule, the best FID of the study (1.20).

Eight generated animal faces from the noise predictor with the linear schedule.

Samples of the noise predictor with the linear schedule (FID 8.37).

Despite the best FID, the x0x_0 samples often show distorted features, while the noise predictor’s faces look more natural (Figures 3 and 4). A lower FID did not guarantee perceptually better images, so the samples had to be judged by eye as well.

Findings

  • What the network predicts matters as much as the schedule: predicting x0x_0 gave the best FID with every schedule, and the posterior mean the worst.
  • Implementation details can break a schedule: one clipping value turned the cosine schedule from 74.58 to 13.94.
  • FID is not the whole story: the configuration with the best FID did not give the most natural faces.

References

  1. J. Ho, A. Jain and P. Abbeel. Denoising diffusion probabilistic models. NeurIPS, 2020.