Skip to content

Fix DPM++ SDE not deterministic across different batch sizes (#5210) #7730

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

Merged
merged 2 commits into from
Feb 19, 2023

Conversation

CCRcmcpe
Copy link
Contributor

Describe what this pull request is trying to achieve.

Fix #5210.

Additional notes and description of your changes

An option was added to ensure reproducibility of old seeds.

Environment this was tested in

List the environment you have developed / tested this on. As per the contributing page, changes should be able to work on Windows out of the box.

  • OS: Linux
  • Browser: Chrome
  • Graphics card: NVIDIA V100

@hithereai
Copy link
Collaborator

Thanks for this, been waiting for a long time :)

@leppie
Copy link
Contributor

leppie commented Feb 13, 2023

Works well! Tested various start seeds and diff batch sizes, all reproducable.

@Cyberbeing
Copy link
Contributor

Traceback (most recent call last):
  File "F:\AI\stable-diffusion-webui\modules\call_queue.py", line 56, in f
    res = list(func(*args, **kwargs))
  File "F:\AI\stable-diffusion-webui\modules\call_queue.py", line 37, in f
    res = func(*args, **kwargs)
  File "F:\AI\stable-diffusion-webui\modules\img2img.py", line 169, in img2img
    processed = process_images(p)
  File "F:\AI\stable-diffusion-webui\modules\processing.py", line 486, in process_images
    res = process_images_inner(p)
  File "F:\AI\stable-diffusion-webui\modules\processing.py", line 628, in process_images_inner
    samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, seeds=seeds, subseeds=subseeds, subseed_strength=p.subseed_strength, prompts=prompts)
  File "F:\AI\stable-diffusion-webui\modules\processing.py", line 1041, in sample
    samples = self.sampler.sample_img2img(self, self.init_latent, x, conditioning, unconditional_conditioning, image_conditioning=self.image_conditioning)
  File "F:\AI\stable-diffusion-webui\modules\sd_samplers_kdiffusion.py", line 303, in sample_img2img
    noise_sampler = self.create_noise_sampler(x, sigmas, p.all_seeds)
  File "F:\AI\stable-diffusion-webui\modules\sd_samplers_kdiffusion.py", line 277, in create_noise_sampler
    return BrownianTreeNoiseSampler(x, sigma_min, sigma_max, seed=seeds)
  File "F:\AI\stable-diffusion-webui\repositories\k-diffusion\k_diffusion\sampling.py", line 120, in __init__
    self.tree = BatchedBrownianTree(x, t0, t1, seed)
  File "F:\AI\stable-diffusion-webui\repositories\k-diffusion\k_diffusion\sampling.py", line 85, in __init__
    assert len(seed) == x.shape[0]
AssertionError

I'm seeing an assert with Batch Count above 1. No issue with Batch Size,

@Cyberbeing
Copy link
Contributor

Cyberbeing commented Feb 15, 2023

Confirmed the assert is now fixed with this new commit.

Tested various batch count, batch size, batch count + batch size in txt2img & img2img and all were deterministic and with reproducible seeds using SDE samplers.

I also briefly stress tested with Batch count + Batch size + Extra Variation Seed + HiresFix + DynamicThreshold Plugin all used at the same time with DPM++SDE Karras, and that as well appeared to be working with reproducible seeds.

Good job.

@AUTOMATIC1111 AUTOMATIC1111 merged commit a77ac2e into AUTOMATIC1111:master Feb 19, 2023
@maluhia
Copy link

maluhia commented Mar 1, 2023

Is this really fixed in the live version? I still cant replicate the single seed versus batch when using SDE sampler, and k-diffusers is enabled in settings.

@Cyberbeing
Copy link
Contributor

Cyberbeing commented Mar 2, 2023

Yes, it's been active in webui since it got merged 2 weeks ago. I just re-confirmed it is working on the latest GIT.

Under Settings > Compatibility, make sure Do not make DPM++ SDE deterministic across different batch sizes. is unchecked and save.

If it wasn't already obvious, this change only helps you reproduce seeds for SDE batches created after this commit was merged, as well any new or old SDE single image (no batch) seeds no matter the batch size or starting seed used with the fix. If you are only seeing small variations yet the overall image structure remains unchanged when attempting to reproduce seeds, those changes are being caused by xformers. Disable xformers if you need perfect seed reproducibility (this applies to any sampler).

To reproduce older SDE batch seeds, you'd still need to use exactly the same batch size and disable this fix in settings. This fix doesn't help at all with old SDE batch seed reproduction.

@maluhia
Copy link

maluhia commented Mar 2, 2023

Perfect, I had it checked mistakenly. Thanks!

@PseudoGrafx
Copy link

I have now encountered this same issue with Euler A. The resulting images are similar but not quite the same.

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.

[Bug]:batch size changes image using same seed with DPM++SDE Karras
7 participants