huggingface / huggingface/diffusers

UnCLIPScheduler.set_timesteps crashes (ZeroDivisionError) for 1 step and silently returns an empty schedule for 0 steps

Open
#14,586 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
34.5k
Forks
7.3k
Avg merge
3d 3h
Merged PRs (30d)
91

Description

### 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](https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/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

```python
from diffusers import UnCLIPScheduler

scheduler = UnCLIPScheduler()
scheduler.set_timesteps(1) # ZeroDivisionError: division by zero
```

and

```python
from diffusers import UnCLIPScheduler

scheduler = UnCLIPScheduler()
scheduler.set_timesteps(0) # no error; scheduler.timesteps is empty
print(scheduler.timesteps) # tensor([], dtype=torch.int64)
```

### Logs

```shell
Traceback (most recent call last):
File "", line 1, in
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

Contributor guide

Open the contributing guide

Research direction

Start in src/diffusers/schedulers/scheduling_unclip.py at UnCLIPScheduler.set_timesteps and compare its handling with the MiniMaxH3Scheduler validation. Reproduce the one-step and zero-step cases, then inspect fix #14574; done means both invalid inputs produce the intended clear validation error rather than a division error or empty schedule.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.