Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix previous timestep of DDIMInverseScheduler #10778

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

stop1one
Copy link

What does this PR do?

Fixes #10695

Reproduction

import torch
import numpy as np
from diffusers import DDIMInverseScheduler

num_train_timesteps=1000
scheduler = DDIMInverseScheduler(num_train_timesteps=num_train_timesteps, timestep_spacing='leading')

inference_step = 10
scheduler.set_timesteps(inference_step)

# Before fix: The previous timestep can become negative.
previous_timesteps = torch.tensor([min(timestep - num_train_timesteps // inference_step, num_train_timesteps - 1) for timestep in scheduler.timesteps])
print('Previous Timestep\tCurrent timesteps')
for prev, cur in zip(previous_timesteps, scheduler.timesteps):
    print(f'{prev}\t\t\t{cur}')

# After fix
previous_timesteps = torch.tensor([min(timestep + num_train_timesteps // inference_step, num_train_timesteps - 1) for timestep in scheduler.timesteps])
print('Previous Timestep\tCurrent timesteps')
for prev, cur in zip(previous_timesteps, scheduler.timesteps):
    print(f'{prev}\t\t\t{cur}')

Just changed the sign when calculating the previous timestep.

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@yiyixuxu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DDIMInverseScheduler.step: Incorrect Previous Timestep Calculation
1 participant