-
Notifications
You must be signed in to change notification settings - Fork 375
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
Stabilize the sampling of DPM-Solver++2M by a stabilizing trick #43
Comments
An example of the stabilizing trick: |
What do Stable Diffusion samples look like with and without this trick? I tried it and it seemed to produce really blurry samples instead at say NFE=5... have you considered restricting the range of |
Interesting suggestion. I will try to tune |
After trying, I still don't know how to improve it further... and I still think this may be due to the non-Lipschitzness for t near to 0, and second-order solvers are more unstable than first-order solvers in such cases. Do you also observe such an unstable problem? (i.e. unstable pixels) |
Oh it mostly seems to happen at higher guidance scales than I typically use... that's why I hadn't been seeing it. |
Hi, I wonder if this is related but using this implementation I've found that with a low number of steps (say < 10), it is better to use the sigmas of a higher step count (1 or 2 more), while still stopping after S steps. I hacked some code to break out of the sampling loop at a specified index, and tried changing some parameters when using with Stable Diffusion. DPM Solver++ (2M) (Karras scheduling):
Woman eating apple
7 guidance scale Euler also had some changes, but less drastic. |
for what it's worth:
https://twitter.com/Birchlabs/status/1589038086633455616 this is k-diffusion dpmpp_2m without the new stabilising trick, and without skipping the denoise-to-0. here's the sigmas SD supports (0.0292 to 14.6146): |
Interesting! What does "still stopping after S steps." means? |
So amazing, I will go deeper into it |
I think it means skipping the last step, you can do it better by |
If you want to do one more function evaluation have you tried doing a DPM++ 2S step as the first step to warm up the linear multistep method, instead of an Euler step? |
I haven't! I've only used |
You have to paste the 2S step code into the 2M sampler because you need to save its |
are these the right way around? trying to relate the suggestion to the code and the pieces aren't fitting for me.
I see a comment on 2S that it uses Euler in the base case, but none of the code in 2M resembles a Euler step to my eye. k-diffusion/k_diffusion/sampling.py Line 453 in 60e5042
again, I see evidence in 2S of second-order stepping (the |
It's this branch of the conditional: k-diffusion/k_diffusion/sampling.py Line 487 in 60e5042
|
…comment). note: could be wrong; merits review.
hmm like this? here's what I get when I decode the latents from each step. second column is the one that'll be impacted by the change. original modified hm… I guess with this modification: the second column has a few more features defined than we had in the original algorithm. is that indication of success? |
That's what I meant to do, yes :) |
… performing a DPM++2S step. as per @crowsonkb's crowsonkb#43 (comment)
DPM2 a and DPM2 a Karras samplers are both affected by an issue described by AUTOMATIC1111#3483 and can be resolved by a workaround suggested by the k-diffusion author at crowsonkb/k-diffusion#43 (comment)
The issue described by @hentailord85ez I can replicate consistently on As you can see, step 9/10 is clear, and step 10/10 is corrupted. and the suggested fix:
Reliably improves quality of outputs, by which I mean avoids the corruption step. I'm not seeing the same issue for EDIT: It affects Could this fix (or an equivalent alternative) be implemented directly into k-diffusion, or does this need to be handled by the caller? |
@mcmonkey4eva I think I could include a modified get_sigmas_karras() that it avoided the second to last sigma... maybe generating a ramp that was one step longer then manually chopping off the second to last step. |
DPM2 a and DPM2 a Karras samplers are both affected by an issue described by AUTOMATIC1111#3483 and can be resolved by a workaround suggested by the k-diffusion author at crowsonkb/k-diffusion#43 (comment)
… performing a DPM++2S step. as per @crowsonkb's crowsonkb#43 (comment)
Hi @crowsonkb , I hope you are doing well :) Recently the community finds that when using For example, And there are more examples here: huggingface/diffusers#5433 , for both Diffusers library (my implementation) and stable-diffusion-webui (with your implemented k-diffusioin). After carefully checking the reason, I find that it is also because of the instability for Because SDXL is a powerful and promising model and the SDE solver is widely used, could you please also support this simple trick for k-diffusion? |
Hi Katherine,
Thank you for your great work on supporting DPM-Solver++, and I've found that it has been used in stable-diffusion-webui and has a great performance: AUTOMATIC1111/stable-diffusion-webui#4304. Thank you for your contribution again!
However, the sampling by DPM-Solver++2M with steps <= 10 often suffers from instability issues (the image quality is much worse than DDIM). In my recent experience, I found that it is due to the non-Lipschitzness near t=0.
(In fact, the score function has numerical issues for t near 0, and it has been revealed in many previous papers, such as CLD and SoftTruncation. )
Therefore, in my recent PR to diffusers, I further added a new "stabilizing" trick to reduce such instability by using lower-order solvers at the final steps (e.g., for 2nd-order DPM-Solver++, I used DPM-Solver++2M at the first N-1 steps and DDIM at the final step.) I find it can greatly stabilize the sampling by DPM-Solver++2M. Please check this PR for details:
huggingface/diffusers#1132
Excuse me for my frequent issues, but could you please further support this "stabilizing" trick in k-diffusion, so that other projects, such as stable-diffusion-webui can further support it? Thank you very much!
The text was updated successfully, but these errors were encountered: