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

Update K-Diffusion and include noise scheduler script #1560

Merged
merged 5 commits into from
Oct 6, 2022

Conversation

C43H66N12O12S2
Copy link
Collaborator

This PR updates K-Diffusion to enable the newest improvements in DPM Adaptive (stochastic sampling and ancestral sampling for adaptive) and includes the noise scheduler script by @dfaker.

The reason I include the script can be seen here #1435 but the TLDR is DPM samplers will output a unpleasantly noisy/filtered image if using the default scheduler. Karras scheduling seems to be the intended way to use these samplers. I included the script instead of changing the default to preserve seed compatibility.

closes #1435

Default
00016-2418091115

Karras scheduling
00088-2418091115

@zsinisi001
Copy link

zsinisi001 commented Oct 3, 2022

It would be awesome if the alternate noise schedules could run alongside other scripts too, would really like to use it with SD upscaling. Liking the results I'm getting from img2img.

@AUTOMATIC1111
Copy link
Owner

the script should still go to wiki
we could add new sampler with optimal params specified if there i a need for that

@d8ahazard
Copy link
Collaborator

This PR updates K-Diffusion to enable the newest improvements in DPM Adaptive (stochastic sampling and ancestral sampling for adaptive) and includes the noise scheduler script by @dfaker.

The reason I include the script can be seen here #1435 but the TLDR is DPM samplers will output a unpleasantly noisy/filtered image if using the default scheduler. Karras scheduling seems to be the intended way to use these samplers. I included the script instead of changing the default to preserve seed compatibility.

closes #1435

Default 00016-2418091115

Karras scheduling 00088-2418091115

So, dumb question...but if it improves output and it "seems to be the intended way", why not just make it an advanced setting option for people who don't care about breaking seeds and just want their pics to look awesome (like myself)?

As you pointed out, because it's a script, it's somewhat restricted in usage. I'd be all for leaving the default alone, and just adding this as an optional setting.

@d8ahazard
Copy link
Collaborator

Also, updating the commit hash doesn't actually change anything ATM, unless you install new.

The "git_clone" command within the launch script just returns if the directory already exists, meaning they'll never be updated from the hash...

@C43H66N12O12S2
Copy link
Collaborator Author

@AUTOMATIC1111

So, we basically have 4 options here:

  • Change the default to karras, breaking seeds
  • Add a setting to use karras scheduler in UI
  • Ship the script
  • Ignore it and let users figure it out themselves, maybe with a wiki entry

Let me know which one you'd prefer. IMO shipping the script would be the easiest path.

@d8ahazard
Originally, dfaker had planned a setting IIRC but @AUTOMATIC1111 disliked it, so that's why I opted to ship the script.

@AUTOMATIC1111
Copy link
Owner

Ship the script for people who want to do research.

Also, if needed, we can add DPM-karras sampler along with existing DPM sampler. Maybe a setting for user to show which samplers are shown in UI.

@C43H66N12O12S2
Copy link
Collaborator Author

@AUTOMATIC1111 please review and pull

@dfaker
Copy link
Collaborator

dfaker commented Oct 5, 2022

Although the sigma range 0.1 - 10 works, I would note it's purely a 'what looked best' choice by myself, for contrast and detail, the k-diffusion configs routinely uses the range 0.01-80: https://github.com/crowsonkb/k-diffusion/blob/f4e99857772fc3a126ba886aadf795a332774878/configs/config_cifar10.json#L17 (albeit for different models) but those values are just noise for me with DPM Adaptive-SD:
image

@C43H66N12O12S2
Copy link
Collaborator Author

@dfaker Birch-san uses 0.2 to 14, I think. Ultimately though 0.1 - 10 produces good results and if I had added knobs to control the sigma range, it would be basically a reimplementation of your script at that point.

There are some other things that can be done (early ramp finish for example) but IIRC crowsonkb plans to implement those so I decided to wait for official support rather than hacking together a monstrosity.

@dfaker
Copy link
Collaborator

dfaker commented Oct 5, 2022

Cool, just wanted to make sure no one is mistaking my arbitrary choices for reasoned defaults!

@C43H66N12O12S2
Copy link
Collaborator Author

@dfaker BTW, if you want to experiment with sigma ranges, don't use DPM fast or adaptive as (at least my implementation) is compatible only with SD scheduler.

@C43H66N12O12S2
Copy link
Collaborator Author

Actually, we could also use the same range SD scheduler uses. Subjectively, 0.1 to 10 looks better, but using the same vanilla range is a more direct migration and still achieves the main motivation of this PR (removing noise).

Using the vanilla range (which is actually 0.03/14.6), the same seed produces this image:
00051-2418091115

@AUTOMATIC1111 What do you think?

@AUTOMATIC1111 AUTOMATIC1111 changed the base branch from master to new_samplers October 6, 2022 10:41
@AUTOMATIC1111 AUTOMATIC1111 merged commit a971e4a into AUTOMATIC1111:new_samplers Oct 6, 2022
@AUTOMATIC1111
Copy link
Owner

So I merged it in but with some edits, made it use the new option that lets the user pick which samplers he wants to see.

And as for the script - I didn't mean ship it with the repo, I meant put it on the wiki.

Some results if anyone is interested:
xy_grid-0002-1790416765

@crowsonkb
Copy link

Although the sigma range 0.1 - 10 works, I would note it's purely a 'what looked best' choice by myself, for contrast and detail, the k-diffusion configs routinely uses the range 0.01-80: https://github.com/crowsonkb/k-diffusion/blob/f4e99857772fc3a126ba886aadf795a332774878/configs/config_cifar10.json#L17 (albeit for different models) but those values are just noise for me with DPM Adaptive-SD:

It's noise because it's not valid to use a noise level outside of the range that Stable Diffusion was trained on. You have to pull the sigma_min and sigma_max out of the SD model wrapper.

sigma_min, sigma_max = model_wrap.sigmas[0].item(), model_wrap.sigmas[-1].item()

Around these lines.

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.

DPM2 ancestral produces odd nosiy/sharpened output during final step
6 participants