Compare commits
2
Commits
main
...
testing_wip
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e0c320949 | ||
|
|
64314b1726 |
+42
-3
@@ -2,41 +2,80 @@ from .nodes import *
|
||||
|
||||
NODE_CLASS_MAPPINGS = {}
|
||||
|
||||
# try:
|
||||
# from .skimmed_CFG import cond_skimming_pre_cfg_node
|
||||
# NODE_CLASS_MAPPINGS["Skimmed CFG"] = cond_skimming_pre_cfg_node
|
||||
# except:
|
||||
# pass
|
||||
|
||||
NODE_CLASS_MAPPINGS_ADD = {
|
||||
"Pre CFG automatic scale": automatic_pre_cfg,
|
||||
"Pre CFG uncond zero": uncondZeroPreCFGNode,
|
||||
"Pre CFG perp-neg": pre_cfg_perp_neg,
|
||||
# "Pre CFG re-negative": pre_cfg_re_negative,
|
||||
"Pre CFG re-negative": pre_cfg_re_negative,
|
||||
|
||||
"Pre CFG PAG": perturbed_attention_guidance_pre_cfg_node,
|
||||
"Pre CFG zero attention": zero_attention_pre_cfg_node,
|
||||
# "Pre CFG color control": latent_color_control_pre_cfg_node,
|
||||
"Pre CFG channel multiplier": channel_multiplier_node,
|
||||
"Pre CFG multiplier": multiply_cond_pre_cfg_node,
|
||||
"Pre CFG roll latent": PreCFGRollLatentNode,
|
||||
"Pre CFG mirror flip": PreCFGMirrorFlipLatentNode,
|
||||
|
||||
"Pre CFG clamp negative": clamp_sign_uncond_pre_cfg_node,
|
||||
"Pre CFG clamp negative to denoised relation": clamp_uncond_to_denoised_pre_cfg_node,
|
||||
|
||||
"Pre CFG clamp min max": minmax_clamp_pre_cfg_node,
|
||||
"Pre CFG lerp": lerp_conds_pre_cfg_node,
|
||||
|
||||
"Pre CFG norm neg to pos": norm_uncond_to_cond_pre_cfg_node,
|
||||
"Pre CFG subtract mean": PreCFGsubtractMeanNode,
|
||||
"Pre CFG variable scaling": variable_scale_pre_cfg_node,
|
||||
"Pre CFG gradient scaling": gradient_scaling_pre_cfg_node,
|
||||
|
||||
|
||||
"Pre CFG flip flop": flip_flip_conds_pre_cfg_node,
|
||||
"Pre CFG replace negative channel": replace_uncond_channel_pre_cfg_node,
|
||||
"Pre CFG merge negative channel": merge_uncond_channel_pre_cfg_node,
|
||||
"Pre CFG merge negative channel": merge_uncond_channel_pre_cfg_node,
|
||||
"Pre CFG timed CFG rescale": rescale_cfg_during_sigma_pre_cfg_node,
|
||||
|
||||
"Pre CFG sharpening": condDiffSharpeningNode,
|
||||
"Pre CFG sharpen/blur": condBlurSharpeningNode,
|
||||
|
||||
"Pre CFG exponentiation": condExpNode,
|
||||
"Pre CFG cond boost": boost_std_pre_cfg_node,
|
||||
"tHe dArK GuiDaNcE": dark_guidance_pre_cfg_node,
|
||||
|
||||
"Conditioning set timestep from sigma": ConditioningSetTimestepRangeFromSigma,
|
||||
"Support empty uncond": support_empty_uncond_pre_cfg_node,
|
||||
"Shape attention": ShapeAttentionNode,
|
||||
"Excellent attention": ExlAttentionNode,
|
||||
"Post CFG subtract mean": PostCFGsubtractMeanNode,
|
||||
# "Post CFG make a dot": PostCFGDotNode,
|
||||
"Individual channel selector": individual_channel_selection_node,
|
||||
"Subtract noise mean": latent_noise_subtract_mean_node,
|
||||
"Empty RGB image": EmptyRGBImage,
|
||||
"Gradient RGB image": GradientRGBImage,
|
||||
"colors test node": colors_test_node,
|
||||
"gradient batch mask": gradientNoisyLatentMaskBatch,
|
||||
"Load latent from path": load_latent_for_guidance,
|
||||
"Latent recombine by channels": latent_recombine_channels,
|
||||
}
|
||||
|
||||
NODE_CLASS_MAPPINGS.update(NODE_CLASS_MAPPINGS_ADD)
|
||||
|
||||
for c in [4,8,16,32,64,128]:
|
||||
NODE_CLASS_MAPPINGS[f"Channel selector for {c} channels"] = type("channel_selection_node", (channel_selection_node,), { "CHANNELS_AMOUNT": c})
|
||||
|
||||
try:
|
||||
from .tester_nodes import *
|
||||
NODE_CLASS_MAPPINGS["K-K-K-K-KOMBO BREAKER"] = combo_breaker
|
||||
NODE_CLASS_MAPPINGS["K-K-K-K-KOMBO BREAKER X2"] = combo_breaker_x2
|
||||
|
||||
NODE_CLASS_MAPPINGS["K-K-K-K-KOMBO BREAKER 6 bool"] = combo_breaker_6_bool
|
||||
NODE_CLASS_MAPPINGS["K-K-K-K-KOMBO BREAKER 4 bool"] = combo_breaker_4_bool
|
||||
|
||||
NODE_CLASS_MAPPINGS["CFG_TEST"] = cfg_test_node
|
||||
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
import torch
|
||||
|
||||
@torch.no_grad()
|
||||
def get_skimming_mask(x_orig, cond, uncond, cond_scale, return_denoised=False, disable_flipping_filter=False, release_inner_scaling=False):
|
||||
denoised = x_orig - ((x_orig - uncond) + cond_scale * ((x_orig - cond) - (x_orig - uncond)))
|
||||
matching_pred_signs = (cond - uncond).sign() == cond.sign()
|
||||
matching_diff_after = cond.sign() == (cond * cond_scale - uncond * (cond_scale - 1)).sign()
|
||||
if disable_flipping_filter:
|
||||
outer_influence = matching_pred_signs & matching_diff_after
|
||||
else:
|
||||
deviation_influence = (denoised.sign() == (denoised - x_orig).sign())
|
||||
outer_influence = matching_pred_signs & matching_diff_after & deviation_influence
|
||||
if return_denoised:
|
||||
return outer_influence, denoised
|
||||
else:
|
||||
return outer_influence
|
||||
|
||||
@torch.no_grad()
|
||||
def skimmed_CFG(x_orig, cond, uncond, cond_scale, skimming_scale, disable_flipping_filter=False):
|
||||
outer_influence, denoised = get_skimming_mask(x_orig, cond, uncond, cond_scale, return_denoised=True, disable_flipping_filter=disable_flipping_filter)
|
||||
low_cfg_denoised_outer = x_orig - ((x_orig - uncond) + skimming_scale * ((x_orig - cond) - (x_orig - uncond)))
|
||||
low_cfg_denoised_outer_difference = denoised - low_cfg_denoised_outer
|
||||
cond[outer_influence] = cond[outer_influence] - (low_cfg_denoised_outer_difference[outer_influence] / cond_scale)
|
||||
return cond
|
||||
|
||||
def skimmed_CFG_patch_wrap(model,Skimming_CFG=-1,end_proportion=1,full_skim_negative=True,disable_flipping_filter=False):
|
||||
@torch.no_grad()
|
||||
def skimmed_CFG_patch(args):
|
||||
conds_out = args["conds_out"]
|
||||
cond_scale = args["cond_scale"]
|
||||
x_orig = args['input']
|
||||
if not torch.any(conds_out[1]):
|
||||
return conds_out
|
||||
if end_proportion != 1:
|
||||
c0,c1=conds_out[0].clone(),conds_out[1].clone()
|
||||
practical_scale = cond_scale if Skimming_CFG < 0 else Skimming_CFG
|
||||
conds_out[1] = skimmed_CFG(x_orig, conds_out[1], conds_out[0], cond_scale, practical_scale if not full_skim_negative else 0, disable_flipping_filter)
|
||||
conds_out[0] = skimmed_CFG(x_orig, conds_out[0], conds_out[1], cond_scale, practical_scale, disable_flipping_filter)
|
||||
if end_proportion != 1:
|
||||
conds_out[0] = conds_out[0] * end_proportion + c0 * (1 - end_proportion)
|
||||
conds_out[1] = conds_out[1] * end_proportion + c1 * (1 - end_proportion)
|
||||
return conds_out
|
||||
m = model.clone()
|
||||
m.set_model_sampler_pre_cfg_function(skimmed_CFG_patch)
|
||||
return m,
|
||||
|
||||
# def skimmed_CFG_patch_wrap(model,Skimming_CFG=-1,end_proportion=1,full_skim_negative=False,disable_flipping_filter=False):
|
||||
# @torch.no_grad()
|
||||
# def skimmed_CFG_patch(args):
|
||||
# conds_out = args["conds_out"]
|
||||
# cond_scale = args["cond_scale"]
|
||||
# x_orig = args['input']
|
||||
# if not torch.any(conds_out[1]):
|
||||
# return conds_out
|
||||
# if end_proportion != 1:
|
||||
# c0,c1=conds_out[0].clone(),conds_out[1].clone()
|
||||
# practical_scale = cond_scale if Skimming_CFG < 0 else Skimming_CFG
|
||||
# conds_out[1] = skimmed_CFG(x_orig, conds_out[1], conds_out[0], cond_scale, practical_scale if not full_skim_negative else 0, disable_flipping_filter)
|
||||
# conds_out[0] = skimmed_CFG(x_orig, conds_out[0], conds_out[1], cond_scale, practical_scale, disable_flipping_filter)
|
||||
# if end_proportion != 1:
|
||||
# conds_out[0] = conds_out[0] * end_proportion + c0 * (1 - end_proportion)
|
||||
# conds_out[1] = conds_out[1] * end_proportion + c1 * (1 - end_proportion)
|
||||
# return conds_out
|
||||
# m = model.clone()
|
||||
# m.set_model_sampler_pre_cfg_function(skimmed_CFG_patch)
|
||||
# return m,
|
||||
Binary file not shown.
Reference in New Issue
Block a user