daquanzhou
merge github repos and lfs track ckpt/path/safetensors/pt
613c9ab
from typing import Union
from torch import Tensor
from .freeinit import FreeInitFilter
from .sample_settings import (FreeInitOptions, IterationOptions,
NoiseLayerAdd, NoiseLayerAddWeighted, NoiseLayerGroup, NoiseLayerReplace, NoiseLayerType,
SeedNoiseGeneration, SampleSettings, CustomCFGKeyframeGroup, CustomCFGKeyframe)
from .utils_model import BIGMIN, BIGMAX, SigmaSchedule
class SampleSettingsNode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"batch_offset": ("INT", {"default": 0, "min": 0, "max": BIGMAX}),
"noise_type": (NoiseLayerType.LIST,),
"seed_gen": (SeedNoiseGeneration.LIST,),
"seed_offset": ("INT", {"default": 0, "min": BIGMIN, "max": BIGMAX}),
},
"optional": {
"noise_layers": ("NOISE_LAYERS",),
"iteration_opts": ("ITERATION_OPTS",),
"seed_override": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "forceInput": True}),
"adapt_denoise_steps": ("BOOLEAN", {"default": False},),
"custom_cfg": ("CUSTOM_CFG",),
"sigma_schedule": ("SIGMA_SCHEDULE",),
}
}
RETURN_TYPES = ("SAMPLE_SETTINGS",)
RETURN_NAMES = ("settings",)
CATEGORY = "Animate Diff πŸŽ­πŸ…πŸ…“"
FUNCTION = "create_settings"
def create_settings(self, batch_offset: int, noise_type: str, seed_gen: str, seed_offset: int, noise_layers: NoiseLayerGroup=None,
iteration_opts: IterationOptions=None, seed_override: int=None, adapt_denoise_steps=False,
custom_cfg: CustomCFGKeyframeGroup=None, sigma_schedule: SigmaSchedule=None):
sampling_settings = SampleSettings(batch_offset=batch_offset, noise_type=noise_type, seed_gen=seed_gen, seed_offset=seed_offset, noise_layers=noise_layers,
iteration_opts=iteration_opts, seed_override=seed_override, adapt_denoise_steps=adapt_denoise_steps,
custom_cfg=custom_cfg, sigma_schedule=sigma_schedule)
return (sampling_settings,)
class NoiseLayerReplaceNode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"batch_offset": ("INT", {"default": 0, "min": 0, "max": BIGMAX}),
"noise_type": (NoiseLayerType.LIST,),
"seed_gen_override": (SeedNoiseGeneration.LIST_WITH_OVERRIDE,),
"seed_offset": ("INT", {"default": 0, "min": BIGMIN, "max": BIGMAX}),
},
"optional": {
"prev_noise_layers": ("NOISE_LAYERS",),
"mask_optional": ("MASK",),
"seed_override": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "forceInput": True}),
}
}
RETURN_TYPES = ("NOISE_LAYERS",)
CATEGORY = "Animate Diff πŸŽ­πŸ…πŸ…“/noise layers"
FUNCTION = "create_layers"
def create_layers(self, batch_offset: int, noise_type: str, seed_gen_override: str, seed_offset: int,
prev_noise_layers: NoiseLayerGroup=None, mask_optional: Tensor=None, seed_override: int=None,):
# prepare prev_noise_layers
if prev_noise_layers is None:
prev_noise_layers = NoiseLayerGroup()
prev_noise_layers = prev_noise_layers.clone()
# create layer
layer = NoiseLayerReplace(noise_type=noise_type, batch_offset=batch_offset, seed_gen_override=seed_gen_override, seed_offset=seed_offset,
seed_override=seed_override, mask=mask_optional)
prev_noise_layers.add_to_start(layer)
return (prev_noise_layers,)
class NoiseLayerAddNode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"batch_offset": ("INT", {"default": 0, "min": 0, "max": BIGMAX}),
"noise_type": (NoiseLayerType.LIST,),
"seed_gen_override": (SeedNoiseGeneration.LIST_WITH_OVERRIDE,),
"seed_offset": ("INT", {"default": 0, "min": BIGMIN, "max": BIGMAX}),
"noise_weight": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 10.0, "step": 0.001}),
},
"optional": {
"prev_noise_layers": ("NOISE_LAYERS",),
"mask_optional": ("MASK",),
"seed_override": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "forceInput": True}),
}
}
RETURN_TYPES = ("NOISE_LAYERS",)
CATEGORY = "Animate Diff πŸŽ­πŸ…πŸ…“/noise layers"
FUNCTION = "create_layers"
def create_layers(self, batch_offset: int, noise_type: str, seed_gen_override: str, seed_offset: int,
noise_weight: float,
prev_noise_layers: NoiseLayerGroup=None, mask_optional: Tensor=None, seed_override: int=None,):
# prepare prev_noise_layers
if prev_noise_layers is None:
prev_noise_layers = NoiseLayerGroup()
prev_noise_layers = prev_noise_layers.clone()
# create layer
layer = NoiseLayerAdd(noise_type=noise_type, batch_offset=batch_offset, seed_gen_override=seed_gen_override, seed_offset=seed_offset,
seed_override=seed_override, mask=mask_optional,
noise_weight=noise_weight)
prev_noise_layers.add_to_start(layer)
return (prev_noise_layers,)
class NoiseLayerAddWeightedNode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"batch_offset": ("INT", {"default": 0, "min": 0, "max": BIGMAX}),
"noise_type": (NoiseLayerType.LIST,),
"seed_gen_override": (SeedNoiseGeneration.LIST_WITH_OVERRIDE,),
"seed_offset": ("INT", {"default": 0, "min": BIGMIN, "max": BIGMAX}),
"noise_weight": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 10.0, "step": 0.001}),
"balance_multiplier": ("FLOAT", {"default": 1.0, "min": 0.0, "step": 0.001}),
},
"optional": {
"prev_noise_layers": ("NOISE_LAYERS",),
"mask_optional": ("MASK",),
"seed_override": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "forceInput": True}),
}
}
RETURN_TYPES = ("NOISE_LAYERS",)
CATEGORY = "Animate Diff πŸŽ­πŸ…πŸ…“/noise layers"
FUNCTION = "create_layers"
def create_layers(self, batch_offset: int, noise_type: str, seed_gen_override: str, seed_offset: int,
noise_weight: float, balance_multiplier: float,
prev_noise_layers: NoiseLayerGroup=None, mask_optional: Tensor=None, seed_override: int=None,):
# prepare prev_noise_layers
if prev_noise_layers is None:
prev_noise_layers = NoiseLayerGroup()
prev_noise_layers = prev_noise_layers.clone()
# create layer
layer = NoiseLayerAddWeighted(noise_type=noise_type, batch_offset=batch_offset, seed_gen_override=seed_gen_override, seed_offset=seed_offset,
seed_override=seed_override, mask=mask_optional,
noise_weight=noise_weight, balance_multiplier=balance_multiplier)
prev_noise_layers.add_to_start(layer)
return (prev_noise_layers,)
class IterationOptionsNode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"iterations": ("INT", {"default": 1, "min": 1}),
},
"optional": {
"iter_batch_offset": ("INT", {"default": 0, "min": 0, "max": BIGMAX}),
"iter_seed_offset": ("INT", {"default": 0, "min": BIGMIN, "max": BIGMAX}),
}
}
RETURN_TYPES = ("ITERATION_OPTS",)
CATEGORY = "Animate Diff πŸŽ­πŸ…πŸ…“/iteration opts"
FUNCTION = "create_iter_opts"
def create_iter_opts(self, iterations: int, iter_batch_offset: int=0, iter_seed_offset: int=0):
iter_opts = IterationOptions(iterations=iterations, iter_batch_offset=iter_batch_offset, iter_seed_offset=iter_seed_offset)
return (iter_opts,)
class FreeInitOptionsNode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"iterations": ("INT", {"default": 2, "min": 1}),
"filter": (FreeInitFilter.LIST,),
"d_s": ("FLOAT", {"default": 0.25, "min": 0.0, "max": 1.0, "step": 0.001}),
"d_t": ("FLOAT", {"default": 0.25, "min": 0.0, "max": 1.0, "step": 0.001}),
"n_butterworth": ("INT", {"default": 4, "min": 1, "max": 100},),
"sigma_step": ("INT", {"default": 999, "min": 1, "max": 999}),
"apply_to_1st_iter": ("BOOLEAN", {"default": False}),
"init_type": (FreeInitOptions.LIST,)
},
"optional": {
"iter_batch_offset": ("INT", {"default": 0, "min": 0, "max": BIGMAX}),
"iter_seed_offset": ("INT", {"default": 1, "min": BIGMIN, "max": BIGMAX}),
}
}
RETURN_TYPES = ("ITERATION_OPTS",)
CATEGORY = "Animate Diff πŸŽ­πŸ…πŸ…“/iteration opts"
FUNCTION = "create_iter_opts"
def create_iter_opts(self, iterations: int, filter: str, d_s: float, d_t: float, n_butterworth: int,
sigma_step: int, apply_to_1st_iter: bool, init_type: str,
iter_batch_offset: int=0, iter_seed_offset: int=1):
# init_type does nothing for now, not until I add more methods of applying low+high freq noise
iter_opts = FreeInitOptions(iterations=iterations, step=sigma_step, apply_to_1st_iter=apply_to_1st_iter,
filter=filter, d_s=d_s, d_t=d_t, n=n_butterworth, init_type=init_type,
iter_batch_offset=iter_batch_offset, iter_seed_offset=iter_seed_offset)
return (iter_opts,)
class CustomCFGNode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"cfg_multival": ("MULTIVAL",),
}
}
RETURN_TYPES = ("CUSTOM_CFG",)
CATEGORY = "Animate Diff πŸŽ­πŸ…πŸ…“/sample settings"
FUNCTION = "create_custom_cfg"
def create_custom_cfg(self, cfg_multival: Union[float, Tensor]):
keyframe = CustomCFGKeyframe(cfg_multival=cfg_multival)
cfg_custom = CustomCFGKeyframeGroup()
cfg_custom.add(keyframe)
return (cfg_custom,)
class CustomCFGKeyframeNode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"cfg_multival": ("MULTIVAL",),
"start_percent": ("FLOAT", {"default": 0.0, "min": 0.0, "max": 1.0, "step": 0.001}),
"guarantee_steps": ("INT", {"default": 1, "min": 0, "max": BIGMAX}),
},
"optional": {
"prev_custom_cfg": ("CUSTOM_CFG",),
}
}
RETURN_TYPES = ("CUSTOM_CFG",)
CATEGORY = "Animate Diff πŸŽ­πŸ…πŸ…“/sample settings"
FUNCTION = "create_custom_cfg"
def create_custom_cfg(self, cfg_multival: Union[float, Tensor], start_percent: float=0.0, guarantee_steps: int=1,
prev_custom_cfg: CustomCFGKeyframeGroup=None):
if not prev_custom_cfg:
prev_custom_cfg = CustomCFGKeyframeGroup()
prev_custom_cfg = prev_custom_cfg.clone()
keyframe = CustomCFGKeyframe(cfg_multival=cfg_multival, start_percent=start_percent, guarantee_steps=guarantee_steps)
prev_custom_cfg.add(keyframe)
return (prev_custom_cfg,)