-
Notifications
You must be signed in to change notification settings - Fork 6k
[scheduler] support custom timesteps
and sigmas
#7817
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
Merged
Changes from 13 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
8dfe500
support custom sigmas and timesteps, dpm euler
yiyixuxu b0017f4
support svd
yiyixuxu 967ee64
add AysSchedules to scheduling_utils
yiyixuxu 9a23c53
Merge branch 'main' into ays
sayakpaul e51cb15
diable num_inference_steps when timestep or sigmas is passed, add mor…
yiyixuxu b6aeeca
up
yiyixuxu 9d700f3
Merge branch 'ays' of github.com:huggingface/diffusers into ays
yiyixuxu 012687d
support heun and dpm single
yiyixuxu 3ddf2fe
fix heun timestep dtype, add tests
yiyixuxu 7d5e564
fix euler and add tests
yiyixuxu bd8e138
fix more
yiyixuxu eeac9ee
add pipeline test for ays
yiyixuxu 1c72f23
Update tests/schedulers/test_scheduler_dpm_multi.py
yiyixuxu 15e39e4
Apply suggestions from code review
yiyixuxu 0cb7805
add doc string for sigmas for all pipeilnes
yiyixuxu faff7bf
add doc page
yiyixuxu 2f896da
Merge branch 'main' into ays
yiyixuxu 80f6920
sdxl animatediff
yiyixuxu 4c4f7ba
up
yiyixuxu 2d54598
update pipeline docstring
yiyixuxu 56407ae
update oc
yiyixuxu 9cd36ef
Update docs/source/en/using-diffusers/schedulers.md
yiyixuxu 80ec506
up
yiyixuxu bc5eff4
Merge branch 'ays' of github.com:huggingface/diffusers into ays
yiyixuxu e70808e
fix
yiyixuxu aa82491
up
yiyixuxu 388d5d6
Update docs/source/en/using-diffusers/schedulers.md
yiyixuxu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,6 +137,7 @@ def retrieve_timesteps( | |
num_inference_steps: Optional[int] = None, | ||
device: Optional[Union[str, torch.device]] = None, | ||
timesteps: Optional[List[int]] = None, | ||
sigmas: Optional[List[float]] = None, | ||
**kwargs, | ||
): | ||
""" | ||
|
@@ -160,6 +161,8 @@ def retrieve_timesteps( | |
`Tuple[torch.Tensor, int]`: A tuple where the first element is the timestep schedule from the scheduler and the | ||
second element is the number of inference steps. | ||
""" | ||
if timesteps is not None and sigmas is not None: | ||
raise ValueError("Only one of `timesteps` or `sigmas` can be passed. Please choose one to set custom values") | ||
if timesteps is not None: | ||
accepts_timesteps = "timesteps" in set(inspect.signature(scheduler.set_timesteps).parameters.keys()) | ||
if not accepts_timesteps: | ||
|
@@ -170,6 +173,16 @@ def retrieve_timesteps( | |
scheduler.set_timesteps(timesteps=timesteps, device=device, **kwargs) | ||
timesteps = scheduler.timesteps | ||
num_inference_steps = len(timesteps) | ||
elif sigmas is not None: | ||
accept_sigmas = "sigmas" in set(inspect.signature(scheduler.set_timesteps).parameters.keys()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if it would be better to add a method to the scheduler, like |
||
if not accept_sigmas: | ||
raise ValueError( | ||
f"The current scheduler class {scheduler.__class__}'s `set_timesteps` does not support custom" | ||
f" sigmas schedules. Please check whether you are using the correct scheduler." | ||
) | ||
scheduler.set_timesteps(sigmas=sigmas, device=device, **kwargs) | ||
timesteps = scheduler.timesteps | ||
num_inference_steps = len(timesteps) | ||
else: | ||
scheduler.set_timesteps(num_inference_steps, device=device, **kwargs) | ||
timesteps = scheduler.timesteps | ||
|
@@ -750,6 +763,7 @@ def __call__( | |
width: Optional[int] = None, | ||
num_inference_steps: int = 50, | ||
timesteps: Optional[List[int]] = None, | ||
sigmas: Optional[List[float]] = None, | ||
guidance_scale: float = 7.5, | ||
strength: float = 0.8, | ||
negative_prompt: Optional[Union[str, List[str]]] = None, | ||
|
@@ -912,7 +926,9 @@ def __call__( | |
) | ||
|
||
# 4. Prepare timesteps | ||
timesteps, num_inference_steps = retrieve_timesteps(self.scheduler, num_inference_steps, device, timesteps) | ||
timesteps, num_inference_steps = retrieve_timesteps( | ||
self.scheduler, num_inference_steps, device, timesteps, sigmas | ||
) | ||
timesteps, num_inference_steps = self.get_timesteps(num_inference_steps, timesteps, strength, device) | ||
latent_timestep = timesteps[:1].repeat(batch_size * num_videos_per_prompt) | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.