Min-SNR-Gamma Loss Weights
Problem Statement
The Min-SNR-gamma strategy (Hang et al., 2023) rebalances the multi-task diffusion loss by capping each timestep's weight. Compute the per-timestep weights for the common eps-prediction case.
Background
For eps-prediction, the Min-SNR weight clamps the SNR at gamma and normalizes by the SNR:
So high-SNR (low-noise, easy) steps get down-weighted toward gamma/SNR, while low-SNR steps keep weight 1. This stops the near-clean timesteps from dominating training.
Your Task
Implement:
def min_snr_weights(snr, gamma):
Return the list of weights rounded to 4 decimals. A timestep with SNR == 0 gets weight 1.0 (no down-weighting possible).
Input Format
- snr: list of non-negative SNRs.
- gamma (float): the clamp, typically 5.0.
Output Format
- A list of floats rounded to 4 decimals.
Sample
print(min_snr_weights([10.0, 5.0, 1.0], 5.0))
Output:
[0.5, 1.0, 1.0]
Example
print(min_snr_weights([10.0, 5.0, 1.0], 5.0))
[0.5, 1.0, 1.0]
- For the first timestep with , the SNR exceeds the clamp , so the weight is calculated as .
- For the second timestep with , the SNR equals the clamp, resulting in a weight of .
- For the third timestep with , the SNR is below the clamp, so the weight remains .
- The computed weights are already within 4 decimal places, so no further rounding changes are needed.
- The final output is
[0.5, 1.0, 1.0]
Constraints
1 <= len(snr) <= 100000, allsnr[i] >= 0,gamma > 0.w_t = min(SNR_t, gamma) / SNR_t;SNR_t == 0gives1.0.- Round to 4 decimals.