AUTOMATIC1111 / stable-diffusion-webui

Stable Diffusion web UI
GNU Affero General Public License v3.0
131.71k stars 25.28k forks source link

Add KL Optimal scheduler #15608

Open drhead opened 4 weeks ago

drhead commented 4 weeks ago

Description

Screenshots/videos:

Note: These grids have CFG skipped on the first step unless otherwise specified. Test grid for 50 steps: Comparing different noise schedulers, and also including sigma max of 4500 (approximately the default for ZSNR) and 160 in the comparison (an alternative that I find works well for other schedulers, spending less time at extremely high sigmas): xyz_grid-1523-2057651393-(best quality, high quality,_1 2) by strange-fox, by fabercastel, by hydaus, (digital painting _(artwork_), photography _(artwor All samplers perform adequately on this one. Most notably, KL Optimal functions better at the higher sigma max value, where Karras is somewhat washed out/smoother.

Test grid for 25 steps: xyz_grid-1524-2057651393-(best quality, high quality,_1 2) by strange-fox, by fabercastel, by hydaus, (digital painting _(artwork_), photography _(artwor At 25 steps, Karras is an absolute mess at the higher default sigma max value. Others all still look acceptable.

Test grid for 10 steps: xyz_grid-1525-2057651393-(best quality, high quality,_1 2) by strange-fox, by fabercastel, by hydaus, (digital painting _(artwork_), photography _(artwor Complete failure case for Uniform and Karras. KL Optimal doesn't look fantastic, but frankly it's better looking than a 10-step sample from a non-distilled model has any right to be.

Failure case when not skipping CFG (50 steps). Probably ZSNR specific: xyz_grid-1521-2057651393-(best quality, high quality,_1 2) by strange-fox, by fabercastel, by hydaus, (digital painting _(artwork_), photography _(artwor Not all prompts will do this, but this happens to be one of the ones that does. The black "doors" surrounding the images in the KL Optimal column will render as a black border that encroaches on the whole image at lower step counts. Higher step counts might stabilize this depending on prompt. Skipping CFG on the first timestep is enough to reliably fix issues such as this.

Checklist:

zcatharisis commented 3 weeks ago

Thanks for implementing this to A1111. Could I ask for your preferred settings for SD 1.5 non-ZSNR models, especially for Schedule Sigma Max and the Negative Guidance minimum sigma? Those are the only variables I haven't been able to dial in in my testing.

drhead commented 3 weeks ago

Thanks for implementing this to A1111. Could I ask for your preferred settings for SD 1.5 non-ZSNR models, especially for Schedule Sigma Max and the Negative Guidance minimum sigma? Those are the only variables I haven't been able to dial in in my testing.

For regular models, leave schedule sigma max at default (0/automatic), the only reason I mess with it on ZSNR models is because it should be infinity there but that doesn't/can't work properly. For negative guidance minimum sigma, I usually find that 0.75 works fine (set to skip all steps instead of every other). Turn it down if images get too smoothed over.