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

@stevhliu could we maybe put this in a doc as discussed a bit during our meeting? Maybe in the overview doc page?

patrickvonplaten avatar Jul 20 '23 00:07 patrickvonplaten

Nice, I'll roll this into a PR I'm working on to update the scheduler APIs!

stevhliu avatar Jul 20 '23 17:07 stevhliu

@patrickvonplaten: I'm confused: Shouldn't DPM++ SDE be DPMSolverSDEScheduler? And in this issue you just said that "DPM++ 2s a" = DPMSolverSinglestepScheduler.

rbertus2000 avatar Jul 21 '23 14:07 rbertus2000

  • https://huggingface.co/docs/diffusers/v0.18.2/en/api/schedulers/dpm_sde is another implementation of DPMSolverSDE but it's not the official one (the author contributed DPMSolverSDE himself), so that the default one. In my opinion, we could deprecate DPMSolverSDE at some point.
  • RE: DPM++ 2s a yes indeed it's very similar to DPMSolverSinglestepScheduler with init with algorithm_type="sde-dpmsolver++" and use_karras_sigmas=True

patrickvonplaten avatar Jul 24 '23 08:07 patrickvonplaten

Hi @patrickvonplaten Thanks for the clarification. For DPM++ 2s a - can you please confirm whether the algorithm_type should be sde-dpmsolver++ or dpmsolver++?

Your recommendation in #3953 is dpmsolver++:

DPM++ 2s a => should be the following: DPMSolverSinglestepScheduler.from_config(..., algorithm_type="dpmsolver++")

And your most-recent message here is sde-dpmsolver++:

RE: DPM++ 2s a yes indeed it's very similar to DPMSolverSinglestepScheduler with init with algorithm_type="sde-dpmsolver++" and use_karras_sigmas=True

Thanks!

cmdr2 avatar Jul 24 '23 08:07 cmdr2

Hmm, I don't think sde-dpmsolver++ is implemented for DPMSolverSinglestepScheduler

NotImplementedError: sde-dpmsolver++ does is not implemented for <class 'diffusers.schedulers.scheduling_dpmsolver_singlestep.DPMSolverSinglestepScheduler'>

cmdr2 avatar Jul 24 '23 08:07 cmdr2

Ah good catch! We need to add this algorithm type. Here: https://github.com/huggingface/diffusers/pull/3344/files was the PR to add it to the Multi-Step scheduler. I think it can be more or less copied 1-to-1 to DPMSolverSinglestepScheduler - would you like to open a PR?

patrickvonplaten avatar Jul 24 '23 19:07 patrickvonplaten

@patrickvonplaten Thanks! I've opened a PR at https://github.com/huggingface/diffusers/pull/4251

There's a discrepancy that I'm not sure about, I've raised that in the PR.

cmdr2 avatar Jul 25 '23 02:07 cmdr2

I tried implementing a1111's kdiffusion samplers in diffusers along with the ability to pass user changable settings from a1111 to kdiffusion.

Do note that I don't have much experience in this field, it's just something I got into for fun the last month or two.

But my findings are:

I was going for 1 to 1 kind of for fun, but I think ideally some sacrifices should be made. Like I'm not sure people intentionally use the extra sampler settings, and they're all set to default as far as I know.

My implementation can be found here. I've compared various samplers to a1111 and my implementation and it seems to work, but probably there are details I've missed. https://github.com/CapsAdmin/diffusers-a1111/

CapsAdmin avatar Jul 25 '23 18:07 CapsAdmin

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.

CapsAdmin avatar Jul 26 '23 10:07 CapsAdmin

I also discovered a potential bug where a1111 will pass eta=1 coming from sampler settings to DPM Fast and DPM Adaptive. The default eta in kdiffusion is 0.

When they are used with eta 0, DPM fast actually produces good results and DPM adaptive finishes a lot faster.

old man, 25 steps, DPM fast, eta 0 image

old man, 25 steps, DPM fast, eta 1 image

I think this setting was supposed to be used for ancestral samplers, but accidentally brought to these samplers.

So I guess this is the reason DPM fast is infamous for producing bad results.

CapsAdmin avatar Jul 26 '23 10:07 CapsAdmin

Wow, this is great, thanks @patrickvonplaten , I have been spending lots of nights testing out the correct mapping relationship

xhinker avatar Aug 04 '23 18:08 xhinker

Thank you @patrickvonplaten for writing up this mapping! <3

@stevhliu did it eventually make it into the Diffusers documentation? I just want to make sure whether this mapping above is still the point of truth or if there is another one somewhere I should use...

Side note, I noticed there are a couple of schedulers in diffusers that are not included in the mapping above. It seems the list is not entirely exhaustive, maybe because they do not exist in A1111?

Thank you both! :open_hands:

alexisrolland avatar Aug 15 '23 10:08 alexisrolland

Hi @alexisrolland, the mapping is live on the main version of the docs 🤗

stevhliu avatar Aug 15 '23 14:08 stevhliu

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

github-actions[bot] avatar Sep 12 '23 15:09 github-actions[bot]

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

stevhliu avatar Sep 12 '23 15:09 stevhliu

Hey HF team, I'm trying to mimic the A1111 samplers using the table listed here and in the docs but it seems the KDPM2DiscreteScheduler and KDPM2AncestralDiscreteScheduler schedulers don't actually support the use_karras_sigmas=True argument.

Please let me know if I'm just missing something :hugs:

CodeCorrupt avatar Sep 12 '23 17:09 CodeCorrupt

Hey @CodeCorrupt,

Yes we could add them in a PR I think :-)

patrickvonplaten avatar Sep 12 '23 17:09 patrickvonplaten

@CodeCorrupt do you mind opening a new issue with this?

patrickvonplaten avatar Sep 12 '23 17:09 patrickvonplaten

New issue was opened #5002 :+1:

CodeCorrupt avatar Sep 13 '23 01:09 CodeCorrupt