From 71c3197eab87bc6564531e86d63acf26ed5b65f9 Mon Sep 17 00:00:00 2001 From: dunkeroni Date: Sat, 27 Apr 2024 14:40:52 -0400 Subject: [PATCH 1/2] fix: denoise latents accepts CFG lists as input --- invokeai/app/invocations/latent.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/invokeai/app/invocations/latent.py b/invokeai/app/invocations/latent.py index 66d6a70e40..85208e866e 100644 --- a/invokeai/app/invocations/latent.py +++ b/invokeai/app/invocations/latent.py @@ -25,7 +25,7 @@ from diffusers.models.unets.unet_2d_condition import UNet2DConditionModel from diffusers.schedulers import DPMSolverSDEScheduler from diffusers.schedulers import SchedulerMixin as Scheduler from PIL import Image, ImageFilter -from pydantic import field_validator +from pydantic import ValidationInfo, field_validator from torchvision.transforms.functional import resize as tv_resize from transformers import CLIPVisionModelWithProjection @@ -341,7 +341,7 @@ class DenoiseLatentsInvocation(BaseInvocation): ) steps: int = InputField(default=10, gt=0, description=FieldDescriptions.steps) cfg_scale: Union[float, List[float]] = InputField( - default=7.5, ge=1, description=FieldDescriptions.cfg_scale, title="CFG Scale" + default=7.5, description=FieldDescriptions.cfg_scale, title="CFG Scale" ) denoising_start: float = InputField( default=0.0, @@ -397,12 +397,14 @@ class DenoiseLatentsInvocation(BaseInvocation): ) @field_validator("cfg_scale") - def ge_one(cls, v: Union[List[float], float]) -> Union[List[float], float]: + def ge_one(cls, v: Union[List[float], float], info: ValidationInfo) -> Union[List[float], float]: """validate that all cfg_scale values are >= 1""" if isinstance(v, list): for i in v: if i < 1: raise ValueError("cfg_scale must be greater than 1") + if len(v) != info.data["steps"]: + raise ValueError("cfg_scale (list) must have the same length as the number of steps") else: if v < 1: raise ValueError("cfg_scale must be greater than 1") From f262b9032debbf01cc2dfc31f3f95aecc6765dd5 Mon Sep 17 00:00:00 2001 From: dunkeroni Date: Sat, 27 Apr 2024 15:12:06 -0400 Subject: [PATCH 2/2] fix: changed validation to not error on connection --- invokeai/app/invocations/latent.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/invokeai/app/invocations/latent.py b/invokeai/app/invocations/latent.py index 85208e866e..4ad63f4f89 100644 --- a/invokeai/app/invocations/latent.py +++ b/invokeai/app/invocations/latent.py @@ -25,7 +25,7 @@ from diffusers.models.unets.unet_2d_condition import UNet2DConditionModel from diffusers.schedulers import DPMSolverSDEScheduler from diffusers.schedulers import SchedulerMixin as Scheduler from PIL import Image, ImageFilter -from pydantic import ValidationInfo, field_validator +from pydantic import field_validator from torchvision.transforms.functional import resize as tv_resize from transformers import CLIPVisionModelWithProjection @@ -397,14 +397,12 @@ class DenoiseLatentsInvocation(BaseInvocation): ) @field_validator("cfg_scale") - def ge_one(cls, v: Union[List[float], float], info: ValidationInfo) -> Union[List[float], float]: + def ge_one(cls, v: Union[List[float], float]) -> Union[List[float], float]: """validate that all cfg_scale values are >= 1""" if isinstance(v, list): for i in v: if i < 1: raise ValueError("cfg_scale must be greater than 1") - if len(v) != info.data["steps"]: - raise ValueError("cfg_scale (list) must have the same length as the number of steps") else: if v < 1: raise ValueError("cfg_scale must be greater than 1") @@ -565,6 +563,11 @@ class DenoiseLatentsInvocation(BaseInvocation): dtype=unet.dtype, ) + if isinstance(self.cfg_scale, list): + assert ( + len(self.cfg_scale) == self.steps + ), "cfg_scale (list) must have the same length as the number of steps" + conditioning_data = TextConditioningData( uncond_text=uncond_text_embedding, cond_text=cond_text_embedding,