Skip to content

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

@cbprfCsun

Description

@cbprfCsun

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

System Info

Diffusers version: 0.35.2

Who can help?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions