From 8a836247c82650a2edae75c8d2248d31a31cf7c5 Mon Sep 17 00:00:00 2001 From: blessedcoolant <54517381+blessedcoolant@users.noreply.github.com> Date: Fri, 12 May 2023 02:23:33 +1200 Subject: [PATCH] Add DPMPP Single, Euler Karras and DPMPP2 Multi Karras Schedulers --- invokeai/app/invocations/latent.py | 7 +++++- invokeai/backend/args.py | 20 +++++++-------- invokeai/backend/generator/base.py | 7 +++++- .../stable_diffusion/schedulers/schedulers.py | 25 +++++++++++-------- invokeai/backend/web/modules/parameters.py | 20 +++++++-------- invokeai/frontend/web/src/app/constants.ts | 12 +++++---- .../frontend/web/src/app/types/invokeai.ts | 19 ++++++++------ 7 files changed, 64 insertions(+), 46 deletions(-) diff --git a/invokeai/app/invocations/latent.py b/invokeai/app/invocations/latent.py index 349a13bf3d..75fa719c07 100644 --- a/invokeai/app/invocations/latent.py +++ b/invokeai/app/invocations/latent.py @@ -60,8 +60,13 @@ SAMPLER_NAME_VALUES = Literal[ def get_scheduler(scheduler_name:str, model: StableDiffusionGeneratorPipeline)->Scheduler: scheduler_class, scheduler_extra_config = SCHEDULER_MAP.get(scheduler_name, SCHEDULER_MAP['ddim']) - scheduler_config = {**model.scheduler.config, **scheduler_extra_config} + + scheduler_config = model.scheduler.config + if "_backup" in scheduler_config: + scheduler_config = scheduler_config["_backup"] + scheduler_config = {**scheduler_config, **scheduler_extra_config, "_backup": scheduler_config} scheduler = scheduler_class.from_config(scheduler_config) + # hack copied over from generate.py if not hasattr(scheduler, 'uses_inpainting_model'): scheduler.uses_inpainting_model = lambda: False diff --git a/invokeai/backend/args.py b/invokeai/backend/args.py index 8cbeea10ad..0efaf6fd26 100644 --- a/invokeai/backend/args.py +++ b/invokeai/backend/args.py @@ -108,18 +108,18 @@ APP_VERSION = invokeai.version.__version__ SAMPLER_CHOICES = [ "ddim", - "k_dpm_2_a", - "k_dpm_2", - "k_dpmpp_2_a", - "k_dpmpp_2", - "k_euler_a", - "k_euler", - "k_heun", "k_lms", "plms", - # diffusers: - "pndm", - "unipc" + "k_heun", + "k_euler", + "euler_karras", + "k_euler_a", + "k_dpm_2", + "k_dpm_2_a", + "dpmpp_2s", + "k_dpmpp_2", + "k_dpmpp_2_karras", + "unipc", ] PRECISION_CHOICES = [ diff --git a/invokeai/backend/generator/base.py b/invokeai/backend/generator/base.py index 317110b35b..8f5b1a8395 100644 --- a/invokeai/backend/generator/base.py +++ b/invokeai/backend/generator/base.py @@ -170,8 +170,13 @@ class InvokeAIGenerator(metaclass=ABCMeta): def get_scheduler(self, scheduler_name:str, model: StableDiffusionGeneratorPipeline)->Scheduler: scheduler_class, scheduler_extra_config = SCHEDULER_MAP.get(scheduler_name, SCHEDULER_MAP['ddim']) - scheduler_config = {**model.scheduler.config, **scheduler_extra_config} + + scheduler_config = model.scheduler.config + if "_backup" in scheduler_config: + scheduler_config = scheduler_config["_backup"] + scheduler_config = {**scheduler_config, **scheduler_extra_config, "_backup": scheduler_config} scheduler = scheduler_class.from_config(scheduler_config) + # hack copied over from generate.py if not hasattr(scheduler, 'uses_inpainting_model'): scheduler.uses_inpainting_model = lambda: False diff --git a/invokeai/backend/stable_diffusion/schedulers/schedulers.py b/invokeai/backend/stable_diffusion/schedulers/schedulers.py index 00d3675fe5..98d73ae10b 100644 --- a/invokeai/backend/stable_diffusion/schedulers/schedulers.py +++ b/invokeai/backend/stable_diffusion/schedulers/schedulers.py @@ -1,17 +1,20 @@ from diffusers import DDIMScheduler, DPMSolverMultistepScheduler, KDPM2DiscreteScheduler, \ KDPM2AncestralDiscreteScheduler, EulerDiscreteScheduler, EulerAncestralDiscreteScheduler, \ - HeunDiscreteScheduler, LMSDiscreteScheduler, PNDMScheduler, UniPCMultistepScheduler + HeunDiscreteScheduler, LMSDiscreteScheduler, PNDMScheduler, UniPCMultistepScheduler, \ + DPMSolverSinglestepScheduler SCHEDULER_MAP = dict( - ddim=(DDIMScheduler, dict(cpu_only=False)), - dpmpp_2=(DPMSolverMultistepScheduler, dict(cpu_only=False)), - k_dpm_2=(KDPM2DiscreteScheduler, dict(cpu_only=False)), - k_dpm_2_a=(KDPM2AncestralDiscreteScheduler, dict(cpu_only=False)), - k_dpmpp_2=(DPMSolverMultistepScheduler, dict(cpu_only=False)), - k_euler=(EulerDiscreteScheduler, dict(cpu_only=False)), - k_euler_a=(EulerAncestralDiscreteScheduler, dict(cpu_only=False)), - k_heun=(HeunDiscreteScheduler, dict(cpu_only=False)), - k_lms=(LMSDiscreteScheduler, dict(cpu_only=False)), - plms=(PNDMScheduler, dict(cpu_only=False)), + ddim=(DDIMScheduler, dict()), + k_lms=(LMSDiscreteScheduler, dict()), + plms=(PNDMScheduler, dict()), + k_euler=(EulerDiscreteScheduler, dict(use_karras_sigmas=False)), + euler_karras=(EulerDiscreteScheduler, dict(use_karras_sigmas=True)), + k_euler_a=(EulerAncestralDiscreteScheduler, dict()), + k_dpm_2=(KDPM2DiscreteScheduler, dict()), + k_dpm_2_a=(KDPM2AncestralDiscreteScheduler, dict()), + dpmpp_2s=(DPMSolverSinglestepScheduler, dict()), + k_dpmpp_2=(DPMSolverMultistepScheduler, dict(use_karras_sigmas=False)), + k_dpmpp_2_karras=(DPMSolverMultistepScheduler, dict(use_karras_sigmas=True)), + k_heun=(HeunDiscreteScheduler, dict()), unipc=(UniPCMultistepScheduler, dict(cpu_only=True)) ) diff --git a/invokeai/backend/web/modules/parameters.py b/invokeai/backend/web/modules/parameters.py index 9c06f68097..f25864765b 100644 --- a/invokeai/backend/web/modules/parameters.py +++ b/invokeai/backend/web/modules/parameters.py @@ -4,18 +4,18 @@ from .parse_seed_weights import parse_seed_weights SAMPLER_CHOICES = [ "ddim", - "k_dpm_2_a", - "k_dpm_2", - "k_dpmpp_2_a", - "k_dpmpp_2", - "k_euler_a", - "k_euler", - "k_heun", "k_lms", "plms", - # diffusers: - "pndm", - "unipc" + "k_heun", + "k_euler", + "euler_karras", + "k_euler_a", + "k_dpm_2", + "k_dpm_2_a", + "dpmpp_2s", + "k_dpmpp_2", + "k_dpmpp_2_karras", + "unipc", ] diff --git a/invokeai/frontend/web/src/app/constants.ts b/invokeai/frontend/web/src/app/constants.ts index 2d89ffe31e..d9a606435c 100644 --- a/invokeai/frontend/web/src/app/constants.ts +++ b/invokeai/frontend/web/src/app/constants.ts @@ -2,15 +2,17 @@ export const DIFFUSERS_SCHEDULERS: Array = [ 'ddim', - 'plms', 'k_lms', - 'dpmpp_2', + 'plms', + 'k_heun', + 'k_euler', + 'euler_karras', + 'k_euler_a', 'k_dpm_2', 'k_dpm_2_a', + 'dpmpp_2s', 'k_dpmpp_2', - 'k_euler', - 'k_euler_a', - 'k_heun', + 'k_dpmpp_2_karras', 'unipc', ]; diff --git a/invokeai/frontend/web/src/app/types/invokeai.ts b/invokeai/frontend/web/src/app/types/invokeai.ts index 4023f7665d..0d8fe4bbdc 100644 --- a/invokeai/frontend/web/src/app/types/invokeai.ts +++ b/invokeai/frontend/web/src/app/types/invokeai.ts @@ -47,15 +47,18 @@ export type CommonGeneratedImageMetadata = { postprocessing: null | Array; sampler: | 'ddim' - | 'k_dpm_2_a' - | 'k_dpm_2' - | 'k_dpmpp_2_a' - | 'k_dpmpp_2' - | 'k_euler_a' - | 'k_euler' - | 'k_heun' | 'k_lms' - | 'plms'; + | 'plms' + | 'k_heun' + | 'k_euler' + | 'euler_karras' + | 'k_euler_a' + | 'k_dpm_2' + | 'k_dpm_2_a' + | 'dpmpp_2s' + | 'k_dpmpp_2' + | 'k_dpmpp_2_karras' + | 'unipc'; prompt: Prompt; seed: number; variations: SeedWeights;