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

[Schedulers] Add exponential sigmas / exponential noise schedule #9499

Merged
merged 4 commits into from
Sep 23, 2024

Conversation

hlky
Copy link
Collaborator

@hlky hlky commented Sep 23, 2024

What does this PR do?

This PR adds exponential sigmas. Added only to Euler for now, after initial review we will add it to other schedulers, and add the other schedulers in the linked issue in subsequent PRs.

The implementation is quite simple, we add use_exponential_sigmas parameter and _convert_to_exponential function.

Example usage:

from diffusers import StableDiffusionXLPipeline, EulerDiscreteScheduler
import torch

pipeline: StableDiffusionXLPipeline = StableDiffusionXLPipeline.from_pretrained(
    "stabilityai/stable-diffusion-xl-base-1.0",
    variant="fp16",
    torch_dtype=torch.float16,
)
pipeline.scheduler = EulerDiscreteScheduler.from_config(
    pipeline.scheduler.config, timestep_spacing="linspace", use_exponential_sigmas=True
)

Note that we set timestep_spacing="linspace" in addition to use_exponential_sigmas=True, this is because XL's scheduler config uses timestep_spacing="leading" by default and the intent is to match results from the webuis where these noise schedules are currently used. We may wish to override timestep_spacing to linspace when use_exponential_sigmas=True or add a warning.

Tested against Forge (note that cuda device for generator is essential to match Forge results):

generator = torch.Generator("cuda").manual_seed(49136503742430)

image = pipeline(
    prompt="enormous kirby. space background",
    num_inference_steps=20,
    guidance_scale=5.0,
    generator=generator,
).images[0]
image

output

and with the same settings on Forge we get the same result:
00002-49136503742430

For reference with the default XL scheduler in Diffusers we get:
output2

#9490

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.
cc @asomoza @yiyixuxu

Copy link
Collaborator

@yiyixuxu yiyixuxu left a comment

Choose a reason for hiding this comment

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

thanks!

@yiyixuxu
Copy link
Collaborator

need a make style now

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Collaborator

@yiyixuxu yiyixuxu left a comment

Choose a reason for hiding this comment

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

thanks!

@yiyixuxu yiyixuxu merged commit 65f9439 into huggingface:main Sep 23, 2024
15 checks passed
@yiyixuxu
Copy link
Collaborator

thanks for the PR! this is cool and feel free to add to other schedulers!

leisuzz pushed a commit to leisuzz/diffusers that referenced this pull request Oct 11, 2024
…gingface#9499)

* exponential sigmas

* Apply suggestions from code review

Co-authored-by: YiYi Xu <[email protected]>

* make style

---------

Co-authored-by: YiYi Xu <[email protected]>
sayakpaul pushed a commit that referenced this pull request Dec 23, 2024
* exponential sigmas

* Apply suggestions from code review

Co-authored-by: YiYi Xu <[email protected]>

* make style

---------

Co-authored-by: YiYi Xu <[email protected]>
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.

3 participants