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

No seed gets set in custom/advanced samplers when add_noise is disabled #2833

Open
blepping opened this issue Feb 19, 2024 · 0 comments · May be fixed by #5306
Open

No seed gets set in custom/advanced samplers when add_noise is disabled #2833

blepping opened this issue Feb 19, 2024 · 0 comments · May be fixed by #5306

Comments

@blepping
Copy link
Contributor

blepping commented Feb 19, 2024

the common sampler code has:

    if disable_noise:
        noise = torch.zeros(latent_image.size(), dtype=latent_image.dtype, layout=latent_image.layout, device="cpu")
    else:
        batch_inds = latent["batch_index"] if "batch_index" in latent else None
        noise = comfy.sample.prepare_noise(latent_image, seed, batch_inds)

prepare_noise is what sets the global RNG that various thing such as ancestral samplers use, so when add_noise is disabled this means no seed gets set before sampling and the RNG is an undefined state. in other words, if you turn off add_noise and use a sampler like euler_a it's impossible to reproduce generations.

it's easy to reproduce: just use an advanced or custom sampler, set a fixed seed, turn off add_noise and use euler_a. start generating and look at the preview. abort it at 50% or so and restart, you will get a completely new generation each time.

is there any reason not to just do torch.manual_seed(seed) in the disable_noise code path to ensure the RNG is in a defined state based on the seed the user set?

i made a simple work around ( https://github.com/blepping/ComfyUI-bleh#blehforceseedsampler ) but it would be nice if that wasn't necessary. edit: my workaround doesn't seem to work reliably

see below for a visual demonstration of the issue. ignore the "Noisy Latent Image" node, it's not connected to anything. the seed comes from a Seed Everywhere node near the top right (set to 0)

current behavior

image

with #2841

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant