Min-SNR Weights for v-Prediction
Problem Statement
Min-SNR weighting changes form with the prediction target. For v-prediction the effective weight uses SNR + 1 in the denominator. Compute it.
Background
Hang et al. give the Min-SNR weight per parameterization by dividing the clamped SNR by the parameterization's implicit weight:
- eps-pred: w = min(SNR, gamma) / SNR
- x0-pred: w = min(SNR, gamma)
- v-pred: w = min(SNR, gamma) / (SNR + 1)
The SNR + 1 denominator for v reflects that v-prediction already balances signal and noise, so its baseline weight is SNR + 1.
Your Task
Implement:
def min_snr_v_weights(snr, gamma):
Return the list of v-prediction Min-SNR weights rounded to 4 decimals.
Input Format
- snr: list of non-negative SNRs.
- gamma (float): the clamp.
Output Format
- A list of floats rounded to 4 decimals.
Sample
print(min_snr_v_weights([10.0, 4.0, 1.0], 5.0))
Output:
[0.4545, 0.8, 0.5]
Example:
print(min_snr_v_weights([10.0, 4.0, 1.0], 5.0))
[0.4545, 0.8, 0.5]
- For each SNR value, the weight is calculated using the v-prediction formula: w=SNR+1min(SNR,γ). The numerator clamps the SNR to the maximum value γ to prevent weights from becoming too large, while the denominator accounts for the signal-to-noise ratio plus one, specific to v-prediction.
- For the first input SNR=10.0 with γ=5.0, the numerator is min(10.0,5.0)=5.0 and the denominator is 10.0+1=11.0. The weight is 5.0/11.0≈0.454545, which rounds to 0.4545.
- For the second input SNR=4.0 with γ=5.0, the numerator is min(4.0,5.0)=4.0 and the denominator is 4.0+1=5.0. The weight is 4.0/5.0=0.8, which remains 0.8 when rounded to 4 decimals.
- For the third input SNR=1.0 with γ=5.0, the numerator is min(1.0,5.0)=1.0 and the denominator is 1.0+1=2.0. The weight is 1.0/2.0=0.5, which remains 0.5 when rounded to 4 decimals.
- The final output is [0.4545, 0.8, 0.5]
Constraints:
1 <= len(snr) <= 100000, allsnr[i] >= 0,gamma > 0.w_t = min(SNR_t, gamma) / (SNR_t + 1).- Round to 4 decimals.
1. Background Knowledge
In diffusion models, the training loss is often weighted by a function of the signal-to-noise ratio (SNR) to balance the contribution of different noise levels. The Min-SNR weighting scheme, introduced by Hang et al., addresses the issue that standard weighting can under- or over-emphasize certain timesteps. The core idea is to clamp the SNR at a threshold γ to prevent extreme weights.
The form of the weight depends on the prediction target (parameterization). For ϵ-prediction, the model predicts noise, and the implicit weight is proportional to 1/SNR. For x0-prediction, the model predicts the clean signal, and the implicit weight is proportional to 1. For v-prediction, the model predicts a velocity-like quantity that is a linear combination of the signal and noise. This parameterization inherently balances both components, leading to an implicit weight proportional to 1/(SNR+1).
The Min-SNR weight for a given parameterization is defined as the clamped SNR divided by the parameterization's implicit weight. For v-prediction, this results in the formula:
w=SNR+1min(SNR,γ)This ensures that for high SNR values (low noise), the weight is capped by γ/(SNR+1), while for low SNR values (high noise), the weight is SNR/(SNR+1), which approaches 1 as SNR becomes large but is small when SNR is near zero.
2. Algorithm Approach
The problem requires applying a vectorized mathematical operation to a list of SNR values. The approach involves:
- Iterating through each SNR value in the input list.
- Computing the clamped SNR: clamped_snr=min(snri,γ).
- Computing the denominator: denom=snri+1.
- Calculating the weight: wi=clamped_snr/denom.
- Rounding the result to 4 decimal places.
- Collecting all weights into a list.
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.