v-Target from x0 and Noise
Problem Statement
The v-prediction target (Salimans & Ho, 2022) is a signal/noise-balanced combination. Compute it from x0 and eps.
Background
The velocity target is
v=Ξ±ΛβΞ΅β1βΞ±Λβx0β
It equals eps at high noise and -x0 at low noise, which is what makes v-prediction stable across the whole schedule and the default for progressive distillation.
Your Task
Implement:
def v_target(x0, eps, alpha_bar):
Return v as a list rounded to 4 decimals.
Input Format
- x0, eps: lists of equal length D.
- alpha_bar (float) in (0, 1).
Output Format
- A list of D floats rounded to 4 decimals.
Sample
print(v_target([1.0, 0.0], [0.0, 1.0], 0.25))
Output:
[-0.866, 0.5]
Example:
print(v_target([1.0, 0.0], [0.0, 1.0], 0.25))
[-0.866, 0.5]
- Compute the scaling coefficients for the noise and signal components using Ξ±Λ=0.25: the noise weight is 0.25β=0.5 and the signal weight is 1β0.25β=0.75ββ0.8660.
- Calculate the v-prediction target for the first element (x0β=1.0, Ο΅=0.0) by combining the weighted terms: v0β=0.5β 0.0β0.8660β 1.0=β0.8660.
- Calculate the v-prediction target for the second element (x0β=0.0, Ο΅=1.0) using the same weights: v1β=0.5β 1.0β0.8660β 0.0=0.5.
- Round each result to 4 decimal places to satisfy the output format, yielding β0.866 and 0.5.
- The final output is [-0.866, 0.5]
Constraints:
len(x0) == len(eps),0 < alpha_bar < 1.v = sqrt(alpha_bar)*eps - sqrt(1 - alpha_bar)*x0.- Round to 4 decimals; avoid
-0.0.
1. Background Knowledge
In diffusion models, the forward process gradually adds Gaussian noise to a data point x0β over T timesteps. At any timestep t, the noisy sample xtβ can be expressed in closed form as:
xtβ=Ξ±Λtββx0β+1βΞ±ΛtββΞ΅
where Ξ±Λtβ=βs=1tβΞ±sβ is the cumulative product of per-step signal retention factors, and Ξ΅βΌN(0,I) is standard Gaussian noise. The parameter Ξ±Λtβ controls the signal-to-noise ratio: when Ξ±Λtββ1 (early timesteps), the sample is mostly signal; when Ξ±Λtββ0 (late timesteps), it is mostly noise.
The v-prediction parameterization (Salimans & Ho, 2022) defines a target velocity:
v=Ξ±ΛβΞ΅β1βΞ±Λβx0β
This is a linear combination of the noise and the clean signal, weighted by the same coefficients that appear in the forward process. The key property is that v smoothly transitions between Ξ΅ (when Ξ±Λβ1, high noise) and βx0β (when Ξ±Λβ0, low noise). This balanced behavior makes v-prediction numerically stable across the entire diffusion schedule and is the default choice in progressive distillation pipelines.
Understanding this target requires recognizing that it is simply a reparameterization of the same underlying Gaussian distribution. Given x0β and Ξ΅, computing v is a deterministic, element-wise operationβno optimization or iterative procedure is involved.
2. Algorithm Approach
This is a direct formula evaluation problem. The algorithm pattern is:
- Parse the input vectors and scalar.
- Compute the two scalar weights: wΞ΅β=Ξ±Λβ and wx0ββ=1βΞ±Λβ.
- For each element index i, compute viβ=wΞ΅ββ Ξ΅iββwx0βββ x0,iβ.
- Round each result to 4 decimal places.
There is no loop over timesteps, no gradient computation, and no iterative refinement. The entire computation is a single pass over the D-dimensional vectors.
3. Step-by-Step Strategy
Continue the full explanation
You're reading the free preview. Unlock the complete walkthrough, the code editor, test runner and reference solution with Premium.
Editor locked
The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.