Uniform Stride Timestep Subsequence
Problem Statement
Fast samplers run on a sparse subset of the T training timesteps. Build the uniformly strided DDIM subsequence used by most implementations.
Background
To take S sampling steps out of T training steps, use a constant stride c = T // S and pick timesteps 0, c, 2c, ..., (S-1)c, then reverse them so sampling runs from high noise to low:
This is the "uniform" spacing from the DDIM paper (as opposed to "quadratic").
Your Task
Implement:
def ddim_timesteps(T, S):
Return the descending list of S timesteps.
Input Format
- T (int): number of training steps.
- S (int): number of sampling steps, 1 <= S <= T.
Output Format
- A list of S ints, descending.
Sample
print(ddim_timesteps(1000, 5))
Output:
[800, 600, 400, 200, 0]
Example
print(ddim_timesteps(1000, 5))
[800, 600, 400, 200, 0]
- Calculate the uniform stride by performing integer division of the total training steps by the sampling steps : .
- Generate the ascending sequence of timesteps by multiplying the stride by indices from to : .
- Reverse the ascending sequence to create the descending order required for sampling from high noise to low noise: .
- The final output is [800, 600, 400, 200, 0]
Constraints
1 <= S <= T <= 1000000.- Stride
c = T // S; timesteps are0, c, ..., (S-1)c, then reversed. - Return exactly
Sdescending ints.