Terminal SNR and the Zero-SNR Fix
Problem Statement
Common schedules never fully destroy the signal: at the last step alpha_bar_T is slightly above 0, leaking image information the sampler can never remove. Detect this and apply the "enforce zero terminal SNR" rescaling from Lin et al. (2024).
Background
The signal-to-noise ratio at step t is SNR_t = alpha_bar_t / (1 - alpha_bar_t). A schedule has zero terminal SNR iff alpha_bar_T = 0. The fix rescales the sqrt(alpha_bar) curve linearly so its first value is unchanged and its last value becomes 0:
αˉt​​′=αˉ0​​−αˉT​​αˉt​​−αˉT​​​⋅αˉ0​​
then square back to get the corrected alpha_bar.
Your Task
Implement:
def fix_zero_terminal_snr(alpha_bar):
Return the corrected alpha_bar list rounded to 6 decimals. The last value must be exactly 0.0.
Input Format
- alpha_bar: list of T cumulative products (decreasing).
Output Format
- A list of T floats rounded to 6 decimals.
Sample
print(fix_zero_terminal_snr([0.81, 0.36, 0.04]))
Output:
[0.81, 0.26449, 0.0]
Example:
print(fix_zero_terminal_snr([0.81, 0.36, 0.04]))
[0.81, 0.26449, 0.0]
- Compute the square roots of the input values to work in the αˉ​ domain: 0.81​=0.9, 0.36​=0.6, and 0.04​=0.2.
- Identify the first (s0​=0.9) and last (sT​=0.2) values to determine the linear rescaling range, which is s0​−sT​=0.9−0.2=0.7.
- Apply the linear transformation s0​−sT​s−sT​​⋅s0​ to each element to shift the curve so the last value becomes zero while keeping the first value unchanged:
- For the first element: 0.70.9−0.2​⋅0.9=1⋅0.9=0.9
- For the second element: 0.70.6−0.2​⋅0.9=0.70.4​⋅0.9≈0.514286
- For the last element: 0.70.2−0.2​⋅0.9=0
- Square the rescaled values to return to the αˉ domain and round to 6 decimal places:
- 0.92=0.81
- (0.514286)2≈0.26449
- 02=0.0
- The final output is
[0.81, 0.26449, 0.0]
Constraints:
2 <= T <= 100000.- Rescale the
sqrt(alpha_bar)curve so the first value is preserved and the last hits 0. - Square back; the final value is exactly
0.0; round to 6 decimals.
1. Background Knowledge
In diffusion models, the forward process gradually adds Gaussian noise to a data sample x0​ over T discrete steps. The state at step t is defined as xt​=αˉt​​x0​+1−αˉt​​ϵ, where ϵ∼N(0,I). The term αˉt​ represents the cumulative product of noise schedule parameters αi​=1−βi​ up to step t. As t increases, αˉt​ decreases, meaning less signal and more noise.
The Signal-to-Noise Ratio (SNR) at step t is given by SNRt​=1−αˉt​αˉt​​. Ideally, at the final step T, the SNR should be zero, implying αˉT​=0. This ensures that xT​ is pure noise, containing no information about the original image x0​. However, many standard noise schedules (like cosine or linear) result in αˉT​>0, leaving a small amount of signal leakage. This leakage can degrade the quality of generated samples because the sampler cannot fully "forget" the original data.
The Zero-Terminal SNR fix, proposed by Lin et al. (2024), corrects this by rescaling the αˉt​​ curve. The goal is to preserve the shape of the noise schedule while forcing the final value to zero. This is done by linearly interpolating the square root of αˉt​ between its initial value and zero, then squaring the result back to obtain the corrected αˉt​.
2. Algorithm Approach
The approach involves a simple linear transformation on the square root of the input array:
- Extract endpoints: Identify αˉ0​​ (first element) and αˉT​​ (last element).
- Linear rescaling: For each element αˉt​​, apply the formula:
This maps αˉ0​​ to itself and αˉT​​ to 0. 3. Square back: Compute αˉt′​=(αˉt​​′)2. 4. Round and enforce: Round each value to 6 decimal places and explicitly set the last element to 0.0.
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.