Deep-ML | Stable Diffusion 3: Logit-Normal, Mode and CosMap Timestep Samplers, Their Densities and Loss WeightsStable Diffusion 3: Logit-Normal, Mode and CosMap Timestep Samplers, Their Densities and Loss Weights
Stable Diffusion 3: Logit-Normal, Mode and CosMap Timestep Samplers, Their Densities and Loss Weights
At t=0.5 the uniform density is 1, the logit-normal with m=0,s=1 peaks at 4/2π, CosMap gives 4/π, the mode sampler with s=0 is uniform, a positive scale raises the middle and a negative scale lowers it.
Timestep Samplers for Rectified Flow: Logit-Normal, Mode and CosMap
Rectified flow is usually trained with t drawn uniformly from [0,1]. Esser and colleagues argue that the middle of the interval is the hard part and draw t from other densities π(t). Drawing t from π is the same as training uniformly with the loss weight wtπ=1−ttπ(t). Implement the samplers as maps from a uniform number u∈[0,1], their densities, and that weight.
The four kinds, with parameters m and s:
"uniform": t=u, π(t)=1.
"lognorm" (logit-normal with location m and scale s>0): t=σ(m+sΦ−1(u)) with σ the logistic function and Φ−1 the standard normal quantile, and
πln(t;m,s)=s2π1t(1−t)1exp(−2s2(logit(t)−m)2),logit(t)=log1−tt.
"mode" (scale s, allowed for −1≤s≤π−22): t=fmode(u;s)=1−u−s(cos2(2πu)−1+u), and πmode(t;s)=dtdfmode−1(t).
"cosmap": t=1−tan(2πu)+11 and πCosMap(t)=π−2πt+2πt22.
Write
timestep_from_uniform(kind, u, m=0.0, s=1.0),
timestep_density(kind, t, m=0.0, s=1.0),
equivalent_loss_weight(kind, t, m=0.0, s=1.0), which returns 1−ttπ(t).
Each accepts a float or a 1-D array and returns a float for a float input, or a NumPy array of the same shape for an array input.
Notes
fmode has no closed-form inverse: find fmode−1(t) numerically on [0,1] (it is decreasing there) to within 10−10.
Raise ValueError for an unknown kind, for "mode" with s outside its range, for "lognorm" with s≤0 or with u or t not strictly inside (0,1), and for other kinds with u or t outside [0,1]. equivalent_loss_weight also needs t<1.