huggingface / huggingface/diffusers

fixed_large_log variance sampling returns NaNs

Offen
#14,569 1 Kommentar 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 finding

`DDPMScheduler.step()` and `DDPMParallelScheduler.step()` treat `fixed_large_log` like an ordinary variance and take its square root. `_get_variance()` returns `log(current_beta_t)` for this mode, though, so the square root is applied to a negative value and the sample becomes `NaN`.

The intended scale is `exp(0.5 * log_variance)`, which is equivalent to the `sqrt(variance)` used by `fixed_large`.

I have a small fix ready for both scheduler implementations, along with CPU regression tests comparing `fixed_large_log` against the equivalent `fixed_large` sampling result. Happy to open the PR if this approach sounds right : )

### Reproduction

```python
import torch
from diffusers import DDPMScheduler, DDPMParallelScheduler

for scheduler_class in (DDPMScheduler, DDPMParallelScheduler):
scheduler = scheduler_class(variance_type="fixed_large_log")
sample = torch.zeros((1, 2, 2, 2))
model_output = torch.zeros_like(sample)
output = scheduler.step(
model_output,
500,
sample,
generator=torch.Generator().manual_seed(0),
).prev_sample
print(scheduler_class.__name__, torch.isnan(output).sum().item())
```

Current output:

```text
DDPMScheduler 8
DDPMParallelScheduler 8
```

Expected: both outputs are finite and match `fixed_large` when using the same generator.

### System info

- Diffusers version: `0.40.0.dev0` (`main` at `58eb52c`)
- Python: `3.12.13`
- PyTorch: `2.13.0+cu130`
- Platform: Linux
- GPU used by reproduction: No
- Distributed setup: No

@yiyixuxu

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Start at DDPMScheduler.step() and DDPMParallelScheduler.step(), then trace how _get_variance() is used for the fixed_large_log mode. Run the provided CPU reproduction and add regression coverage for both schedulers; done means outputs are finite and match fixed_large sampling with the same generator.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python, pytorch
Bereich
machine-learning, testing
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Aktiv
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
76/100

Neue Issues direkt in Ihr Postfach

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