-
Notifications
You must be signed in to change notification settings - Fork 6.1k
[Scheduler design] The pragmatic approach #719
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
Conversation
The documentation is not available anymore as the PR was closed or merged. |
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py
Outdated
Show resolved
Hide resolved
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py
Outdated
Show resolved
Hide resolved
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py
Outdated
Show resolved
Hide resolved
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.
Awesome, love this API design - think it's slim and should solve 99% of our problems! Actually maybe no need after all to have a SchedulerType.CONTINUOUS
then after all in a first step 😍
The slow tests pass ✔️ |
timesteps = timesteps.to(original_samples.device) | ||
step_indices = [(schedule_timesteps == t).nonzero().item() for t in timesteps] |
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.
Really dislike what we have to do here, but unfortunately there's no good vectorized alternative to search for multiple indices and keep the order the same.
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.
don't think it's that bad honestly
Really cool - like this new design a lot! Think we can merge this tomorrow 😍 Some final TODOs / suggestions:
|
if not self.is_scale_input_called: | ||
warnings.warn( | ||
"The `scale_model_input` function should be called before `step` to ensure correct denoising. " | ||
"See `StableDiffusionPipeline` for a usage example." | ||
) |
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.
This will pop up in existing community pipelines but won't break them like an exception would. The legacy pipelines can continue using the manual scaling code 👍
@@ -226,6 +226,27 @@ def recursive_check(tuple_object, dict_object): | |||
|
|||
recursive_check(outputs_tuple, outputs_dict) | |||
|
|||
def test_scheduler_public_api(self): |
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.
Very nice!
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.
Very nice! Happy to merge and help you update existing notebooks / docs / blog post now:
- Update PR description that states exactly what people have to change if they have written their own custom loop. E.g. If you have been using the K-LMS scheduler, please make sure to do the following:
- If you have been using other schedulers, no need to change anything, but we recomend for generality to always make use of
init_sigma
andscale_model_input
- All blog posts
- All notebooks
- All training examples
* init * improve add_noise * [debug start] run slow test * [debug end] * quick revert * Add docstrings and warnings + API tests * Make the warning less spammy
* init * improve add_noise * [debug start] run slow test * [debug end] * quick revert * Add docstrings and warnings + API tests * Make the warning less spammy
This schedulers API redesign addresses concerns raised in #336 and starts to make the schedulers interchangeable without making scheduler class-dependent customizations to pipelines.
init_noise_sigma
parameter to scale the normal distribution of the initial noise. While it is just1.0
for DDPM, DDIM and PNDM, it is customized for the VE and K-LMS schedulers.Example usage:
scale_model_input(sample, timestep)
(even if it just returns thesample
) that scales the denoising model's input based on the currenttimestep
. The method should be called before everymodel()
call.Example usage:
Note: the decision to not make it a base class method is intentional, as suggested by @patrickvonplaten
Closes #336