From 3acf95e7a492db5d9ae048deebe1d3a8a669ac1a Mon Sep 17 00:00:00 2001 From: Jedrzej Kosinski Date: Mon, 15 Jul 2024 16:12:56 -0500 Subject: [PATCH] Added autosize on a bunch more nodes, added Sigma Schedule to Sigmas node --- animatediff/nodes.py | 6 +++-- animatediff/nodes_ad_settings.py | 11 ++++++++ animatediff/nodes_conditioning.py | 30 +++++++++++++++++++--- animatediff/nodes_lora.py | 13 ++++++---- animatediff/nodes_sample.py | 10 ++++++++ animatediff/nodes_sigma_schedule.py | 40 +++++++++++++++++++++++++++++ 6 files changed, 99 insertions(+), 11 deletions(-) diff --git a/animatediff/nodes.py b/animatediff/nodes.py index 5597df2..62af7ff 100644 --- a/animatediff/nodes.py +++ b/animatediff/nodes.py @@ -23,7 +23,7 @@ from .nodes_sample import (FreeInitOptionsNode, NoiseLayerAddWeightedNode, Sampl CustomCFGNode, CustomCFGSimpleNode, CustomCFGKeyframeNode, CustomCFGKeyframeSimpleNode, CFGExtrasPAGNode, CFGExtrasPAGSimpleNode, CFGExtrasRescaleCFGNode, CFGExtrasRescaleCFGSimpleNode, NoisedImageInjectionNode, NoisedImageInjectOptionsNode) -from .nodes_sigma_schedule import (SigmaScheduleNode, RawSigmaScheduleNode, WeightedAverageSigmaScheduleNode, InterpolatedWeightedAverageSigmaScheduleNode, SplitAndCombineSigmaScheduleNode) +from .nodes_sigma_schedule import (SigmaScheduleNode, RawSigmaScheduleNode, WeightedAverageSigmaScheduleNode, InterpolatedWeightedAverageSigmaScheduleNode, SplitAndCombineSigmaScheduleNode, SigmaScheduleToSigmasNode) from .nodes_context import (LegacyLoopedUniformContextOptionsNode, LoopedUniformContextOptionsNode, LoopedUniformViewOptionsNode, StandardUniformContextOptionsNode, StandardStaticContextOptionsNode, BatchedContextOptionsNode, StandardStaticViewOptionsNode, StandardUniformViewOptionsNode, ViewAsContextOptionsNode, VisualizeContextOptionsK, VisualizeContextOptionsKAdv, VisualizeContextOptionsSCustom) @@ -115,6 +115,7 @@ NODE_CLASS_MAPPINGS = { "ADE_SigmaScheduleWeightedAverage": WeightedAverageSigmaScheduleNode, "ADE_SigmaScheduleWeightedAverageInterp": InterpolatedWeightedAverageSigmaScheduleNode, "ADE_SigmaScheduleSplitAndCombine": SplitAndCombineSigmaScheduleNode, + "ADE_SigmaScheduleToSigmas": SigmaScheduleToSigmasNode, "ADE_NoisedImageInjection": NoisedImageInjectionNode, "ADE_NoisedImageInjectOptions": NoisedImageInjectOptionsNode, "ADE_CFGExtrasPAGSimple": CFGExtrasPAGSimpleNode, @@ -220,7 +221,7 @@ NODE_DISPLAY_NAME_MAPPINGS = { "ADE_NoiseLayerReplace": "Noise Layer [Replace] πŸŽ­πŸ…πŸ…“", # AnimateDiff Settings "ADE_AnimateDiffSettings": "AnimateDiff Settings πŸŽ­πŸ…πŸ…“", - "ADE_AdjustPESweetspotStretch": "Adjust PE [Sweetspot Stretch] πŸŽ­πŸ…πŸ…“", + "ADE_AdjustPESweetspotStretch": "Adjust PE [Sweetspot] πŸŽ­πŸ…πŸ…“", "ADE_AdjustPEFullStretch": "Adjust PE [Full Stretch] πŸŽ­πŸ…πŸ…“", "ADE_AdjustPEManual": "Adjust PE [Manual] πŸŽ­πŸ…πŸ…“", "ADE_AdjustWeightAllAdd": "Adjust Weight [Allβ—†Add] πŸŽ­πŸ…πŸ…“", @@ -239,6 +240,7 @@ NODE_DISPLAY_NAME_MAPPINGS = { "ADE_SigmaScheduleWeightedAverage": "Sigma Schedule Weighted Mean πŸŽ­πŸ…πŸ…“", "ADE_SigmaScheduleWeightedAverageInterp": "Sigma Schedule Interpolated Mean πŸŽ­πŸ…πŸ…“", "ADE_SigmaScheduleSplitAndCombine": "Sigma Schedule Split Combine πŸŽ­πŸ…πŸ…“", + "ADE_SigmaScheduleToSigmas": "Sigma Schedule To Sigmas πŸŽ­πŸ…πŸ…“", "ADE_NoisedImageInjection": "Image Injection πŸŽ­πŸ…πŸ…“", "ADE_NoisedImageInjectOptions": "Image Injection Options πŸŽ­πŸ…πŸ…“", "ADE_CFGExtrasPAGSimple": "CFG Extrasβ—†PAG πŸŽ­πŸ…πŸ…“", diff --git a/animatediff/nodes_ad_settings.py b/animatediff/nodes_ad_settings.py index fbe8dd2..e99364b 100644 --- a/animatediff/nodes_ad_settings.py +++ b/animatediff/nodes_ad_settings.py @@ -9,6 +9,7 @@ class AnimateDiffSettingsNode: "optional": { "pe_adjust": ("PE_ADJUST",), "weight_adjust": ("WEIGHT_ADJUST",), + "autosize": ("ADEAUTOSIZE", {"padding": 0}), } } @@ -30,9 +31,11 @@ class ManualAdjustPENode: "initial_pe_idx_offset": ("INT", {"default": 0, "min": 0, "step": 1}), "final_pe_idx_offset": ("INT", {"default": 0, "min": 0, "step": 1}), "print_adjustment": ("BOOLEAN", {"default": False}), + }, "optional": { "prev_pe_adjust": ("PE_ADJUST",), + "autosize": ("ADEAUTOSIZE", {"padding": 30}), } } @@ -64,6 +67,7 @@ class SweetspotStretchPENode: }, "optional": { "prev_pe_adjust": ("PE_ADJUST",), + "autosize": ("ADEAUTOSIZE", {"padding": 20}), } } @@ -91,6 +95,7 @@ class FullStretchPENode: }, "optional": { "prev_pe_adjust": ("PE_ADJUST",), + "autosize": ("ADEAUTOSIZE", {"padding": 30}), } } @@ -118,6 +123,7 @@ class WeightAdjustAllAddNode: }, "optional": { "prev_weight_adjust": ("WEIGHT_ADJUST",), + "autosize": ("ADEAUTOSIZE", {"padding": 0}), } } @@ -147,6 +153,7 @@ class WeightAdjustAllMultNode: }, "optional": { "prev_weight_adjust": ("WEIGHT_ADJUST",), + "autosize": ("ADEAUTOSIZE", {"padding": 0}), } } @@ -178,6 +185,7 @@ class WeightAdjustIndivAddNode: }, "optional": { "prev_weight_adjust": ("WEIGHT_ADJUST",), + "autosize": ("ADEAUTOSIZE", {"padding": 0}), } } @@ -211,6 +219,7 @@ class WeightAdjustIndivMultNode: }, "optional": { "prev_weight_adjust": ("WEIGHT_ADJUST",), + "autosize": ("ADEAUTOSIZE", {"padding": 0}), } } @@ -249,6 +258,7 @@ class WeightAdjustIndivAttnAddNode: }, "optional": { "prev_weight_adjust": ("WEIGHT_ADJUST",), + "autosize": ("ADEAUTOSIZE", {"padding": 20}), } } @@ -295,6 +305,7 @@ class WeightAdjustIndivAttnMultNode: }, "optional": { "prev_weight_adjust": ("WEIGHT_ADJUST",), + "autosize": ("ADEAUTOSIZE", {"padding": 20}), } } diff --git a/animatediff/nodes_conditioning.py b/animatediff/nodes_conditioning.py index 87121e9..6a95465 100644 --- a/animatediff/nodes_conditioning.py +++ b/animatediff/nodes_conditioning.py @@ -32,7 +32,8 @@ class PairedConditioningSetMaskHooked: "optional": { "opt_mask": ("MASK", ), "opt_lora_hook": ("LORA_HOOK",), - "opt_timesteps": ("TIMESTEPS_COND",) + "opt_timesteps": ("TIMESTEPS_COND",), + "autosize": ("ADEAUTOSIZE", {"padding": 0}), } } @@ -62,7 +63,8 @@ class ConditioningSetMaskHooked: "optional": { "opt_mask": ("MASK", ), "opt_lora_hook": ("LORA_HOOK",), - "opt_timesteps": ("TIMESTEPS_COND",) + "opt_timesteps": ("TIMESTEPS_COND",), + "autosize": ("ADEAUTOSIZE", {"padding": 0}), } } @@ -94,7 +96,8 @@ class PairedConditioningSetMaskAndCombineHooked: "optional": { "opt_mask": ("MASK", ), "opt_lora_hook": ("LORA_HOOK",), - "opt_timesteps": ("TIMESTEPS_COND",) + "opt_timesteps": ("TIMESTEPS_COND",), + "autosize": ("ADEAUTOSIZE", {"padding": 70}), } } @@ -125,7 +128,8 @@ class ConditioningSetMaskAndCombineHooked: "optional": { "opt_mask": ("MASK", ), "opt_lora_hook": ("LORA_HOOK",), - "opt_timesteps": ("TIMESTEPS_COND",) + "opt_timesteps": ("TIMESTEPS_COND",), + "autosize": ("ADEAUTOSIZE", {"padding": 55}), } } @@ -154,6 +158,7 @@ class PairedConditioningSetUnmaskedAndCombineHooked: }, "optional": { "opt_lora_hook": ("LORA_HOOK",), + "autosize": ("ADEAUTOSIZE", {"padding": 10}), } } @@ -179,6 +184,7 @@ class ConditioningSetUnmaskedAndCombineHooked: }, "optional": { "opt_lora_hook": ("LORA_HOOK",), + "autosize": ("ADEAUTOSIZE", {"padding": 0}), } } @@ -207,6 +213,9 @@ class ConditioningTimestepsNode: "required": { "start_percent": ("FLOAT", {"default": 0.0, "min": 0.0, "max": 1.0, "step": 0.001}), "end_percent": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.001}) + }, + "optional": { + "autosize": ("ADEAUTOSIZE", {"padding": 25}), } } @@ -225,6 +234,9 @@ class SetLoraHookKeyframes: "required": { "lora_hook": ("LORA_HOOK",), "hook_kf": ("LORA_HOOK_KEYFRAMES",), + }, + "optional": { + "autosize": ("ADEAUTOSIZE", {"padding": 40}), } } @@ -249,6 +261,7 @@ class CreateLoraHookKeyframe: }, "optional": { "prev_hook_kf": ("LORA_HOOK_KEYFRAMES",), + "autosize": ("ADEAUTOSIZE", {"padding": 5}), } } @@ -503,6 +516,9 @@ class SetModelLoraHook: "required": { "conditioning": ("CONDITIONING",), "lora_hook": ("LORA_HOOK",), + }, + "optional": { + "autosize": ("ADEAUTOSIZE", {"padding": 5}), } } @@ -526,6 +542,9 @@ class SetClipLoraHook: "required": { "clip": ("CLIP",), "lora_hook": ("LORA_HOOK",), + }, + "optional": { + "autosize": ("ADEAUTOSIZE", {"padding": 0}), } } @@ -549,6 +568,7 @@ class CombineLoraHooks: "optional": { "lora_hook_A": ("LORA_HOOK",), "lora_hook_B": ("LORA_HOOK",), + "autosize": ("ADEAUTOSIZE", {"padding": 30}), } } @@ -572,6 +592,7 @@ class CombineLoraHookFourOptional: "lora_hook_B": ("LORA_HOOK",), "lora_hook_C": ("LORA_HOOK",), "lora_hook_D": ("LORA_HOOK",), + "autosize": ("ADEAUTOSIZE", {"padding": 30}), } } @@ -601,6 +622,7 @@ class CombineLoraHookEightOptional: "lora_hook_F": ("LORA_HOOK",), "lora_hook_G": ("LORA_HOOK",), "lora_hook_H": ("LORA_HOOK",), + "autosize": ("ADEAUTOSIZE", {"padding": 30}), } } diff --git a/animatediff/nodes_lora.py b/animatediff/nodes_lora.py index 3286962..1f1524c 100644 --- a/animatediff/nodes_lora.py +++ b/animatediff/nodes_lora.py @@ -14,11 +14,12 @@ class AnimateDiffLoraLoader: def INPUT_TYPES(s): return { "required": { - "lora_name": (get_available_motion_loras(),), + "name": (get_available_motion_loras(),), "strength": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.001}), }, "optional": { "prev_motion_lora": ("MOTION_LORA",), + "autosize": ("ADEAUTOSIZE", {"padding": 30}), } } @@ -26,17 +27,19 @@ class AnimateDiffLoraLoader: CATEGORY = "Animate Diff πŸŽ­πŸ…πŸ…“" FUNCTION = "load_motion_lora" - def load_motion_lora(self, lora_name: str, strength: float, prev_motion_lora: MotionLoraList=None): + def load_motion_lora(self, name: str, strength: float, prev_motion_lora: MotionLoraList=None, lora_name: str=None): if prev_motion_lora is None: prev_motion_lora = MotionLoraList() else: prev_motion_lora = prev_motion_lora.clone() + if lora_name is not None: # backwards compatibility + name = lora_name # check if motion lora with name exists - lora_path = get_motion_lora_path(lora_name) + lora_path = get_motion_lora_path(name) if not Path(lora_path).is_file(): - raise FileNotFoundError(f"Motion lora with name '{lora_name}' not found.") + raise FileNotFoundError(f"Motion lora with name '{name}' not found.") # create motion lora info to be loaded in AnimateDiff Loader - lora_info = MotionLoraInfo(name=lora_name, strength=strength) + lora_info = MotionLoraInfo(name=name, strength=strength) prev_motion_lora.add_lora(lora_info) return (prev_motion_lora,) diff --git a/animatediff/nodes_sample.py b/animatediff/nodes_sample.py index a5e147c..5d8b772 100644 --- a/animatediff/nodes_sample.py +++ b/animatediff/nodes_sample.py @@ -32,6 +32,7 @@ class SampleSettingsNode: "custom_cfg": ("CUSTOM_CFG",), "sigma_schedule": ("SIGMA_SCHEDULE",), "image_inject": ("IMAGE_INJECT",), + "autosize": ("ADEAUTOSIZE", {"padding": 10}), } } @@ -63,6 +64,7 @@ class NoiseLayerReplaceNode: "prev_noise_layers": ("NOISE_LAYERS",), "mask_optional": ("MASK",), "seed_override": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "forceInput": True}), + "autosize": ("ADEAUTOSIZE", {"padding": 20}), } } @@ -98,6 +100,7 @@ class NoiseLayerAddNode: "prev_noise_layers": ("NOISE_LAYERS",), "mask_optional": ("MASK",), "seed_override": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "forceInput": True}), + "autosize": ("ADEAUTOSIZE", {"padding": 20}), } } @@ -136,6 +139,7 @@ class NoiseLayerAddWeightedNode: "prev_noise_layers": ("NOISE_LAYERS",), "mask_optional": ("MASK",), "seed_override": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "forceInput": True}), + "autosize": ("ADEAUTOSIZE", {"padding": 10}), } } @@ -197,6 +201,7 @@ class FreeInitOptionsNode: "optional": { "iter_batch_offset": ("INT", {"default": 0, "min": 0, "max": BIGMAX}), "iter_seed_offset": ("INT", {"default": 1, "min": BIGMIN, "max": BIGMAX}), + "autosize": ("ADEAUTOSIZE", {"padding": 55}), } } @@ -324,6 +329,7 @@ class CFGExtrasPAGNode: }, "optional": { "prev_extras": ("CFG_EXTRAS",), + "autosize": ("ADEAUTOSIZE", {"padding": 45}), } } @@ -355,6 +361,7 @@ class CFGExtrasPAGSimpleNode: }, "optional": { "prev_extras": ("CFG_EXTRAS",), + "autosize": ("ADEAUTOSIZE", {"padding": 0}), } } @@ -407,6 +414,7 @@ class CFGExtrasRescaleCFGSimpleNode: }, "optional": { "prev_extras": ("CFG_EXTRAS",), + "autosize": ("ADEAUTOSIZE", {"padding": 45}), } } @@ -436,6 +444,7 @@ class NoisedImageInjectionNode: "img_inject_opts": ("IMAGE_INJECT_OPTIONS", ), "strength_multival": ("MULTIVAL", ), "prev_image_inject": ("IMAGE_INJECT", ), + "autosize": ("ADEAUTOSIZE", {"padding": 0}), } } @@ -465,6 +474,7 @@ class NoisedImageInjectOptionsNode: "optional": { "composite_x": ("INT", {"default": 0, "min": 0, "max": MAX_RESOLUTION, "step": 1}), "composite_y": ("INT", {"default": 0, "min": 0, "max": MAX_RESOLUTION, "step": 1}), + "autosize": ("ADEAUTOSIZE", {"padding": 30}), } } diff --git a/animatediff/nodes_sigma_schedule.py b/animatediff/nodes_sigma_schedule.py index 4431c7a..20580a2 100644 --- a/animatediff/nodes_sigma_schedule.py +++ b/animatediff/nodes_sigma_schedule.py @@ -1,5 +1,7 @@ import torch +import comfy.samplers + from .utils_model import BetaSchedules, SigmaSchedule, ModelSamplingType, ModelSamplingConfig, InterpolationMethod @@ -71,6 +73,9 @@ class WeightedAverageSigmaScheduleNode: "schedule_A": ("SIGMA_SCHEDULE",), "schedule_B": ("SIGMA_SCHEDULE",), "weight_A": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.001}), + }, + "optional": { + "autosize": ("ADEAUTOSIZE", {"padding": 80}), } } @@ -124,6 +129,9 @@ class SplitAndCombineSigmaScheduleNode: "schedule_Start": ("SIGMA_SCHEDULE",), "schedule_End": ("SIGMA_SCHEDULE",), "idx_split_percent": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.001}) + }, + "optional": { + "autosize": ("ADEAUTOSIZE", {"padding": 40}), } } @@ -139,3 +147,35 @@ class SplitAndCombineSigmaScheduleNode: new_schedule = schedule_Start.clone() new_schedule.model_sampling.set_sigmas(new_sigmas) return (new_schedule,) + + +class SigmaScheduleToSigmasNode: + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "sigma_schedule": ("SIGMA_SCHEDULE",), + "scheduler": (comfy.samplers.SCHEDULER_NAMES, ), + "steps": ("INT", {"default": 20, "min": 1, "max": 10000}), + "denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}), + }, + "optional": { + "autosize": ("ADEAUTOSIZE", {"padding": 50}), + } + } + + RETURN_TYPES = ("SIGMAS",) + CATEGORY = "Animate Diff πŸŽ­πŸ…πŸ…“/sample settings/sigma schedule" + FUNCTION = "get_sigmas" + + def get_sigmas(self, sigma_schedule: SigmaSchedule, scheduler: str, steps: int, denoise: float): + total_steps = steps + if denoise < 1.0: + if denoise <= 0.0: + return (torch.FloatTensor([]),) + total_steps = int(steps/denoise) + + sigmas = comfy.samplers.calculate_sigmas(sigma_schedule, scheduler, total_steps).cpu() + sigmas = sigmas[-(steps + 1):] + return (sigmas, ) + \ No newline at end of file