PIXELBANKv9.1.0
Menu

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:

seq=[ (S−1)c,  (S−2)c,  …,  c,  0 ]\text{seq} = [\,(S-1)c,\; (S-2)c,\; \dots,\; c,\; 0\,]

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:

Input:
print(ddim_timesteps(1000, 5))
Output:
[800, 600, 400, 200, 0]
Reasoning:
  • Calculate the uniform stride cc by performing integer division of the total training steps TT by the sampling steps SS: c=1000//5=200c = 1000 // 5 = 200.
  • Generate the ascending sequence of timesteps by multiplying the stride cc by indices from 00 to S−1S-1: [0â‹…200,1â‹…200,2â‹…200,3â‹…200,4â‹…200]=[0,200,400,600,800][0 \cdot 200, 1 \cdot 200, 2 \cdot 200, 3 \cdot 200, 4 \cdot 200] = [0, 200, 400, 600, 800].
  • Reverse the ascending sequence to create the descending order required for sampling from high noise to low noise: [800,600,400,200,0][800, 600, 400, 200, 0].
  • The final output is [800, 600, 400, 200, 0]

Constraints:

  • 1 <= S <= T <= 1000000.
  • Stride c = T // S; timesteps are 0, c, ..., (S-1)c, then reversed.
  • Return exactly S descending ints.
🔒

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.

solution.py

Test Results

0/0
Run code to see test results.