Salimans and Ho (2022, Progressive Distillation for Fast Sampling of Diffusion Models) write the forward process as with and , and train the network to predict the velocity
Given and a prediction , both other targets follow: and . Implement four functions. Every array argument has shape (N, ...); alpha_bar is a scalar or an (N,) array of broadcast along the batch axis.
to_v(x0, eps, alpha_bar): return .v_to_eps(v, x_t, alpha_bar): return .v_to_x0(v, x_t, alpha_bar): return .prediction_losses(x0, eps, alpha_bar, v_pred, decimals=6): form and the true from x0, eps; convert v_pred to and ; return a dict with keys "v_loss", "eps_loss", "x0_loss", each the mean squared error over all elements of the batch, as floats rounded to decimals.The three losses are tied together: and , so for a scalar you must find eps_loss + x0_loss == v_loss and eps_loss / x0_loss == SNR.
(N,) alpha_bar to (N, 1, ..., 1) once, then compute and from it.v_to_eps(to_v(x0, eps, ab), x_t, ab) recovers eps exactly on a small example before writing the losses.