Perform one ancestral sampling step of a DDPM, moving the whole batch from timestep t to timestep t−1.
μ=αt1(xt−1−αˉtβtϵ^),xt−1=μ+σtzHere xt is the current batch x_t, ϵ^ is predicted_noise, z is noise, and βt is betas at index t. The per-step signal fraction is αt=1−βt, and αˉt is the product of α0 through αt. Write αˉt−1 for the product up to t−1, with αˉ−1=1.
The variance σt2 depends on variance_type. For "fixed_large" it is βt. For "fixed_small" it is the posterior variance
β~t=βt1−αˉt1−αˉt−1.At t=0 the step returns μ alone and the noise is ignored, whatever the variance_type.
Return a PyTorch tensor with the same shape, dtype and device as x_t.
Input: x_t = [[[[0.8,-0.4],[1.2,0.1]]]], t = 2, predicted_noise = [[[[0.5,-1.0],[0.3,0.9]]]], betas = [0.1,0.2,0.3,0.4], noise = [[[[1.0,0.2],[-0.6,0.4]]]], variance_type = "fixed_small"
Output: [[[[1.113144,0.113347],[1.034618,-0.174086]]]]
Explanation: At t = 2 the cumulative products are 0.72 before and 0.504 at the step, so the noise coefficient is about 0.426, the mean is divided by about 0.837, and the posterior variance is about 0.169.
Input: x_t = [[[[0.8,-0.4],[1.2,0.1]]]], t = 2, predicted_noise = [[[[0.5,-1.0],[0.3,0.9]]]], betas = [0.1,0.2,0.3,0.4], noise = [[[[1.0,0.2],[-0.6,0.4]]]], variance_type = "fixed_large"
Output: [[[[1.249339,0.140586],[0.952901,-0.119608]]]]
Input: x_t = [[0.5,-0.5,1.0],[0.0,2.0,-1.5]], t = 0, predicted_noise = [[0.2,-0.1,0.4],[1.0,0.0,-0.3]], betas = [0.05,0.1,0.2], noise = [[1.0,-1.0,0.5],[0.3,0.8,-0.2]], variance_type = "fixed_large"
Output: [[0.467106,-0.490048,0.934212],[-0.229416,2.051957,-1.470143]]
torch.cumprod(1 - betas, dim=0) gives every alpha_bar at once.
Guard alpha_bars[t - 1] with a t > 0 check so index -1 does not wrap to the last entry.
Build the result with + rather than += or add_ so x_t stays unchanged.
Accepts: array
Accepts: integer
Accepts: array
Accepts: array
Accepts: array
Accepts: string
Perform one ancestral sampling step of a DDPM, moving the whole batch from timestep t to timestep t−1.
μ=αt1(xt−1−αˉtβtϵ^),xt−1=μ+σtzHere xt is the current batch x_t, ϵ^ is predicted_noise, z is noise, and βt is betas at index t. The per-step signal fraction is αt=1−βt, and αˉt is the product of α0 through αt. Write αˉt−1 for the product up to t−1, with αˉ−1=1.
The variance σt2 depends on variance_type. For "fixed_large" it is βt. For "fixed_small" it is the posterior variance
β~t=βt1−αˉt1−αˉt−1.At t=0 the step returns μ alone and the noise is ignored, whatever the variance_type.
Return a PyTorch tensor with the same shape, dtype and device as x_t.
Input: x_t = [[[[0.8,-0.4],[1.2,0.1]]]], t = 2, predicted_noise = [[[[0.5,-1.0],[0.3,0.9]]]], betas = [0.1,0.2,0.3,0.4], noise = [[[[1.0,0.2],[-0.6,0.4]]]], variance_type = "fixed_small"
Output: [[[[1.113144,0.113347],[1.034618,-0.174086]]]]
Explanation: At t = 2 the cumulative products are 0.72 before and 0.504 at the step, so the noise coefficient is about 0.426, the mean is divided by about 0.837, and the posterior variance is about 0.169.
Input: x_t = [[[[0.8,-0.4],[1.2,0.1]]]], t = 2, predicted_noise = [[[[0.5,-1.0],[0.3,0.9]]]], betas = [0.1,0.2,0.3,0.4], noise = [[[[1.0,0.2],[-0.6,0.4]]]], variance_type = "fixed_large"
Output: [[[[1.249339,0.140586],[0.952901,-0.119608]]]]
Input: x_t = [[0.5,-0.5,1.0],[0.0,2.0,-1.5]], t = 0, predicted_noise = [[0.2,-0.1,0.4],[1.0,0.0,-0.3]], betas = [0.05,0.1,0.2], noise = [[1.0,-1.0,0.5],[0.3,0.8,-0.2]], variance_type = "fixed_large"
Output: [[0.467106,-0.490048,0.934212],[-0.229416,2.051957,-1.470143]]
torch.cumprod(1 - betas, dim=0) gives every alpha_bar at once.
Guard alpha_bars[t - 1] with a t > 0 check so index -1 does not wrap to the last entry.
Build the result with + rather than += or add_ so x_t stays unchanged.
Accepts: array
Accepts: integer
Accepts: array
Accepts: array
Accepts: array
Accepts: string