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

[docs] Clean scheduler api #4204

Merged
merged 7 commits into from
Aug 9, 2023
Merged

Conversation

stevhliu
Copy link
Member

This PR focuses on tidying up the Scheduler API section:

  • removes the design discussion around the scheduler API because this is already covered here
  • adds a table mapping k-diffusion/A1111 samplers to our schedulers (see A1111 <> Diffusers Scheduler mapping #4167)
  • removes [[autodoc]] for KarrasDiffusionSchedulers since it seems like it is more of a mapping?
  • aligns scheduler names in the toctree for consistency (important to use the same language everywhere to avoid confusion, for example DPM Discrete Scheduler --> KDPM2DiscreteScheduler)
  • reduced some extra content (like the abstract for the Common Diffusion Noise Schedules and Sample Steps are Flawed paper) for DDIMScheduler and put the changes in a Tips section
  • moves some of the extra content from the docstring into the Tips section (see DEISMultistepScheduler for example)
  • add expected SchedulerOutput for each scheduler
  • improve the readability of docstrings

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint.

@stevhliu stevhliu marked this pull request as ready for review July 31, 2023 18:18
Comment on lines -17 to -30
## What is a scheduler?

The schedule functions, denoted *Schedulers* in the library take in the output of a trained model, a sample which the diffusion process is iterating on, and a timestep to return a denoised sample. That's why schedulers may also be called *Samplers* in other diffusion models implementations.

- Schedulers define the methodology for iteratively adding noise to an image or for updating a sample based on model outputs.
- adding noise in different manners represent the algorithmic processes to train a diffusion model by adding noise to images.
- for inference, the scheduler defines how to update a sample based on an output from a pretrained model.
- Schedulers are often defined by a *noise schedule* and an *update rule* to solve the differential equation solution.

### Discrete versus continuous schedulers

All schedulers take in a timestep to predict the updated version of the sample being diffused.
The timesteps dictate where in the diffusion process the step is, where data is generated by iterating forward in time and inference is executed by propagating backwards through timesteps.
Different algorithms use timesteps that can be discrete (accepting `int` inputs), such as the [`DDPMScheduler`] or [`PNDMScheduler`], or continuous (accepting `float` inputs), such as the score-based schedulers [`ScoreSdeVeScheduler`] or [`ScoreSdeVpScheduler`].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be in favor of keeping this information. Any reason not to?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the information is still there, I just made it less wordy and more concise. The only information I removed is how schedulers are designed (this can be found in the Philosophy).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the commits, it felt like the sections (that should be present like this one) are entirely gone.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm that's strange, I can still see all the info there:

Screenshot 2023-08-02 at 10 26 39 AM

Copy link
Member

@sayakpaul sayakpaul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice start! Left a couple of general comments.

Let's try to make sure the CI tests pass :)

@stevhliu
Copy link
Member Author

stevhliu commented Aug 1, 2023

Let's try to make sure the CI tests pass :)

Any idea how to get this test to pass?

@sayakpaul
Copy link
Member

Hmm the failed test is very new to me. @patrickvonplaten any idea?

Copy link
Contributor

@patrickvonplaten patrickvonplaten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good to me! Regarding the test I would also have to go into to the PR to see what's going on. Can do this if no one manages - or is this test failing at other spots as well?

@yiyixuxu
Copy link
Collaborator

yiyixuxu commented Aug 3, 2023

@sayakpaul @patrickvonplaten @stevhliu

about the failing test, I think you need to manually update this reference code
https://github.com/huggingface/diffusers/blob/main/tests/others/test_check_copies.py#L33

@stevhliu
Copy link
Member Author

stevhliu commented Aug 3, 2023

Thank you so much @yiyixuxu, that did the trick! ❤️

Copy link
Member

@sayakpaul sayakpaul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for iterating!

@stevhliu stevhliu merged commit 16ad13b into huggingface:main Aug 9, 2023
8 checks passed
@stevhliu stevhliu deleted the clean-scheduler-api branch August 9, 2023 16:00
yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
* clean scheduler mixin

* up to dpmsolvermultistep

* finish cleaning

* first draft

* fix overview table

* apply feedback

* update reference code
AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
* clean scheduler mixin

* up to dpmsolvermultistep

* finish cleaning

* first draft

* fix overview table

* apply feedback

* update reference code
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.

None yet

5 participants