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:
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
print(loss_weights([4.0, 1.0, 0.25]))
{'eps': [1.0, 1.0, 1.0], 'x0': [4.0, 1.0, 0.25]}- The input list of Signal-to-Noise Ratios (SNRs) is . 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 for all timesteps. Thus, we generate a list of three values: . - For the
"x0"parameterization, the weight at each timestep is equal to the SNR at that timestep, i.e., . We map each input value to itself: , , and . - Each value in the
"x0"list is rounded to 4 decimal places. Since the input values , , and are already precise to fewer than 4 decimal places, they remain unchanged: . - The final output is
{'eps': [1.0, 1.0, 1.0], 'x0': [4.0, 1.0, 0.25]}
Constraints
1 <= len(snr) <= 100000, allsnr[i] >= 0.epsweight is1.0everywhere;x0weight equals the SNR.- Round to 4 decimals.