-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Fix SDXL Refiner with Higher Order Schedulers #13453
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
Open
Beinsezii
wants to merge
1
commit into
huggingface:main
Choose a base branch
from
Beinsezii:beinsezii/fix_denoise_order
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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 |
|---|---|---|
|
|
@@ -666,18 +666,11 @@ def get_timesteps(self, num_inference_steps, strength, device, denoising_start=N | |
| ) | ||
| ) | ||
|
|
||
| num_inference_steps = (self.scheduler.timesteps < discrete_timestep_cutoff).sum().item() | ||
| if self.scheduler.order == 2 and num_inference_steps % 2 == 0: | ||
| # if the scheduler is a 2nd order scheduler we might have to do +1 | ||
| # because `num_inference_steps` might be even given that every timestep | ||
| # (except the highest one) is duplicated. If `num_inference_steps` is even it would | ||
| # mean that we cut the timesteps in the middle of the denoising step | ||
| # (between 1st and 2nd derivative) which leads to incorrect results. By adding 1 | ||
| # we ensure that the denoising process always ends after the 2nd derivate step of the scheduler | ||
| num_inference_steps = num_inference_steps + 1 | ||
|
Comment on lines
-670
to
-677
Contributor
Author
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. Based on this comment, it was previously hardcoded specifically for Heun's method, and anything else is 100% broken. Thing is, Heun appears to be the only higher order singlestep solver in Diffusers, so I guess we can't add tests for this yet? |
||
| real_timesteps = self.scheduler.timesteps[:: self.scheduler.order] | ||
| num_inference_steps = (real_timesteps < discrete_timestep_cutoff).sum().item() | ||
|
|
||
| # because t_n+1 >= t_n, we slice the timesteps starting from the end | ||
| t_start = len(self.scheduler.timesteps) - num_inference_steps | ||
| t_start = (len(real_timesteps) - num_inference_steps) * self.scheduler.order | ||
| timesteps = self.scheduler.timesteps[t_start:] | ||
| if hasattr(self.scheduler, "set_begin_index"): | ||
| self.scheduler.set_begin_index(t_start) | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically this might change the current results with Heun but it's necessary because otherwise it'll split wrong on a butcher tableaux with non-sequential coefficients like
Where it could split on stage 3, but the following stages contain lesser timestep values, and since the refiner is not trained on earlier timesteps this will lead to worse results.