Produce the noisy sample xt for every item in a batch by jumping straight from the clean data to its timestep in one step.
xt=αˉtx0+1−αˉtϵHere x0 holds the clean samples with the batch on the first axis, timesteps holds one integer timestep t per sample, alpha_bars is the cumulative schedule so that αˉt is alpha_bars at index t, and noise holds the Gaussian noise ϵ with the same shape as x0. Each sample uses its own timestep, so the two scalar factors differ from one sample to the next.
Return a PyTorch tensor with the same shape, dtype and device as x0.
Input: x0 = [[[[1.0,-1.0],[0.5,0.0]]],[[[0.2,0.4],[-0.6,0.8]]]], timesteps = [0,3], alpha_bars = [0.9,0.7,0.4,0.1], noise = [[[[0.3,0.1],[-0.2,1.0]]],[[[1.0,-1.0],[0.5,0.0]]]]
Output: [[[[1.043552,-0.91706],[0.411096,0.316228]]],[[[1.011929,-0.822192],[0.284605,0.252982]]]]
Explanation: Here timesteps is an int64 tensor that gives each image its own timestep. The first image uses alpha_bars[0] = 0.9, so it keeps a signal factor of about 0.949 and a noise factor of about 0.316. The second image uses alpha_bars[3] = 0.1, so its noise dominates.
Input: x0 = [[2.0,0.0,-2.0],[1.0,1.0,1.0]], timesteps = [1,1], alpha_bars = [0.99,0.64], noise = [[0.5,0.5,0.5],[-1.0,0.0,1.0]]
Output: [[1.9,0.3,-1.3],[0.2,0.8,1.4]]
Input: x0 = [[3.0,-3.0]], timesteps = [2], alpha_bars = [0.5,0.25,0.0], noise = [[0.7,-0.2]]
Output: [[0.7,-0.2]]
Indexing alpha_bars[timesteps] with the int64 timestep tensor gives one value per sample, with shape (B,).
Calling .view(-1, *([1] * (x0.dim() - 1))) on a (B,) tensor reshapes it to (B, 1, 1, ...) so it broadcasts against x0 of any rank.
torch.sqrt takes the elementwise square root of a tensor.
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Produce the noisy sample xt for every item in a batch by jumping straight from the clean data to its timestep in one step.
xt=αˉtx0+1−αˉtϵHere x0 holds the clean samples with the batch on the first axis, timesteps holds one integer timestep t per sample, alpha_bars is the cumulative schedule so that αˉt is alpha_bars at index t, and noise holds the Gaussian noise ϵ with the same shape as x0. Each sample uses its own timestep, so the two scalar factors differ from one sample to the next.
Return a PyTorch tensor with the same shape, dtype and device as x0.
Input: x0 = [[[[1.0,-1.0],[0.5,0.0]]],[[[0.2,0.4],[-0.6,0.8]]]], timesteps = [0,3], alpha_bars = [0.9,0.7,0.4,0.1], noise = [[[[0.3,0.1],[-0.2,1.0]]],[[[1.0,-1.0],[0.5,0.0]]]]
Output: [[[[1.043552,-0.91706],[0.411096,0.316228]]],[[[1.011929,-0.822192],[0.284605,0.252982]]]]
Explanation: Here timesteps is an int64 tensor that gives each image its own timestep. The first image uses alpha_bars[0] = 0.9, so it keeps a signal factor of about 0.949 and a noise factor of about 0.316. The second image uses alpha_bars[3] = 0.1, so its noise dominates.
Input: x0 = [[2.0,0.0,-2.0],[1.0,1.0,1.0]], timesteps = [1,1], alpha_bars = [0.99,0.64], noise = [[0.5,0.5,0.5],[-1.0,0.0,1.0]]
Output: [[1.9,0.3,-1.3],[0.2,0.8,1.4]]
Input: x0 = [[3.0,-3.0]], timesteps = [2], alpha_bars = [0.5,0.25,0.0], noise = [[0.7,-0.2]]
Output: [[0.7,-0.2]]
Indexing alpha_bars[timesteps] with the int64 timestep tensor gives one value per sample, with shape (B,).
Calling .view(-1, *([1] * (x0.dim() - 1))) on a (B,) tensor reshapes it to (B, 1, 1, ...) so it broadcasts against x0 of any rank.
torch.sqrt takes the elementwise square root of a tensor.
Accepts: array
Accepts: array
Accepts: array
Accepts: array