home/ atoms/ ddpm-sampling-reverse-loop

DDPM inference reverses the diffusion process: starting from noise, iteratively subtract predicted noise for T steps

To generate a new image with a trained DDPM, you: (1) sample x_T ~ N(0,I) (pure noise); (2) for each timestep t from T down to 1: use the network epsilon_theta(x_t, t) to predict the noise, compute the denoised mean, add a small amount of Gaussian noise (except at t=1); (3) return x_0. The mean at each step is computed from Equation 11: mu_theta = (1/sqrt(alpha_t)) * (x_t - beta_t/sqrt(1-alpha_bar_t) * epsilon_theta). The added noise at each step (except the last) prevents the process from collapsing to the mean. This is the expensive part of DDPM: generating one image requires T=1000 forward passes through the network.

Examples

Code: p_sample_loop iterates reversed(range(0, timesteps)), calling p_sample at each step. The full sample function wraps this for batches.

Assessment

Trace through one step of DDPM sampling: given x_t and a trained model, write the formula for computing x_{t-1}. Why is noise added at each step except t=1?

“Generating new images from a diffusion model happens by reversing the diffusion process: we start from TT, where we sample pure noise from a Gaussian distribution”
corpus · the-annotated-diffusion-model-hugging-face-ddpm-in-pytorch-s · chunk 12