PIXELBANKv9.1.0
Menu

Convert Loss Weights Between Parameterizations

Problem Statement

The simple eps-prediction loss corresponds to a specific SNR-dependent weight in the x0-prediction view. Given per-timestep SNRs, compute both the eps weight and the x0 weight.

Background

Training targets are related by x0-loss = SNR * eps-loss (per timestep). The DDPM "simple" objective uses a constant weight of 1 on the eps-loss. Reported in the x0 parameterization, that same objective carries weight SNR_t:

wtε=1,wtx0=SNRtw^{\varepsilon}_t = 1, \qquad w^{x_0}_t = \text{SNR}_t

Your Task

Implement:

def loss_weights(snr):
  • snr: list of per-timestep SNR values.

Return a dict with "eps" (list of 1.0s) and "x0" (list equal to the SNRs), values rounded to 4 decimals.

Input Format

  • snr: list of non-negative floats.

Output Format

  • A dict with two lists.

Sample

print(loss_weights([4.0, 1.0, 0.25]))

Output:

{'eps': [1.0, 1.0, 1.0], 'x0': [4.0, 1.0, 0.25]}

Example:

Input:
print(loss_weights([4.0, 1.0, 0.25]))
Output:
{'eps': [1.0, 1.0, 1.0], 'x0': [4.0, 1.0, 0.25]}
Reasoning:
  • The input list of Signal-to-Noise Ratios (SNRs) is [4.0,1.0,0.25][4.0, 1.0, 0.25]. The function requires two weight lists corresponding to the length of this input, which is 3.
  • For the "eps" parameterization, the weight is defined as a constant 11 for all timesteps. Thus, we generate a list of three 1.01.0 values: [1.0,1.0,1.0][1.0, 1.0, 1.0].
  • For the "x0" parameterization, the weight at each timestep tt is equal to the SNR at that timestep, i.e., wtx0=SNRtw^{x_0}_t = \text{SNR}_t. We map each input value to itself: 4.0→4.04.0 \to 4.0, 1.0→1.01.0 \to 1.0, and 0.25→0.250.25 \to 0.25.
  • Each value in the "x0" list is rounded to 4 decimal places. Since the input values 4.04.0, 1.01.0, and 0.250.25 are already precise to fewer than 4 decimal places, they remain unchanged: [4.0,1.0,0.25][4.0, 1.0, 0.25].
  • The final output is {'eps': [1.0, 1.0, 1.0], 'x0': [4.0, 1.0, 0.25]}

Constraints:

  • 1 <= len(snr) <= 100000, all snr[i] >= 0.
  • eps weight is 1.0 everywhere; x0 weight equals the SNR.
  • 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.
Convert Loss Weights Between Parameterizations - Easy | PixelBank