All problems
DDIM Step
Problem
Perform one deterministic DDIM reverse step: first estimate pred_x0 = (x_t - sqrt(1 - alpha_bar_t) * eps_pred) / sqrt(alpha_bar_t), then return x_prev = sqrt(alpha_bar_prev) * pred_x0 + sqrt(1 - alpha_bar_prev) * eps_pred.
The signature is ddim_step(x_t, eps_pred, alpha_bar_t, alpha_bar_prev). All values are scalars.
Hint
DDIM removes the random noise term, giving deterministic sampling with fewer steps.
Test cases
case 1
in: [1,0,0.5,0.25]
expected: 0.7071067812
case 2
in: [0,1,0.25,0]
expected: 1
case 3
in: [2,0.5,0.25,0.25]
expected: 2
case 4
in: [1,1,1,1]
expected: 1
Starter codePython
import math
def ddim_step(x_t, eps_pred, alpha_bar_t, alpha_bar_prev):
# Your code here
pass4 test cases · run your code against them in the editor