Sigmoid Beta Schedule
Problem Statement
The sigmoid schedule (popularized for higher-resolution training) shapes betas with a logistic curve so most of the noising happens in the middle of the trajectory. Build it.
Background
Take T points on a linear grid over [-6, 6], pass them through the logistic sigmoid sigma(x) = 1/(1+e^{-x}), then affinely rescale that curve so its minimum maps to beta_start and its maximum to beta_end:
stβ=Ο(β6+Tβ112tβ),Ξ²tβ=Ξ²startβ+sTβ1ββs0βstββs0ββ(Ξ²endββΞ²startβ)
so beta_0 = beta_start and beta_{T-1} = beta_end exactly.
Your Task
Implement:
def sigmoid_beta_schedule(T, beta_start, beta_end):
Return a list of T betas rounded to 6 decimals.
Input Format
- T (int), T >= 2.
- beta_start, beta_end (float): 0 < beta_start < beta_end < 1.
Output Format
- A list of T floats rounded to 6 decimals.
Sample
print(sigmoid_beta_schedule(3, 0.0001, 0.02))
Output:
[0.0001, 0.01005, 0.02]
Example:
print(sigmoid_beta_schedule(3, 0.0001, 0.02))
[0.0001, 0.01005, 0.02]
- Generate Grid Points: With T=3, we create a linear grid of 3 points spanning the interval [β6,6]. This yields the input values for the sigmoid function: x=[β6,0,6].
- Compute Sigmoid Values: We apply the logistic function Ο(x)=1+eβx1β to each point.
- For x=β6: Ο(β6)β0.002473
- For x=0: Ο(0)=0.5
- For x=6: Ο(6)β0.997527
- Normalize the Curve: We rescale the sigmoid outputs so the minimum maps to 0 and the maximum maps to 1 using the formula sTβ1ββs0βstββs0ββ.
- The range is sTβ1ββs0ββ0.997527β0.002473=0.995054.
- Normalized values:
- t=0: 0.9950540.002473β0.002473β=0
- t=1: 0.9950540.5β0.002473ββ0.499999
- t=2: 0.9950540.997527β0.002473β=1
- Affine Rescaling to Beta Range: We map the normalized values to the interval [Ξ²startβ,Ξ²endβ]=[0.0001,0.02] using Ξ²tβ=Ξ²startβ+normalizedtββ
(Ξ²endββΞ²startβ). The total range is 0.02β0.0001=0.0199.
- t=0: 0.0001+0β 0.0199=0.0001
- t=1: 0.0001+0.499999β 0.0199β0.01005
- t=2: 0.0001+1β 0.0199=0.02
- The final output is
[0.0001, 0.01005, 0.02]
Constraints:
T >= 2,0 < beta_start < beta_end < 1.- Grid is
[-6, 6]; rescale so endpoints hitbeta_start/beta_endexactly. - Round every beta to 6 decimals.
1. Background Knowledge
In denoising diffusion probabilistic models (DDPMs), the forward process gradually adds Gaussian noise to a data sample over T discrete timesteps. The amount of noise added at each step is controlled by a variance parameter Ξ²tβ, which must satisfy 0<Ξ²tβ<1. The choice of how Ξ²tβ varies with tβthe noise scheduleβsignificantly affects training stability and sample quality.
A linear schedule simply interpolates Ξ²tβ from Ξ²startβ to Ξ²endβ. However, for higher-resolution images, a sigmoid schedule performs better. It concentrates most of the noising in the middle of the trajectory, mimicking a smooth "S-curve." This is achieved by evaluating the logistic sigmoid function Ο(x)=1+eβx1β at evenly spaced points and then affinely rescaling the result so that the first and last values match the desired Ξ²startβ and Ξ²endβ exactly.
The key mathematical operation here is affine normalization: given a sequence stβ with known minimum s0β and maximum sTβ1β, you map it to a new range [Ξ²startβ,Ξ²endβ] via the formula Ξ²tβ=Ξ²startβ+sTβ1ββs0βstββs0ββ(Ξ²endββΞ²startβ). This guarantees the endpoints are exact while preserving the sigmoid shape in between.
2. Algorithm Approach
This is a direct formula evaluation problem. There is no iterative search or optimization. The approach is:
- Generate T evenly spaced input points on the interval [β6,6].
- Apply the sigmoid function to each point to obtain raw scores stβ.
- Compute the affine rescaling factor using s0β and sTβ1β.
- Apply the rescaling to every stβ to produce Ξ²tβ.
- Round each result to 6 decimal places and return as a list.
The entire computation is a single pass over T values with constant-time arithmetic per element.
3. Step-by-Step Strategy
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.