huggingface / huggingface/diffusers

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

Aperta
#14,586 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
34.5k
Fork
7.3k
Merge medio
3g 3h
PR unite (30g)
91

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python, pytorch
Ambito
machine-learning
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
30/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.