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

[Feature Request]: (Optimization) Option to remove negative conditioning at low sigma values #9129

Closed
1 task done
devNegative-asm opened this issue Mar 29, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@devNegative-asm
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues and checked the recent builds/commits

What would your feature do ?

At low sigma values towards the latter steps of a diffusion process, there is not much practical difference between different cfg values. Setting cfg=1 for these steps allows the calls to the unet to be cut in half with minimal quality loss.
Original: https://twitter.com/Birchlabs/status/1640033271512702977

with high-res fix on, and step counts ~20-30 the difference is even less noticable:
image

Proposed workflow

  1. Go to settings/Sampler parameters (or perhaps a more suitable setting menu)
  2. Use slider to change Negative Guidance minimum sigma
  3. default value to 0 (maximum quality), allow it to be increased (more speed)

Additional information

From experimentation, values below 0.8 preserve quality decently unless the step count is too high. With hi-res fix on, values up to 0.95 can work fairly well.

I have a version of this that does function, but it breaks live image preview:

master...devNegative-asm:stable-diffusion-webui:master

@devNegative-asm devNegative-asm added the enhancement New feature or request label Mar 29, 2023
@catboxanon
Copy link
Collaborator

Nice work!

Live preview image seems to be working fine for me with this. Do you mean by it being broken it's behaving in a way it shouldn't? Regardless it seems worth it to at least open a draft PR for this. Auto does not read issues and this would otherwise go unnoticed until a PR is made.

@devNegative-asm
Copy link
Contributor Author

PR made: #9177

@devNegative-asm
Copy link
Contributor Author

also fixed the live previews

@evanjs
Copy link

evanjs commented May 16, 2023

Seems to work nicely, but what numeric type is meant to be supported?
Upon trying to load last image/prompt generation parameters with NGMS specified using floating point values, generation_parameters_copypaste gets angry.

File "...\automatic1111\stable-diffusion-webui\modules\shared.py", line 635, in cast_value
    value = expected_type(value)
ValueError: invalid literal for int() with base 10: '3.0'

@gdxia
Copy link

gdxia commented Jun 12, 2023

A big bug:

我测试了一下,把这个值设置为小数,会给WebUi带来一些问题。

比如设置为0.7,那么“生成”按钮下的那几个图标功能会失效,并在命令行提示错误。但是如何设置为整数,比如'1"那就正常了。

Traceback (most recent call last):
File "D:\AI\sd-webui-aki-v4.1\python\lib\site-packages\gradio\routes.py", line 422, in run_predict
output = await app.get_blocks().process_api(
File "D:\AI\sd-webui-aki-v4.1\python\lib\site-packages\gradio\blocks.py", line 1323, in process_api
result = await self.call_function(
File "D:\AI\sd-webui-aki-v4.1\python\lib\site-packages\gradio\blocks.py", line 1051, in call_function
prediction = await anyio.to_thread.run_sync(
File "D:\AI\sd-webui-aki-v4.1\python\lib\site-packages\anyio\to_thread.py", line 31, in run_sync
return await get_asynclib().run_sync_in_worker_thread(
File "D:\AI\sd-webui-aki-v4.1\python\lib\site-packages\anyio_backends_asyncio.py", line 937, in run_sync_in_worker_thread
return await future
File "D:\AI\sd-webui-aki-v4.1\python\lib\site-packages\anyio_backends_asyncio.py", line 867, in run
result = context.run(func, *args)
File "D:\AI\sd-webui-aki-v4.1\modules\generation_parameters_copypaste.py", line 379, in paste_func
v = key(params)
File "D:\AI\sd-webui-aki-v4.1\modules\generation_parameters_copypaste.py", line 414, in paste_settings
v = shared.opts.cast_value(setting_name, v)
File "D:\AI\sd-webui-aki-v4.1\modules\shared.py", line 692, in cast_value
value = expected_type(value)
ValueError: invalid literal for int() with base 10: '0.7'
提示:Python 运行时抛出了一个异常。请检查疑难解答页面。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants