MONAI icon indicating copy to clipboard operation
MONAI copied to clipboard

timesteps in set_timesteps of DDPM and DDIM schedulers doesn't reach end point T (e.g. T= 1000)

Open AbrightWay opened this issue 2 months ago • 0 comments

I am reading the source code implementation of DDPM and DDIM schedulers, and I found this line defining timesteps for the schedulers timesteps = (np.arange(0, num_inference_steps) * step_ratio).round()[::-1].astype(np.int64)

np.arange(0, 100) doesn't return an array from 0 to 1000, it actually returns an array from 0 to 999. Therefore, if we have, say, step_ratio = 10, and num_inference_steps=100 for a model trained on DDPM of num_train_timesteps=1000, then the final self.timesteps would be a 1D array from 990 to 0, NOT 1000 to 0.

I think the right one is: timesteps = (np.arange(0, num_inference_steps + 1e-3) * step_ratio).round()[::-1].astype(np.int64) Here's the links for the schedulers:

  1. DDPM: https://github.com/Project-MONAI/MONAI/blob/69f3dd26ed2a65e89ae89d951bb16f2dcb4d7c5d/monai/networks/schedulers/ddpm.py#L128
  2. DDIM: https://github.com/Project-MONAI/MONAI/blob/69f3dd26ed2a65e89ae89d951bb16f2dcb4d7c5d/monai/networks/schedulers/ddim.py#L130

AbrightWay avatar Oct 24 '25 08:10 AbrightWay