Perform one DDIM update that moves the whole batch from timestep t to timestep t_prev, and return the new sample together with the predicted clean sample.
Let αˉt be alpha_bars at index t and αˉprev be alpha_bars at index t_prev, or exactly 1 when t_prev is -1. With x_t, the noise prediction ϵ^ (predicted_noise) and fresh noise z (noise),
x^0=αˉtxt−1−αˉtϵ^,σ=η1−αˉt1−αˉprev1−αˉprevαˉt xprev=αˉprevx^0+1−αˉprev−σ2ϵ^+σzHere η is eta. When clip_sample is true, first clamp x^0 to [-1, 1], then recompute ϵ^=(xt−αˉtx^0)/1−αˉt from the clamped value, and use both in the update. Clamp the term under the direction square root at 0 before taking the root.
Return a dict with the keys "x_prev" and "pred_x0" (the possibly clamped x^0), each a PyTorch tensor with the shape, dtype and device of x_t.
Input: x_t = [[[[0.5,-1.2],[0.8,0.1]]]], predicted_noise = [[[[0.3,-0.7],[1.1,0.2]]]], t = 3, t_prev = 1, alpha_bars = [0.9,0.7,0.5,0.3,0.1], eta = 0.0, noise = [[[[0.4,1.0],[-0.5,-0.2]]]], clip_sample = False
Output: {"x_prev":[[[[0.544674,-1.321823],[0.418694,0.006693]]]],"pred_x0":[[[[0.454613,-1.121623],[-0.219684,-0.122931]]]]}
Explanation: With alpha_bars[3] = 0.3 the first pixel gives pred_x0 = (0.5 - sqrt(0.7) 0.3) / sqrt(0.3), about 0.4546. Since eta = 0 there is no noise, and x_prev = sqrt(0.7) pred_x0 + sqrt(0.3) predicted_noise, about 0.5447.
Input: x_t = [[[[0.5,-1.2],[0.8,0.1]]]], predicted_noise = [[[[0.3,-0.7],[1.1,0.2]]]], t = 3, t_prev = 1, alpha_bars = [0.9,0.7,0.5,0.3,0.1], eta = 1.0, noise = [[[[0.4,1.0],[-0.5,-0.2]]]], clip_sample = True
Output: {"x_prev":[[[[0.648727,-0.524795],[-0.173025,-0.154878]]]],"pred_x0":[[[[0.454613,-1.0],[-0.219684,-0.122931]]]]}
Input: x_t = [[0.9,-0.3,0.2]], predicted_noise = [[0.5,0.1,-0.4]], t = 0, t_prev = -1, alpha_bars = [0.8,0.5,0.2], eta = 0.5, noise = [[1.0,-1.0,0.5]], clip_sample = False
Output: {"x_prev":[[0.756231,-0.38541,0.423607]],"pred_x0":[[0.756231,-0.38541,0.423607]]}
Read alpha_bars[t_prev] only when t_prev >= 0; otherwise use 1.
torch.clamp(pred_x0, -1.0, 1.0) clips the clean estimate.
.clamp_min(0) keeps a square-root argument non-negative.
Accepts: array
Accepts: array
Accepts: integer
Accepts: integer
Accepts: array
Accepts: number
Accepts: array
Perform one DDIM update that moves the whole batch from timestep t to timestep t_prev, and return the new sample together with the predicted clean sample.
Let αˉt be alpha_bars at index t and αˉprev be alpha_bars at index t_prev, or exactly 1 when t_prev is -1. With x_t, the noise prediction ϵ^ (predicted_noise) and fresh noise z (noise),
x^0=αˉtxt−1−αˉtϵ^,σ=η1−αˉt1−αˉprev1−αˉprevαˉt xprev=αˉprevx^0+1−αˉprev−σ2ϵ^+σzHere η is eta. When clip_sample is true, first clamp x^0 to [-1, 1], then recompute ϵ^=(xt−αˉtx^0)/1−αˉt from the clamped value, and use both in the update. Clamp the term under the direction square root at 0 before taking the root.
Return a dict with the keys "x_prev" and "pred_x0" (the possibly clamped x^0), each a PyTorch tensor with the shape, dtype and device of x_t.
Input: x_t = [[[[0.5,-1.2],[0.8,0.1]]]], predicted_noise = [[[[0.3,-0.7],[1.1,0.2]]]], t = 3, t_prev = 1, alpha_bars = [0.9,0.7,0.5,0.3,0.1], eta = 0.0, noise = [[[[0.4,1.0],[-0.5,-0.2]]]], clip_sample = False
Output: {"x_prev":[[[[0.544674,-1.321823],[0.418694,0.006693]]]],"pred_x0":[[[[0.454613,-1.121623],[-0.219684,-0.122931]]]]}
Explanation: With alpha_bars[3] = 0.3 the first pixel gives pred_x0 = (0.5 - sqrt(0.7) 0.3) / sqrt(0.3), about 0.4546. Since eta = 0 there is no noise, and x_prev = sqrt(0.7) pred_x0 + sqrt(0.3) predicted_noise, about 0.5447.
Input: x_t = [[[[0.5,-1.2],[0.8,0.1]]]], predicted_noise = [[[[0.3,-0.7],[1.1,0.2]]]], t = 3, t_prev = 1, alpha_bars = [0.9,0.7,0.5,0.3,0.1], eta = 1.0, noise = [[[[0.4,1.0],[-0.5,-0.2]]]], clip_sample = True
Output: {"x_prev":[[[[0.648727,-0.524795],[-0.173025,-0.154878]]]],"pred_x0":[[[[0.454613,-1.0],[-0.219684,-0.122931]]]]}
Input: x_t = [[0.9,-0.3,0.2]], predicted_noise = [[0.5,0.1,-0.4]], t = 0, t_prev = -1, alpha_bars = [0.8,0.5,0.2], eta = 0.5, noise = [[1.0,-1.0,0.5]], clip_sample = False
Output: {"x_prev":[[0.756231,-0.38541,0.423607]],"pred_x0":[[0.756231,-0.38541,0.423607]]}
Read alpha_bars[t_prev] only when t_prev >= 0; otherwise use 1.
torch.clamp(pred_x0, -1.0, 1.0) clips the clean estimate.
.clamp_min(0) keeps a square-root argument non-negative.
Accepts: array
Accepts: array
Accepts: integer
Accepts: integer
Accepts: array
Accepts: number
Accepts: array