T2I-Adapter icon indicating copy to clipboard operation
T2I-Adapter copied to clipboard

Bug Report: Illegal timesteps

Open LazyChild opened this issue 2 years ago • 0 comments

Branch: main Bug description: In lines 674-676 of train_sketch.py, when calculating the timesteps variable, it may generate an illegal timesteps = 1000, causing an assertion error when running the training script. The specific reason for the error is that the numbers generated by torch.rand() fall within the range [0, 1), and after cubing, values within [0,1) will decrease. Due to machine truncation, they are considered to be 0, leading to an illegal result while executing timesteps = (1 - timesteps**3) * noise_scheduler.config.num_train_timesteps resulting in program crash.

Here is a simple reproduction: image

The following is the error line, located in the scheduling_ddpm.py file within the diffusers library. Accessing alphas_cumprod[1000] causes an index out of bounds error, as alphas_cumprod[] is a tensor of length 1000, leading to a program crash. image

Solution: Replace timesteps = (1 - timesteps**3) * noise_scheduler.config.num_train_timesteps with timesteps = (1 - timesteps**3) * (noise_scheduler.config.num_train_timesteps - 1)

LazyChild avatar Apr 28 '24 14:04 LazyChild