Describe the bug
UnCLIPScheduler.set_timesteps breaks for fewer than 2 inference steps:
num_inference_steps == 1 crashes with a bare ZeroDivisionError;
num_inference_steps == 0 silently returns an empty timestep schedule.
Root cause: the scheduler uses the karlo-style inclusive-endpoint step ratio (num_train_timesteps - 1) / (num_inference_steps - 1) (see set_timesteps in scheduling_unclip.py). The docstring does not state a minimum, and UnCLIPPipeline forwards the user's value straight through, so the low value surfaces as an opaque crash instead of a clear error.
Since the schedule interpolates the two endpoints of the training range, num_inference_steps == 1 has no well-defined interval; validating up front (minimum 2 steps, like MiniMaxH3Scheduler already does for the same situation) seems more appropriate than defining n=1 numerics.
I found this while sweeping schedulers for low-step edge cases in an agentic coding session (root-cause analysis developed with AI assistance; I verified the reproduction and the code path locally). I have already opened a fix: #14574.
Reproduction
from diffusers import UnCLIPScheduler
scheduler = UnCLIPScheduler()
scheduler.set_timesteps(1) # ZeroDivisionError: division by zero
and
from diffusers import UnCLIPScheduler
scheduler = UnCLIPScheduler()
scheduler.set_timesteps(0) # no error; scheduler.timesteps is empty
print(scheduler.timesteps) # tensor([], dtype=torch.int64)
Logs
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "...\src\diffusers\schedulers\scheduling_unclip.py", line 191, in set_timesteps
step_ratio = (self.config.num_train_timesteps - 1) / (self.num_inference_steps - 1)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ZeroDivisionError: division by zero
System Info
- 🤗 Diffusers version: 0.40.0.dev0
- Platform: Windows-10-10.0.26200-SP0
- Running on Google Colab?: No
- Python version: 3.10.11
- PyTorch version (GPU?): 2.13.0+cpu (False)
- Huggingface_hub version: 1.28.0
- Transformers version: not installed
- Accelerate version: not installed
- PEFT version: not installed
- Safetensors version: 0.8.0
- xFormers version: not installed
- Accelerator: NVIDIA GeForce RTX 4060 Laptop GPU, 8188 MiB
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: No
Who can help?
@yiyixuxu
Describe the bug
UnCLIPScheduler.set_timestepsbreaks for fewer than 2 inference steps:num_inference_steps == 1crashes with a bareZeroDivisionError;num_inference_steps == 0silently returns an empty timestep schedule.Root cause: the scheduler uses the karlo-style inclusive-endpoint step ratio
(num_train_timesteps - 1) / (num_inference_steps - 1)(see set_timesteps in scheduling_unclip.py). The docstring does not state a minimum, andUnCLIPPipelineforwards the user's value straight through, so the low value surfaces as an opaque crash instead of a clear error.Since the schedule interpolates the two endpoints of the training range,
num_inference_steps == 1has no well-defined interval; validating up front (minimum 2 steps, likeMiniMaxH3Scheduleralready does for the same situation) seems more appropriate than defining n=1 numerics.I found this while sweeping schedulers for low-step edge cases in an agentic coding session (root-cause analysis developed with AI assistance; I verified the reproduction and the code path locally). I have already opened a fix: #14574.
Reproduction
and
Logs
System Info
Who can help?
@yiyixuxu