DDIM Deterministic Step (eta = 0)
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β=Ξ±Λtββxtββ1βΞ±ΛtββΞ΅^β,xtβ²β=Ξ±Λtβ²ββx^0β+1βΞ±Λtβ²ββΞ΅^
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:
print(ddim_deterministic([1.4142, 0.0], [1.0, -1.0], 0.5, 1.0))
[1.0, 1.0]
- Compute the predicted clean sample x^0β using the formula x^0β=Ξ±Λtββxtββ1βΞ±ΛtββΞ΅^β. With Ξ±Λtβ=0.5, the scaling factors are 1β0.5β=0.5ββ0.7071 and 0.5ββ0.7071.
- For the first dimension, substitute xtβ=1.4142 and Ξ΅^=1.0: x^0,1β=0.70711.4142β(0.7071β 1.0)β=0.70710.7071β=1.0.
- For the second dimension, substitute xtβ=0.0 and Ξ΅^=β1.0: x^0,2β=0.70710.0β(0.7071β β1.0)β=0.70710.7071β=1.0. Thus, x^0β=[1.0,1.0].
- Compute the next state xtβ²β using xtβ²β=Ξ±Λtβ²ββx^0β+1βΞ±Λtβ²ββΞ΅^. Since Ξ±Λtβ²β=1.0, the coefficients are 1.0β=1.0 and 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].
- The final output is [1.0, 1.0]
Constraints:
len(x_t) == len(eps); alpha-bar values in(0, 1].alpha_bar_prev = 1.0yields exactlyx0_hat(the direction term vanishes).- Round to 4 decimals; avoid
-0.0.
1. Background Knowledge
DDPM (Denoising Diffusion Probabilistic Models) and DDIM (Denoising Diffusion Implicit Models) are two frameworks for sampling from a learned noise distribution. In DDPM, each reverse step is stochastic: you predict the noise Ξ΅^, estimate the clean signal x^0β, and then add fresh Gaussian noise to move to xtβ1β. DDIM generalizes this by introducing a parameter Ξ·β[0,1] that controls how much stochasticity remains. When Ξ·=0, the process becomes deterministic: the same predicted noise Ξ΅^ is reused as the "direction" toward the noisy sample, and no new random noise is injected.
The forward process defines Ξ±Λtβ=βs=1tβΞ±sβ, where Ξ±sβ=1βΞ²sβ. The noisy sample is xtβ=Ξ±Λtββx0β+1βΞ±ΛtββΞ΅. The model predicts Ξ΅^ from xtβ. From this prediction you can recover an estimate of the clean signal:
x^0β=Ξ±Λtββxtββ1βΞ±ΛtββΞ΅^β
For the deterministic DDIM step, you then reconstruct xtβ²β (where tβ²<t) by blending x^0β and Ξ΅^ using the previous alpha-bar value:
xtβ²β=Ξ±Λtβ²ββx^0β+1βΞ±Λtβ²ββΞ΅^
This is a linear combination, so the operation is element-wise over the feature dimension D.
2. Algorithm Approach
The problem reduces to two vectorized (or element-wise) arithmetic operations:
- Predict x^0β: For each dimension i, compute x^0β[i]=Ξ±Λtββxtβ[i]β1βΞ±Λtβββ Ξ΅^[i]β.
- Reconstruct xtβ²β: For each dimension i, compute xtβ²β[i]=Ξ±Λtβ²βββ x^0β[i]+1βΞ±Λtβ²βββ Ξ΅^[i].
No loops over timesteps are neededβthis is a single-step update. The key insight is that both Ξ±Λtββ and 1βΞ±Λtββ are scalars shared across all dimensions, so you compute them once and apply them element-wise.
3. Step-by-Step Strategy
Continue the full explanation
You're reading the free preview. Unlock the complete walkthrough, the code editor, test runner and reference solution with Premium.
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.