v9.1.1
Menu

DDIM Deterministic Step (eta = 0)

easyPRODDPM and DDIM SamplingDiffusion ModelsDiffusion Models 1

Problem Statement

The deterministic DDIM update (eta = 0) is the workhorse of fast sampling. Implement one step given x_t, the predicted noise, and the two alpha-bar values.

Background

With eta = 0 there is no injected noise, so the update is

x^0=xt−1−αˉt ε^αˉt,xt′=αˉt′ x^0+1−αˉt′ ε^\hat{x}_0 = \frac{x_t - \sqrt{1 - \bar{\alpha}_t}\, \hat{\varepsilon}}{\sqrt{\bar{\alpha}_t}}, \qquad x_{t'} = \sqrt{\bar{\alpha}_{t'}}\, \hat{x}_0 + \sqrt{1 - \bar{\alpha}_{t'}}\, \hat{\varepsilon}

The same predicted noise is reused as the "direction pointing to x_t."

Your Task

Implement:

def ddim_deterministic(x_t, eps, alpha_bar_t, alpha_bar_prev):

Return x_{t'} as a list rounded to 4 decimals.

Input Format

  • x_t, eps: lists of length D.
  • alpha_bar_t, alpha_bar_prev (float) in (0, 1].

Output Format

  • A list of D floats rounded to 4 decimals.

Sample

print(ddim_deterministic([1.4142, 0.0], [1.0, -1.0], 0.5, 1.0))

Output:

[1.0, 1.0]

Example

Input
print(ddim_deterministic([1.4142, 0.0], [1.0, -1.0], 0.5, 1.0))
Output
[1.0, 1.0]
Reasoning
  • Compute the predicted clean sample x^0\hat{x}_0 using the formula x^0=xt−1−αˉt ε^αˉt\hat{x}_0 = \frac{x_t - \sqrt{1 - \bar{\alpha}_t}\, \hat{\varepsilon}}{\sqrt{\bar{\alpha}_t}}. With αˉt=0.5\bar{\alpha}_t = 0.5, the scaling factors are 1−0.5=0.5≈0.7071\sqrt{1 - 0.5} = \sqrt{0.5} \approx 0.7071 and 0.5≈0.7071\sqrt{0.5} \approx 0.7071.
  • For the first dimension, substitute xt=1.4142x_t = 1.4142 and ε^=1.0\hat{\varepsilon} = 1.0: x^0,1=1.4142−(0.7071⋅1.0)0.7071=0.70710.7071=1.0\hat{x}_{0,1} = \frac{1.4142 - (0.7071 \cdot 1.0)}{0.7071} = \frac{0.7071}{0.7071} = 1.0.
  • For the second dimension, substitute xt=0.0x_t = 0.0 and ε^=−1.0\hat{\varepsilon} = -1.0: x^0,2=0.0−(0.7071⋅−1.0)0.7071=0.70710.7071=1.0\hat{x}_{0,2} = \frac{0.0 - (0.7071 \cdot -1.0)}{0.7071} = \frac{0.7071}{0.7071} = 1.0. Thus, x^0=[1.0,1.0]\hat{x}_0 = [1.0, 1.0].
  • Compute the next state xt′x_{t'} using xt′=αˉt′ x^0+1−αˉt′ ε^x_{t'} = \sqrt{\bar{\alpha}_{t'}}\, \hat{x}_0 + \sqrt{1 - \bar{\alpha}_{t'}}\, \hat{\varepsilon}. Since αˉt′=1.0\bar{\alpha}_{t'} = 1.0, the coefficients are 1.0=1.0\sqrt{1.0} = 1.0 and 1−1.0=0.0\sqrt{1 - 1.0} = 0.0.
  • Apply the coefficients to the vectors: xt′=1.0⋅[1.0,1.0]+0.0⋅[1.0,−1.0]=[1.0,1.0]x_{t'} = 1.0 \cdot [1.0, 1.0] + 0.0 \cdot [1.0, -1.0] = [1.0, 1.0].
  • The final output is [1.0, 1.0]

Constraints

  • len(x_t) == len(eps); alpha-bar values in (0, 1].
  • alpha_bar_prev = 1.0 yields exactly x0_hat (the direction term vanishes).
  • Round to 4 decimals; avoid -0.0.

Learn this in

More from Diffusion Models 1

PRO

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test results

Sign in to run your code against the test cases.