diffusers icon indicating copy to clipboard operation
diffusers copied to clipboard

A1111 <> Diffusers Scheduler mapping

Open patrickvonplaten opened this issue 3 years ago • 29 comments

A1111 <> Diffusers Mapping

A1111 / K-Diffusion Diffusers Notes
DPM++ 2M Multistep DPM-Solver
DPM++ 2M Karras Multistep DPM-Solver init with use_karras_sigmas=True
DPM++ 2M SDE Multistep DPM-Solver init with algorithm_type="sde-dpmsolver++"
DPM++ 2M SDE Karras Multistep DPM-Solver init with algorithm_type="sde-dpmsolver++" and use_karras_sigmas=True
DPM++ 2S a N/A Very similar to DPM++ SDE
DPM++ 2S a Karras N/A Very similar to DPM++ SDE Karras
DPM++ SDE Singlestep DPM-Solver
DPM++ SDE Karras Singlestep DPM-Solver init with use_karras_sigmas=True
DPM2 DPM Discrete Scheduler
DPM2 Karras DPM Discrete Scheduler init with use_karras_sigmas=True
DPM2 a DPM Discrete Scheduler with ancestral sampling
DPM2 a Karras DPM Discrete Scheduler with ancestral sampling init with use_karras_sigmas=True
DPM adaptive N/A
DPM fast N/A Not really used no?
Euler Euler scheduler
Euler a Euler Ancestral Scheduler
Heun Heun Scheduler
LMS Linear Multistep
LMS Karras Linear Multistep Init with use_karras_sigmas=True
N/A DEIS
N/A UniPCMultistepScheduler

Diffusers samplers have a couple more ways to be customized as can be seen from the inits of the respective samplers.

patrickvonplaten avatar Jul 19 '23 23:07 patrickvonplaten

Hi! Wondering if there's plan for "DPM++ 3M SDE" implementation (or if that's already implemented?)

jiaxin-lin avatar Dec 09 '23 06:12 jiaxin-lin

There is no plan to add it yet, feel free to open a PR @JLLLinn :-)

patrickvonplaten avatar Dec 18 '23 13:12 patrickvonplaten

I've refactored and fixed some issues, samplers reproduce the same result in a1111 except for DPM2 a Karras (which is marked as a second order sampler). I also explain a bit better in code what's going on in kdiffusion.py

I can observe that samplers like Heun, DPM2 a, DPM fast, DPM++ SDE Karras produce very similar results but has a subtle variation from a1111.

I was thinking this would be the sigma values being slightly different. For example:

diffusers: [14.6172, 11.7266,  9.3438,  7.3867,  5.7891,  4.5000,  3.4648,  2.6406,
         1.9912,  1.4834,  1.0908,  0.7910,  0.5649,  0.3965,  0.2732,  0.1842,
         0.1214,  0.0779,  0.0485,  0.0292,  0.0000]

a1111: [14.6116, 11.7413,  9.3685,  7.4192,  5.8284,  4.5394,  3.5029,  2.6763,
         2.0228,  1.5112,  1.1147,  0.8110,  0.5812,  0.4096,  0.2834,  0.1921,
         0.1273,  0.0822,  0.0515,  0.0313,  0.0000]

I used the same method from the k-diffusion pipeline in diffusers to get the min max sigma and I'm not sure how to do it otherwise.

The discrepancy arises from numerical precision. In A1111, betas are generated in float64, and the alphas_cumprod, used in sigma creation, is in float16 format. Conversely, diffusers use float32. torch.cumprod is sensitive to precision, especially when it contains 1000 items. If matching the format, sigmas should be identical. This discrepancy also leads to some differences between A1111 and diffusers' results.

caiqi avatar Feb 19 '24 14:02 caiqi

Ok to close this @patrickvonplaten now that it is in the docs here?

@stevhliu it seems the link is broken. Would you mind resharing a link to where this is in the doc please?

Thank you

alexisrolland avatar Feb 19 '24 22:02 alexisrolland

You can find it in the Schedulers overview :)

stevhliu avatar Feb 20 '24 16:02 stevhliu

How about the LCM scheduler?How to set init params to align a1111 rst?

abc2cba avatar Mar 04 '24 03:03 abc2cba

@caiqi I am debugging my comfyui implementation of TCD scheduler, and want to print the sigmas array like you did above. Can you please share how you did that? Sorry if it's a basic question, I am still learning my way around diffusers pipelines... I only see timesteps inside the scheduler mixin code and am not sure where to get the sigmas.

UPDATE: I figured it out, added this to the scheduler's set_timesteps method

        self.timesteps = torch.from_numpy(timesteps).to(device=device, dtype=torch.long)
        print(f"timesteps: {repr(self.timesteps)}")
        sigmas = np.sqrt(1 - self.alphas_cumprod)
        print(f"sigmas: {sigmas.to(device=device)[self.timesteps]}")

dfl avatar Mar 24 '24 19:03 dfl

Hi! Wondering if there's plan for "DPM++ 3M SDE" implementation (or if that's already implemented?)

+1 for this. I'm getting consistent good results with this sampler in A1111, so I'd really love to see it in Diffusers

andypotato avatar Mar 27 '24 09:03 andypotato

mark

Youngon avatar May 21 '24 11:05 Youngon