huggingface / huggingface/diffusers

FlowMatchEulerDiscreteScheduler Timesteps have Floating Point Errors

Open
#11,749 1 comment 0 reactions 1 assignee Claimed by @yiyixuxu View on GitHub
bug stale
Dominant language
Python
Stars
34.5k
Forks
7.3k
Avg merge
3d 3h
Merged PRs (30d)
91

Description

### Describe the bug

When using the index_for_timestep method from FlowMatchEulerDiscreteScheduler in scheduling_flow_match_euler_discrete.py, the self.timesteps variable after __init__ maintains floating point values for timesteps (by default, 1000 to 1). Some timestep values have floating point discrepancies that cause index lookups using (self.timesteps == query_timestep).nonzero() to return empty. This causes errors when calling the index_for_timestep function or any other functions that call index_for_timestep when using specific query timesteps.

As a monkeypatch, I applied the following after instantiating the scheduler
noise_scheduler.timesteps = torch.round(noise_scheduler.timesteps).to(dtype=torch.long)

### Reproduction
```python
from diffusers import FlowMatchEulerDiscreteScheduler
import torch

noise_scheduler = FlowMatchEulerDiscreteScheduler()
print(noise_scheduler.timesteps[746].item())
\# prints 254.00001525878906

query_timestep = torch.tensor([254]).to(dtype=torch.long)
print((noise_scheduler.timesteps == query_timestep).nonzero())
\# prints tensor([], size=(0, 1), dtype=torch.int64)
```

### Logs

```shell

```

### System Info

- Note, I found this bug on both Windows 11 and Linux

Windows:
- 🤗 Diffusers version: 0.33.1
- Platform: Windows-11-10.0.22000-SP0
- Running on Google Colab?: No
- Python version: 3.12.8
- PyTorch version (GPU?): 2.6.0+cu124 (True)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Huggingface_hub version: 0.33.0
- Transformers version: 4.48.1
- Accelerate version: 1.3.0
- PEFT version: 0.14.0
- Bitsandbytes version: not installed
- Safetensors version: 0.5.3
- xFormers version: not installed
- Accelerator: NVIDIA GeForce GTX 1080 Ti, 11264 MiB
- Using GPU in script?: Yes
- Using distributed or parallel set-up in script?: No

Linux:
- 🤗 Diffusers version: 0.33.1
- Platform: Linux-5.15.0-133-generic-x86_64-with-glibc2.35
- Running on Google Colab?: No
- Python version: 3.12.8
- PyTorch version (GPU?): 2.6.0+cu124 (True)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Huggingface_hub version: 0.33.0
- Transformers version: 4.48.1
- Accelerate version: 1.3.0
- PEFT version: 0.14.0
- Bitsandbytes version: not installed
- Safetensors version: 0.5.3
- xFormers version: not installed
- Accelerator: Quadro RTX 6000, 24576 MiB
Quadro RTX 6000, 24576 MiB
Quadro RTX 6000, 24576 MiB
Quadro RTX 6000, 24576 MiB
Quadro RTX 6000, 24576 MiB
Quadro RTX 6000, 24576 MiB
Quadro RTX 6000, 24576 MiB
Quadro RTX 6000, 24576 MiB
- Using GPU in script?: Yes
- Using distributed or parallel set-up in script?: No

### Who can help?

@yiyixuxu

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.