PIXELBANKv9.1.0
Menu

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:

wt=min⁡(SNRt,γ)SNRtw_t = \frac{\min(\text{SNR}_t, \gamma)}{\text{SNR}_t}

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:

Input:
print(min_snr_weights([10.0, 5.0, 1.0], 5.0))
Output:
[0.5, 1.0, 1.0]
Reasoning:
  • For the first timestep with SNR=10.0\text{SNR} = 10.0, the SNR exceeds the clamp γ=5.0\gamma = 5.0, so the weight is calculated as min⁡(10.0,5.0)/10.0=5.0/10.0=0.5\min(10.0, 5.0) / 10.0 = 5.0 / 10.0 = 0.5.
  • For the second timestep with SNR=5.0\text{SNR} = 5.0, the SNR equals the clamp, resulting in a weight of min⁡(5.0,5.0)/5.0=5.0/5.0=1.0\min(5.0, 5.0) / 5.0 = 5.0 / 5.0 = 1.0.
  • For the third timestep with SNR=1.0\text{SNR} = 1.0, the SNR is below the clamp, so the weight remains min⁡(1.0,5.0)/1.0=1.0/1.0=1.0\min(1.0, 5.0) / 1.0 = 1.0 / 1.0 = 1.0.
  • The computed weights [0.5,1.0,1.0][0.5, 1.0, 1.0] 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, all snr[i] >= 0, gamma > 0.
  • w_t = min(SNR_t, gamma) / SNR_t; SNR_t == 0 gives 1.0.
  • Round to 4 decimals.
🔒

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.

solution.py

Test Results

0/0
Run code to see test results.
Min-SNR-Gamma Loss Weights - Medium | PixelBank