File size: 27,172 Bytes
82ea528 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 |
from typing import Union
from torch import Tensor
from collections.abc import Iterable
from comfy.sd import VAE
from .freeinit import FreeInitFilter
from .sample_settings import (FreeInitOptions, IterationOptions,
NoiseLayerAdd, NoiseLayerAddWeighted, NoiseLayerGroup, NoiseLayerReplace, NoiseLayerType,
SeedNoiseGeneration, SampleSettings, NoiseCalibration,
CustomCFGKeyframeGroup, CustomCFGKeyframe, CFGExtrasGroup, CFGExtras,
NoisedImageToInjectGroup, NoisedImageToInject, NoisedImageInjectOptions)
from .utils_model import BIGMIN, BIGMAX, MAX_RESOLUTION, SigmaSchedule, InterpolationMethod
from .cfg_extras import perturbed_attention_guidance_patch, rescale_cfg_patch, set_model_options_sampler_cfg_function, set_model_options_post_cfg_function
from .logger import logger
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",),
"image_inject": ("IMAGE_INJECT",),
#"noise_calib": ("NOISE_CALIBRATION",), # TODO: bring back once NoiseCalibration is working
},
"hidden": {
"autosize": ("ADEAUTOSIZE", {"padding": 0}),
}
}
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, image_inject: NoisedImageToInjectGroup=None,
noise_calib: NoiseCalibration=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, image_injection=image_inject, noise_calibration=noise_calib)
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}),
},
"hidden": {
"autosize": ("ADEAUTOSIZE", {"padding": 0}),
}
}
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}),
},
"hidden": {
"autosize": ("ADEAUTOSIZE", {"padding": 0}),
}
}
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}),
},
"hidden": {
"autosize": ("ADEAUTOSIZE", {"padding": 0}),
}
}
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}),
},
"hidden": {
"autosize": ("ADEAUTOSIZE", {"padding": 0}),
}
}
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 NoiseCalibrationNode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"calib_iterations": ("INT", {"default": 1, "min": 1, "step": 1}),
"thresh_freq": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.001}),
},
"hidden": {
"autosize": ("ADEAUTOSIZE", {"padding": 0}),
}
}
RETURN_TYPES = ("NOISE_CALIBRATION",)
RETURN_NAMES = ("NOISE_CALIB",)
CATEGORY = "Animate Diff ππ
π
/sample settings"
FUNCTION = "create_noisecalibration"
def create_noisecalibration(self, calib_iterations: int, thresh_freq: float):
noise_calib = NoiseCalibration(scale=thresh_freq, calib_iterations=calib_iterations)
return (noise_calib,)
class CustomCFGNode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"cfg_multival": ("MULTIVAL",),
},
"optional": {
"cfg_extras": ("CFG_EXTRAS",),
},
"hidden": {
"autosize": ("ADEAUTOSIZE", {"padding": 0}),
}
}
RETURN_TYPES = ("CUSTOM_CFG",)
CATEGORY = "Animate Diff ππ
π
/sample settings/custom cfg"
FUNCTION = "create_custom_cfg"
def create_custom_cfg(self, cfg_multival: Union[float, Tensor], cfg_extras: CFGExtrasGroup=None):
keyframe = CustomCFGKeyframe(cfg_multival=cfg_multival, cfg_extras=cfg_extras)
cfg_custom = CustomCFGKeyframeGroup()
cfg_custom.add(keyframe)
return (cfg_custom,)
class CustomCFGSimpleNode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0, "step": 0.1}),
},
"optional": {
"cfg_extras": ("CFG_EXTRAS",),
},
"hidden": {
"autosize": ("ADEAUTOSIZE", {"padding": 0}),
}
}
RETURN_TYPES = ("CUSTOM_CFG",)
CATEGORY = "Animate Diff ππ
π
/sample settings/custom cfg"
FUNCTION = "create_custom_cfg"
def create_custom_cfg(self, cfg: float, cfg_extras: CFGExtrasGroup=None):
return CustomCFGNode.create_custom_cfg(self, cfg_multival=cfg, cfg_extras=cfg_extras)
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",),
"cfg_extras": ("CFG_EXTRAS",),
},
"hidden": {
"autosize": ("ADEAUTOSIZE", {"padding": 0}),
}
}
RETURN_TYPES = ("CUSTOM_CFG",)
CATEGORY = "Animate Diff ππ
π
/sample settings/custom cfg"
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, cfg_extras: CFGExtrasGroup=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, cfg_extras=cfg_extras)
prev_custom_cfg.add(keyframe)
return (prev_custom_cfg,)
class CustomCFGKeyframeSimpleNode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0, "step": 0.1}),
"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",),
"cfg_extras": ("CFG_EXTRAS",),
},
"hidden": {
"autosize": ("ADEAUTOSIZE", {"padding": 10}),
}
}
RETURN_TYPES = ("CUSTOM_CFG",)
CATEGORY = "Animate Diff ππ
π
/sample settings/custom cfg"
FUNCTION = "create_custom_cfg"
def create_custom_cfg(self, cfg: float, start_percent: float=0.0, guarantee_steps: int=1,
prev_custom_cfg: CustomCFGKeyframeGroup=None, cfg_extras: CFGExtrasGroup=None):
return CustomCFGKeyframeNode.create_custom_cfg(self, cfg_multival=cfg, start_percent=start_percent,
guarantee_steps=guarantee_steps, prev_custom_cfg=prev_custom_cfg, cfg_extras=cfg_extras)
class CustomCFGKeyframeInterpolationNode:
@classmethod
def INPUT_TYPES(s):
return {
"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}),
"cfg_start": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0, "step": 0.1}),
"cfg_end": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0, "step": 0.1}),
"interpolation": (InterpolationMethod._LIST, ),
"intervals": ("INT", {"default": 50, "min": 2, "max": 100, "step": 1}),
"print_keyframes": ("BOOLEAN", {"default": False}),
},
"optional": {
"prev_custom_cfg": ("CUSTOM_CFG",),
"cfg_extras": ("CFG_EXTRAS",),
},
"hidden": {
"autosize": ("ADEAUTOSIZE", {"padding": 0}),
}
}
RETURN_TYPES = ("CUSTOM_CFG",)
CATEGORY = "Animate Diff ππ
π
/sample settings/custom cfg"
FUNCTION = "create_custom_cfg"
def create_custom_cfg(self,
start_percent: float, end_percent: float,
cfg_start: float, cfg_end: float, interpolation: str, intervals: int,
prev_custom_cfg: CustomCFGKeyframeGroup=None, cfg_extras: CFGExtrasGroup=None,
print_keyframes=False):
if not prev_custom_cfg:
prev_custom_cfg = CustomCFGKeyframeGroup()
prev_custom_cfg = prev_custom_cfg.clone()
percents = InterpolationMethod.get_weights(num_from=start_percent, num_to=end_percent, length=intervals, method=InterpolationMethod.LINEAR)
cfgs = InterpolationMethod.get_weights(num_from=cfg_start, num_to=cfg_end, length=intervals, method=interpolation)
is_first = True
for percent, cfg in zip(percents, cfgs):
guarantee_steps = 0
if is_first:
guarantee_steps = 1
is_first = False
prev_custom_cfg.add(CustomCFGKeyframe(cfg_multival=float(cfg), start_percent=percent, guarantee_steps=guarantee_steps, cfg_extras=cfg_extras))
if print_keyframes:
logger.info(f"CustomCFGKeyframe - start_percent:{percent} = {cfg}")
return (prev_custom_cfg,)
class CustomCFGKeyframeFromListNode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"cfgs_float": ("FLOAT", {"default": -1, "min": -1, "step": 0.001, "forceInput": True}),
"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}),
"print_keyframes": ("BOOLEAN", {"default": False}),
},
"optional": {
"prev_custom_cfg": ("CUSTOM_CFG",),
"cfg_extras": ("CFG_EXTRAS",),
}
}
RETURN_TYPES = ("CUSTOM_CFG",)
CATEGORY = "Animate Diff ππ
π
/sample settings/custom cfg"
FUNCTION = "create_custom_cfg"
def create_custom_cfg(self, cfgs_float: Union[float, list[float]],
start_percent: float, end_percent: float,
prev_custom_cfg: CustomCFGKeyframeGroup=None, cfg_extras: CFGExtrasGroup=None,
print_keyframes=False):
if not prev_custom_cfg:
prev_custom_cfg = CustomCFGKeyframeGroup()
prev_custom_cfg = prev_custom_cfg.clone()
if type(cfgs_float) in (float, int):
cfgs_float = [float(cfgs_float)]
elif isinstance(cfgs_float, Iterable):
pass
else:
raise Exception(f"strengths_float must be either an interable input or a float, but was {type(cfgs_float).__repr__}.")
percents = InterpolationMethod.get_weights(num_from=start_percent, num_to=end_percent, length=len(cfgs_float), method=InterpolationMethod.LINEAR)
is_first = True
for percent, cfg in zip(percents, cfgs_float):
guarantee_steps = 0
if is_first:
guarantee_steps = 1
is_first = False
prev_custom_cfg.add(CustomCFGKeyframe(cfg_multival=float(cfg), start_percent=percent, guarantee_steps=guarantee_steps, cfg_extras=cfg_extras))
if print_keyframes:
logger.info(f"CustomCFGKeyframe - start_percent:{percent} = {cfg}")
return (prev_custom_cfg,)
class CFGExtrasPAGNode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"scale_multival": ("MULTIVAL",),
},
"optional": {
"prev_extras": ("CFG_EXTRAS",),
},
"hidden": {
"autosize": ("ADEAUTOSIZE", {"padding": 0}),
}
}
RETURN_TYPES = ("CFG_EXTRAS",)
FUNCTION = "add_cfg_extras"
CATEGORY = "Animate Diff ππ
π
/sample settings/cfg extras"
def add_cfg_extras(self, scale_multival: Union[float, Tensor], prev_extras: CFGExtrasGroup=None):
if prev_extras is None:
prev_extras = CFGExtrasGroup()
prev_extras = prev_extras.clone()
patch = perturbed_attention_guidance_patch(scale_multival)
def call_extras(model_options: dict[str]):
return set_model_options_post_cfg_function(model_options.copy(), patch)
extra = CFGExtras(call_extras)
prev_extras.add(extra)
return (prev_extras,)
class CFGExtrasPAGSimpleNode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"scale": ("FLOAT", {"default": 3.0, "min": 0.0, "max": 100.0, "step": 0.1, "round": 0.01}),
},
"optional": {
"prev_extras": ("CFG_EXTRAS",),
},
"hidden": {
"autosize": ("ADEAUTOSIZE", {"padding": 0}),
}
}
RETURN_TYPES = ("CFG_EXTRAS",)
FUNCTION = "add_cfg_extras"
CATEGORY = "Animate Diff ππ
π
/sample settings/cfg extras"
def add_cfg_extras(self, scale: float, prev_extras: CFGExtrasGroup=None):
return CFGExtrasPAGNode.add_cfg_extras(self, scale_multival=scale, prev_extras=prev_extras)
class CFGExtrasRescaleCFGNode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"mult_multival": ("MULTIVAL",),
},
"optional": {
"prev_extras": ("CFG_EXTRAS",),
}
}
RETURN_TYPES = ("CFG_EXTRAS",)
FUNCTION = "add_cfg_extras"
CATEGORY = "Animate Diff ππ
π
/sample settings/cfg extras"
def add_cfg_extras(self, mult_multival: Union[float, Tensor], prev_extras: CFGExtrasGroup=None):
if prev_extras is None:
prev_extras = CFGExtrasGroup()
prev_extras = prev_extras.clone()
patch = rescale_cfg_patch(mult_multival)
def call_extras(model_options: dict[str]):
return set_model_options_sampler_cfg_function(model_options.copy(), patch)
extra = CFGExtras(call_extras)
prev_extras.add(extra)
return (prev_extras,)
class CFGExtrasRescaleCFGSimpleNode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"multiplier": ("FLOAT", {"default": 0.7, "min": 0.0, "max": 1.0, "step": 0.01}),
},
"optional": {
"prev_extras": ("CFG_EXTRAS",),
},
"hidden": {
"autosize": ("ADEAUTOSIZE", {"padding": 10}),
}
}
RETURN_TYPES = ("CFG_EXTRAS",)
FUNCTION = "add_cfg_extras"
CATEGORY = "Animate Diff ππ
π
/sample settings/cfg extras"
def add_cfg_extras(self, multiplier: float, prev_extras: CFGExtrasGroup=None):
return CFGExtrasRescaleCFGNode.add_cfg_extras(self, mult_multival=multiplier, prev_extras=prev_extras)
class NoisedImageInjectionNode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"image": ("IMAGE", ),
"vae": ("VAE", ),
},
"optional": {
"mask_opt": ("MASK", ),
"invert_mask": ("BOOLEAN", {"default": False}),
"resize_image": ("BOOLEAN", {"default": True}),
"start_percent": ("FLOAT", {"default": 0.0, "min": 0.0, "max": 1.0, "step": 0.001}),
"guarantee_steps": ("INT", {"default": 1, "min": 1, "max": BIGMAX}),
"img_inject_opts": ("IMAGE_INJECT_OPTIONS", ),
"strength_multival": ("MULTIVAL", ),
"prev_image_inject": ("IMAGE_INJECT", ),
},
"hidden": {
"autosize": ("ADEAUTOSIZE", {"padding": 0}),
}
}
RETURN_TYPES = ("IMAGE_INJECT",)
CATEGORY = "Animate Diff ππ
π
/sample settings/image inject"
FUNCTION = "create_image_inject"
def create_image_inject(self, image: Tensor, vae: VAE, invert_mask: bool, resize_image: bool, start_percent: float,
mask_opt: Tensor=None, strength_multival: Union[float, Tensor]=None, prev_image_inject: NoisedImageToInjectGroup=None, guarantee_steps=1,
img_inject_opts=None):
if not prev_image_inject:
prev_image_inject = NoisedImageToInjectGroup()
prev_image_inject = prev_image_inject.clone()
to_inject = NoisedImageToInject(image=image, mask=mask_opt, vae=vae, invert_mask=invert_mask, resize_image=resize_image, strength_multival=strength_multival,
start_percent=start_percent, guarantee_steps=guarantee_steps,
img_inject_opts=img_inject_opts)
prev_image_inject.add(to_inject)
return (prev_image_inject,)
class NoisedImageInjectOptionsNode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
},
"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}),
},
"hidden": {
"autosize": ("ADEAUTOSIZE", {"padding": 0}),
}
}
RETURN_TYPES = ("IMAGE_INJECT_OPTIONS",)
RETURN_NAMES = ("IMG_INJECT_OPTS",)
CATEGORY = "Animate Diff ππ
π
/sample settings/image inject"
FUNCTION = "create_image_inject_opts"
def create_image_inject_opts(self, x=0, y=0):
return (NoisedImageInjectOptions(x=x, y=y),)
|