Convert between v-prediction and x0/epsilon
Why it matters Stable Diffusion 2 and many video diffusion models are trained with v-prediction.
v-prediction trains the network on v = alpha * eps - sigma * x0, where x_t = alpha * x0 + sigma * eps with alpha^2 + sigma^2 = 1.
Write v_convert(x_t, v, alpha, sigma). Return (x0, eps) recovered from the model's v: x0 = alpha * x_t - sigma * v and eps = sigma * x_t + alpha * v.
def v_convert(x_t, v, alpha, sigma)Example
x0 = [1], eps = [0], alpha = 0.6, sigma = 0.8 gives x_t [0.6] and v [-0.8]; v_convert([0.6], [-0.8], 0.6, 0.8) returns x0 [1] and eps [0].
Understand the idea
A noisy sample mixes clean data and noise: x_t = alpha * x0 + sigma * eps, with alpha^2 + sigma^2 = 1. Instead of predicting eps or x0 directly, a v-prediction model predicts v = alpha * eps - sigma * x0. Because alpha^2 + sigma^2 = 1, the pair (x_t, v) is just a rotation of (x0, eps), so you can rotate back to recover both. Worked example: alpha 0.8, sigma 0.6, x0 = 2, eps = 1. x_t = 1.6 + 0.6 = 2.2 and v = 0.8 - 1.2 = -0.4. Recover: x0 = 0.8 * 2.2 - 0.6 * (-0.4) = 1.76 + 0.24 = 2.0, and eps = 0.6 * 2.2 + 0.8 * (-0.4) = 1.32 - 0.32 = 1.0. Both match. Rule: x0 = alpha * x_t - sigma * v and eps = sigma * x_t + alpha * v, element-wise on arrays. Watch the signs: the v term is subtracted for x0 and added for eps. You can check any answer by plugging x0 and eps back into the forward formulas. Used in: Stable Diffusion 2 style models, video diffusion and distillation methods that train on v.
Shapes and data flow
[x_t] [ alpha sigma] [x0 ] [ v ] = [-sigma alpha] [eps] inverse = transpose