huggingface / huggingface/diffusers

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

Offen
#14,586 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
34.5k
Forks
7.3k
Ø Merge
3 T. 3 Std.
Gemergte PRs (30 T.)
91

Beschreibung

### 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

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python, pytorch
Bereich
machine-learning
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
30/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.