InvokeAI icon indicating copy to clipboard operation
InvokeAI copied to clipboard

[bug]: KDPM 2 / KDPM 2 Ancestral schedulers don't produce expected output on M1

Open peterdandreti opened this issue 3 years ago • 5 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

OS

macOS

GPU

mps

VRAM

15

What version did you experience this issue on?

3.3.0

What happened?

KDPM 2 / KDPM 2 Ancestral schedulers output visual noise on M1, (see example) from the below specs:

Generation Mode: txt2img Positive Prompt: an astronaught riding a unicorn in space Seed: 1 Model: stable-diffusion-v1-5 Width: 512 Height: 512 Scheduler: kdpm_2_a Steps: 10 CFG scale: 7

Changing these specs doesn't improve the output however.

Screenshots

a51805f4-8922-480f-8ff2-85e9d1676a24

Additional context

Predates 3.3.0

Contact Details

petecats

peterdandreti avatar Oct 13 '23 10:10 peterdandreti

There is a behavioral difference between KDPM2 and KDPM2 Ancestral. Base KDPM2 produces a black image, while Ancestral produces color noise. In any case, I can confirm that these schedulers do not work on Apple Silicon.

M2 Max, Sonoma, Torch(Vision) nightlies October 14

Adreitz avatar Oct 14 '23 23:10 Adreitz

just ran a quick test in Diffusers. Everything looks good until the last step, then the latents are all nan

          [-0.8965,  2.5312,  1.4717,  ..., -0.5049, -1.0488,  0.4048]]]],
       device='mps:0', dtype=torch.float16)
100%|████| 10/10 [09:24<00:00, 47.57s/it]
18
tensor(1., device='mps:0')
tensor([[[[nan, nan, nan,  ..., nan, nan, nan],
          [nan, nan, nan,  ..., nan, nan, nan],
          [nan, nan, nan,  ..., nan, nan, nan],
          ...,

As you can see the latents from the step before where fine.

The issue seems to be that the sigma_interpol values are derived by a lerp of the log values of sigmas.

Digging further down its an MPS Pytorch with torch.lerp. lerping between -Inf and another value is -Inf on the CPU (and I guess CUDA) and NaN on MPS. That value is then used by exp, exp(-iInf) is 0 exp(NaN) is NaN

The NaN gets used to calculate the latent on the final step, leading to an all NaN latent.

Vargol avatar Oct 16 '23 15:10 Vargol

https://github.com/pytorch/pytorch/issues/111374

Vargol avatar Oct 16 '23 15:10 Vargol

Just looping back in to say that this has been resolved.

peterdandreti avatar Feb 13 '24 22:02 peterdandreti

This appears to be reintroduced/regressed in 5.0 at least when doing upscale operations. Screenshot 2024-10-01 at 11 04 26 AM

niffrig avatar Oct 01 '24 18:10 niffrig