2024-07-03 15:13:16 +00:00
|
|
|
from typing import Any, Literal, Type
|
|
|
|
|
2023-05-11 12:40:03 +00:00
|
|
|
from diffusers import (
|
|
|
|
DDIMScheduler,
|
2023-08-18 15:13:28 +00:00
|
|
|
DDPMScheduler,
|
|
|
|
DEISMultistepScheduler,
|
2023-05-11 12:40:03 +00:00
|
|
|
DPMSolverMultistepScheduler,
|
2023-08-18 15:13:28 +00:00
|
|
|
DPMSolverSDEScheduler,
|
|
|
|
DPMSolverSinglestepScheduler,
|
2023-05-11 12:40:03 +00:00
|
|
|
EulerAncestralDiscreteScheduler,
|
2023-08-18 15:13:28 +00:00
|
|
|
EulerDiscreteScheduler,
|
2023-05-11 14:23:33 +00:00
|
|
|
HeunDiscreteScheduler,
|
2023-08-18 15:13:28 +00:00
|
|
|
KDPM2AncestralDiscreteScheduler,
|
|
|
|
KDPM2DiscreteScheduler,
|
2023-11-08 06:28:37 +00:00
|
|
|
LCMScheduler,
|
2023-05-11 14:23:33 +00:00
|
|
|
LMSDiscreteScheduler,
|
|
|
|
PNDMScheduler,
|
2024-03-28 21:51:59 +00:00
|
|
|
TCDScheduler,
|
2024-04-03 06:02:45 +00:00
|
|
|
UniPCMultistepScheduler,
|
2023-07-27 14:54:01 +00:00
|
|
|
)
|
2024-07-03 15:13:16 +00:00
|
|
|
from diffusers.schedulers.scheduling_utils import SchedulerMixin
|
|
|
|
|
2024-07-29 19:55:45 +00:00
|
|
|
# TODO: add dpmpp_3s/dpmpp_3s_k when fix released
|
|
|
|
# https://github.com/huggingface/diffusers/issues/9007
|
|
|
|
|
2024-07-03 15:13:16 +00:00
|
|
|
SCHEDULER_NAME_VALUES = Literal[
|
|
|
|
"ddim",
|
|
|
|
"ddpm",
|
|
|
|
"deis",
|
2024-07-29 12:14:34 +00:00
|
|
|
"deis_k",
|
2024-07-03 15:13:16 +00:00
|
|
|
"lms",
|
|
|
|
"lms_k",
|
|
|
|
"pndm",
|
|
|
|
"heun",
|
|
|
|
"heun_k",
|
|
|
|
"euler",
|
|
|
|
"euler_k",
|
|
|
|
"euler_a",
|
|
|
|
"kdpm_2",
|
2024-07-29 12:14:34 +00:00
|
|
|
"kdpm_2_k",
|
2024-07-03 15:13:16 +00:00
|
|
|
"kdpm_2_a",
|
2024-07-29 12:14:34 +00:00
|
|
|
"kdpm_2_a_k",
|
2024-07-03 15:13:16 +00:00
|
|
|
"dpmpp_2s",
|
|
|
|
"dpmpp_2s_k",
|
|
|
|
"dpmpp_2m",
|
|
|
|
"dpmpp_2m_k",
|
|
|
|
"dpmpp_2m_sde",
|
|
|
|
"dpmpp_2m_sde_k",
|
2024-07-29 19:52:15 +00:00
|
|
|
"dpmpp_3m",
|
|
|
|
"dpmpp_3m_k",
|
2024-07-03 15:13:16 +00:00
|
|
|
"dpmpp_sde",
|
|
|
|
"dpmpp_sde_k",
|
|
|
|
"unipc",
|
2024-07-29 12:14:34 +00:00
|
|
|
"unipc_k",
|
2024-07-03 15:13:16 +00:00
|
|
|
"lcm",
|
|
|
|
"tcd",
|
|
|
|
]
|
2023-05-11 12:40:03 +00:00
|
|
|
|
2024-07-03 15:13:16 +00:00
|
|
|
SCHEDULER_MAP: dict[SCHEDULER_NAME_VALUES, tuple[Type[SchedulerMixin], dict[str, Any]]] = {
|
2023-11-10 23:44:43 +00:00
|
|
|
"ddim": (DDIMScheduler, {}),
|
|
|
|
"ddpm": (DDPMScheduler, {}),
|
2024-07-29 12:14:34 +00:00
|
|
|
"deis": (DEISMultistepScheduler, {"use_karras_sigmas": False}),
|
|
|
|
"deis_k": (DEISMultistepScheduler, {"use_karras_sigmas": True}),
|
2023-11-10 23:44:43 +00:00
|
|
|
"lms": (LMSDiscreteScheduler, {"use_karras_sigmas": False}),
|
|
|
|
"lms_k": (LMSDiscreteScheduler, {"use_karras_sigmas": True}),
|
|
|
|
"pndm": (PNDMScheduler, {}),
|
|
|
|
"heun": (HeunDiscreteScheduler, {"use_karras_sigmas": False}),
|
|
|
|
"heun_k": (HeunDiscreteScheduler, {"use_karras_sigmas": True}),
|
|
|
|
"euler": (EulerDiscreteScheduler, {"use_karras_sigmas": False}),
|
|
|
|
"euler_k": (EulerDiscreteScheduler, {"use_karras_sigmas": True}),
|
|
|
|
"euler_a": (EulerAncestralDiscreteScheduler, {}),
|
2024-07-29 12:14:34 +00:00
|
|
|
"kdpm_2": (KDPM2DiscreteScheduler, {"use_karras_sigmas": False}),
|
|
|
|
"kdpm_2_k": (KDPM2DiscreteScheduler, {"use_karras_sigmas": True}),
|
|
|
|
"kdpm_2_a": (KDPM2AncestralDiscreteScheduler, {"use_karras_sigmas": False}),
|
|
|
|
"kdpm_2_a_k": (KDPM2AncestralDiscreteScheduler, {"use_karras_sigmas": True}),
|
2024-07-29 19:52:15 +00:00
|
|
|
"dpmpp_2s": (DPMSolverSinglestepScheduler, {"use_karras_sigmas": False, "solver_order": 2}),
|
|
|
|
"dpmpp_2s_k": (DPMSolverSinglestepScheduler, {"use_karras_sigmas": True, "solver_order": 2}),
|
|
|
|
"dpmpp_2m": (DPMSolverMultistepScheduler, {"use_karras_sigmas": False, "solver_order": 2}),
|
|
|
|
"dpmpp_2m_k": (DPMSolverMultistepScheduler, {"use_karras_sigmas": True, "solver_order": 2}),
|
2024-07-29 19:59:17 +00:00
|
|
|
"dpmpp_2m_sde": (
|
|
|
|
DPMSolverMultistepScheduler,
|
|
|
|
{"use_karras_sigmas": False, "solver_order": 2, "algorithm_type": "sde-dpmsolver++"},
|
|
|
|
),
|
|
|
|
"dpmpp_2m_sde_k": (
|
|
|
|
DPMSolverMultistepScheduler,
|
|
|
|
{"use_karras_sigmas": True, "solver_order": 2, "algorithm_type": "sde-dpmsolver++"},
|
|
|
|
),
|
2024-07-29 19:52:15 +00:00
|
|
|
"dpmpp_3m": (DPMSolverMultistepScheduler, {"use_karras_sigmas": False, "solver_order": 3}),
|
|
|
|
"dpmpp_3m_k": (DPMSolverMultistepScheduler, {"use_karras_sigmas": True, "solver_order": 3}),
|
2023-11-10 23:44:43 +00:00
|
|
|
"dpmpp_sde": (DPMSolverSDEScheduler, {"use_karras_sigmas": False, "noise_sampler_seed": 0}),
|
|
|
|
"dpmpp_sde_k": (DPMSolverSDEScheduler, {"use_karras_sigmas": True, "noise_sampler_seed": 0}),
|
2024-07-29 12:14:34 +00:00
|
|
|
"unipc": (UniPCMultistepScheduler, {"use_karras_sigmas": False, "cpu_only": True}),
|
|
|
|
"unipc_k": (UniPCMultistepScheduler, {"use_karras_sigmas": True, "cpu_only": True}),
|
2023-11-10 23:44:43 +00:00
|
|
|
"lcm": (LCMScheduler, {}),
|
2024-04-03 06:03:02 +00:00
|
|
|
"tcd": (TCDScheduler, {}),
|
2023-11-10 23:44:43 +00:00
|
|
|
}
|