#149DDPM Reverse (Denoise) StepMedium

DDPM Reverse (Denoise) Step

Background

DDPM (Denoising Diffusion Probabilistic Models) sample by iteratively denoising: given the current noisy xtx_t and the model's noise prediction ϵ^\hat\epsilon, compute xt1x_{t-1} using the closed-form reverse update. Apply this TT to 11 to sample from the model. This problem isolates one reverse step.

Problem statement

Implement ddpm_reverse_step(x_t, eps_theta, t, betas, seed=None) using:

xt1  =  1αt(xt1αt1αˉtϵ^)+σtz,zN(0,I)x_{t-1} \;=\; \frac{1}{\sqrt{\alpha_t}}\Bigl(x_t - \frac{1-\alpha_t}{\sqrt{1-\bar\alpha_t}}\,\hat\epsilon\Bigr) + \sigma_t z,\quad z \sim \mathcal N(0, I)

where αt=1βt\alpha_t = 1 - \beta_t, αˉt=stαs\bar\alpha_t = \prod_{s \le t}\alpha_s, and σt=βt\sigma_t = \sqrt{\beta_t}. At t=0t = 0, no noise is added (deterministic).

Input

  • x_tnp.ndarray of any shape, the current noisy sample.
  • eps_thetanp.ndarray same shape, the model's noise prediction.
  • tint >= 0, the current diffusion step (in betas index).
  • betas — 1-D array of βt\beta_t values for t=0,1,,T1t = 0, 1, \dots, T-1.
  • seed — optional int for reproducibility.

Output

Returns np.ndarray of the same shape as x_t.

Examples

Example 1 — shape preserved

Input:  x_t=(3, 4) array, eps=(3, 4) array, betas=length-20, t=5
Output: (3, 4) array

Example 2 — t=0 is deterministic

Input:  any x, t=0
Output: identical across seeds (no noise term added)

Constraints

  • t must be a valid index into betas.
  • Use np.random.default_rng(seed) for the noise term so output is reproducible.
  • At t = 0, return the mean term only.

Notes

  • Variance scheduler. σt=βt\sigma_t = \sqrt{\beta_t} is the simpler choice; some implementations use β~t=1αˉt11αˉtβt\tilde\beta_t = \frac{1-\bar\alpha_{t-1}}{1-\bar\alpha_t}\beta_t. Either gives valid samples.
  • Iterating. A full sampler calls this TT times starting from xTN(0,I)x_T \sim \mathcal N(0, I).
Python
Loading...

▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.

  • reference: full reverse update at t=7 is deterministic given the seed
  • example: t=0 returns the deterministic mean term only
  • sample: 1-D input at t=3 matches the seeded reference