Skip to content

Vanilla image noise generator option#12812

Closed
lllyasviel wants to merge 3 commits intoAUTOMATIC1111:devfrom
lllyasviel:dev
Closed

Vanilla image noise generator option#12812
lllyasviel wants to merge 3 commits intoAUTOMATIC1111:devfrom
lllyasviel:dev

Conversation

@lllyasviel
Copy link
Copy Markdown

Description

Right now webui’s noise generating system is very powerful yet convoluted, making it difficult to produce consistent results with other software.

This pull request add an option “use_vanilla_random_number_generator” to temporarily disable some webui hackings to the noise generators.

The result is that now we can perfectly reproduce results from other software like comfyui, fooocus, etc. This pull request also include a minor fix in the dpm++’s first sigmas for the noise processing so that the results are even more consistent.

My recommendation is that the option “use_vanilla_random_number_generator” should only be targeted to code development, since introducing this to users will cause some confusing about reproducing results from old seeds.

This option is very useful when we want to implement extensions and check those extensions’ behaviors across different software.

image

Example 1

cinematic film still, a car in the city street . shallow depth of field, vignette, highly detailed, high budget, bokeh, cinemascope, moody, epic, gorgeous, film grain, grainy
Negative prompt: anime, cartoon, graphic, text, painting, crayon, graphite, abstract, glitch, deformed, mutated, ugly, disfigured
Steps: 20, Sampler: DPM++ 2M SDE Karras, CFG scale: 8, Seed: 123456, Size: 1024x1024, Model hash: e6bb9ea85b, Model: sd_xl_base_1.0_0.9vae, Version: v1.6.0-RC-32-gde0db85f

Webui

image
image

Comfy

image
image

Fooocus (all tricks disabled)

image

Webui (with "use_vanilla_random_number_generator")

image
image

Example 2

professional 3d model of a cute cat. octane render, highly detailed, volumetric, dramatic lighting
Negative prompt: ugly, deformed, noisy, low poly, blurry, painting
Steps: 20, Sampler: DPM++ 2M SDE Karras, CFG scale: 8, Seed: 123456, Size: 1024x1024, Model hash: e6bb9ea85b, Model: sd_xl_base_1.0_0.9vae, Version: v1.6.0-RC-33-gc8f0b780

Webui

image

image

Comfy

image

image

Fooocus (all tricks disabled)

image

Webui (with "use_vanilla_random_number_generator")

image

image

Minor

If you may still see some minor difference between these results, my guess is that this is caused by other software using cpu to process clip text encoding. Nevertheless, we do not think it is necessary to perfectly reproduce that.

Checklist:

@lllyasviel
Copy link
Copy Markdown
Author

lllyasviel commented Aug 27, 2023

and we will need something like this to check if some extensions' implementation is correct, like control-lora, revision, ip-adapter, etc.


x = x * sigmas[0]
if opts.use_vanilla_random_number_generator:
# https://github.com/comfyanonymous/ComfyUI/blob/a57b0c797b0670e6fd48ff3cf1f37dbf0d0a67b5/comfy/samplers.py#L716
Copy link
Copy Markdown
Collaborator

@catboxanon catboxanon Aug 27, 2023

Choose a reason for hiding this comment

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

Makes more sense to link to the original sgm repo where this originates.

Suggested change
# https://github.com/comfyanonymous/ComfyUI/blob/a57b0c797b0670e6fd48ff3cf1f37dbf0d0a67b5/comfy/samplers.py#L716
# https://github.com/Stability-AI/generative-models/blob/477d8b9a7730d9b2e92b326a770c0420d00308c9/sgm/modules/diffusionmodules/sampling.py#L50

}))

options_templates.update(options_section(('compatibility', "Compatibility"), {
"use_vanilla_random_number_generator": OptionInfo(False, "Use vanilla random number generator. Can reproduce other UI's results (Fooocus/ComfyUI). Require full restart."),
Copy link
Copy Markdown
Collaborator

@catboxanon catboxanon Aug 27, 2023

Choose a reason for hiding this comment

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

This feels too wordy for me so linking back to this PR makes more sense imo. Also a minor fix to use a chained function indiciating it requires a restart. (I will test this shortly, but -- does it actually?)

Suggested change
"use_vanilla_random_number_generator": OptionInfo(False, "Use vanilla random number generator. Can reproduce other UI's results (Fooocus/ComfyUI). Require full restart."),
"use_vanilla_random_number_generator": OptionInfo(False, "Use vanilla random number generator").link("PR", "https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/12812").info("can reproduce other UI's results").needs_restart(),

Something also tells me this is the only actual change needed. I will test that in a moment.

@catboxanon
Copy link
Copy Markdown
Collaborator

catboxanon commented Aug 27, 2023

Okay, this PR is definitely making it more complicated than it should -- I get identical results just by making your sigma change from sgm's repo, and setting the existing Random number generator source option to CPU. For reference, the change actually makes very little difference.

x * sigmas[0]

old

x * torch.sqrt(1.0 + sigmas[0] ** 2.0)

new

minor fix in the dpm++’s first sigmas

I think more notably this changes it for all k-diffusion samplers across the board. It doesn't look like this was in the original ldm repo either. While I'm personally ok with including it disabled by default, do you know the mathematical rationale behind the change?

@catboxanon
Copy link
Copy Markdown
Collaborator

catboxanon commented Aug 27, 2023

I've made a PR with the only change needed. #12818

@lllyasviel
Copy link
Copy Markdown
Author

I do not know the reason for this sigmas, probably related to tsnr.
also this pull request behavior can reproduce other repo results with batchsize larger than 1, but I will probably try a bit more to see if other options can achieve same thing

@catboxanon
Copy link
Copy Markdown
Collaborator

catboxanon commented Aug 27, 2023

There is an existing option to disable noise overriding of the SDE seeds. That's probably what you're thinking of. Look for Do not make DPM++ SDE deterministic across different batch sizes.

If there needs to be yet another implementation for making that consistent across different software that would be better for a separate PR, just as I made the sigma change separate. "Vanilla" in this sense here doesn't make sense when it's replicating ComfyUI's implementation.

@lllyasviel
Copy link
Copy Markdown
Author

“Vanilla” means it is consistent to

torch.manual_seed(seed)
noise=torch.rand((batch_size, 4, height, width))

This is also used by others like diffusers and native scripts written by people without taking special cares about noise.
Let me taking a look at “Do not make DPM++ SDE deterministic across different batch sizes”
Probably SDXL report can be cited if we want to have reference for first sigmas

@lllyasviel
Copy link
Copy Markdown
Author

wait a moment - this seems to break some other things related to img2img - Let me take a look first and close it for now

@lllyasviel lllyasviel closed this Aug 28, 2023
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.

2 participants