huggingface / huggingface/diffusers

DDIMScheduler.step() logic mismatches set_timesteps() list when using timestep_spacing='linspace'

Open
#12,633 1 comment 0 reactions 0 assignees 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

The step() function calculates prev_timestep using a hard-coded formula:
`prev_timestep = timestep - self.config.num_train_timesteps // self.num_inference_steps.`
https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/scheduling_ddim.py#L402

However, if the scheduler is initialized with timestep_spacing="linspace", the preve_timestep is not match the set_timesteps.

Suggested Method to Fix:
This inconsistency could be resolved by modifying the step() function to look up the correct prev_timestep from the self.timesteps list directly, just as in DDPMScheduler.
https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/scheduling_ddpm.py#L549

### Reproduction

```
scheduler = DDIMScheduler.from_pretrained(model_id, subfolder='scheduler', timestep_spacing="linspace")
scheduler.set_timesteps(10)
prev_timesteps = []
for t in scheduler.timesteps:
prev_t = t- 1000 // num_inference_steps
prev_timesteps.append(prev_t.item())
```

### Logs

```shell

```

### System Info

Diffusers version: 0.35.2

### Who can help?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start in src/diffusers/schedulers/scheduling_ddim.py at DDIMScheduler.step() and compare its previous-timestep calculation with the lookup used in src/diffusers/schedulers/scheduling_ddpm.py. Run the linspace reproduction with set_timesteps(10) and verify that step() follows the corresponding self.timesteps entry for every timestep.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.