Skip to content

Conversation

@StAlKeR7779
Copy link
Contributor

@StAlKeR7779 StAlKeR7779 commented Aug 6, 2024

What does this PR do?

This pull request addresses two issues:

Incorrect output in DPMSolverSinglestepScheduler

Fixed the issue where using solver_order=3 and a step count of 3n-1 resulted in incorrect output. The problem was caused by improper handling of final_sigmas_type=zero, leading to a log(0) error in the singlestep_dpm_solver_second_order_update function. The handling has been implemented in the simplest possible way, and I welcome any suggestions how it can done better.

Support for sde-dpmsolver++ in third order

Added support for the sde-dpmsolver++ algorithm to both the DPMSolverSinglestepScheduler and DPMSolverMultistepScheduler. Previously, using solver_order=3 would throw an error:
UnboundLocalError: local variable 'x_t' referenced before assignment
This was due to the lack of a branch to handle the sde-dpmsolver++ algorithm in the singlestep_dpm_solver_third_order_update and multistep_dpm_solver_third_order_update functions. My implementation is based on how the sde is already integrated into first and second-order solvers, so please review carefully to ensure correctness.

Fixes # (issue)
#9007

Who can review?

@yiyixuxu
@LuChengTHU (sorry if wrongly tag you)

@StAlKeR7779 StAlKeR7779 changed the title Stalker7779/dpmpp3 fixes DPM++ third order fixes Aug 6, 2024
@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

@github-actions github-actions bot added the stale Issues that haven't received updates label Sep 14, 2024
@yiyixuxu yiyixuxu removed the stale Issues that haven't received updates label Dec 3, 2024
@yiyixuxu
Copy link
Collaborator

yiyixuxu commented Dec 3, 2024

can you take a look here? @hlky

@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
Contributor

@hlky hlky left a comment

Choose a reason for hiding this comment

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

Thanks @StAlKeR7779! 🤗

Test
from diffusers import DPMSolverSinglestepScheduler, DPMSolverMultistepScheduler, StableDiffusionXLPipeline
import torch

solver_order = 3
algorithm_type = "sde-dpmsolver++"

model = "stabilityai/stable-diffusion-xl-base-1.0"
dpm_single = DPMSolverSinglestepScheduler.from_pretrained(model, subfolder="scheduler", solver_order=solver_order, algorithm_type=algorithm_type)
dpm_multi = DPMSolverMultistepScheduler.from_pretrained(model, subfolder="scheduler", solver_order=solver_order, algorithm_type=algorithm_type)

pipeline = StableDiffusionXLPipeline.from_pretrained(model, variant="fp16", torch_dtype=torch.float16)
pipeline.enable_vae_tiling()
pipeline = pipeline.to("cuda")

prompt = "a photo of an astronaut riding a horse on mars"

pipeline.scheduler = dpm_single
num_inference_steps = 23

image = pipeline(prompt, num_inference_steps=num_inference_steps, generator=torch.Generator().manual_seed(0)).images[0]
image.save("dpm_single.png")

pipeline.scheduler = dpm_multi

image = pipeline(prompt, num_inference_steps=num_inference_steps, generator=torch.Generator().manual_seed(0)).images[0]
image.save("dpm_multi.png")
Outputs

DPMSolverMultistepScheduler
dpm_multi_23

DPMSolverSinglestepScheduler
dpm_single_23

@yiyixuxu yiyixuxu merged commit 8ac6de9 into huggingface:main Dec 3, 2024
15 checks passed
@yiyixuxu yiyixuxu added the roadmap Add to current release roadmap label Dec 4, 2024
lawrence-cj pushed a commit to lawrence-cj/diffusers that referenced this pull request Dec 4, 2024
* Fix wrong output on 3n-1 steps count

* Add sde handling to 3 order

* make

* copies

---------

Co-authored-by: hlky <[email protected]>
sayakpaul pushed a commit that referenced this pull request Dec 23, 2024
* Fix wrong output on 3n-1 steps count

* Add sde handling to 3 order

* make

* copies

---------

Co-authored-by: hlky <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

roadmap Add to current release roadmap

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants