Skip to content

Commit 9a616b8

Browse files
Add rescaling_scale from STG to SkipLayerGuidanceDiT.
1 parent 3bed56b commit 9a616b8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

comfy_extras/nodes_slg.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def INPUT_TYPES(s):
1616
"single_layers": ("STRING", {"default": "7, 8, 9", "multiline": False}),
1717
"scale": ("FLOAT", {"default": 3.0, "min": 0.0, "max": 10.0, "step": 0.1}),
1818
"start_percent": ("FLOAT", {"default": 0.01, "min": 0.0, "max": 1.0, "step": 0.001}),
19-
"end_percent": ("FLOAT", {"default": 0.15, "min": 0.0, "max": 1.0, "step": 0.001})
19+
"end_percent": ("FLOAT", {"default": 0.15, "min": 0.0, "max": 1.0, "step": 0.001}),
20+
"rescaling_scale": ("FLOAT", {"default": 0.0, "min": 0.0, "max": 10.0, "step": 0.01}),
2021
}}
2122
RETURN_TYPES = ("MODEL",)
2223
FUNCTION = "skip_guidance"
@@ -26,7 +27,7 @@ def INPUT_TYPES(s):
2627

2728
CATEGORY = "advanced/guidance"
2829

29-
def skip_guidance(self, model, scale, start_percent, end_percent, double_layers="", single_layers=""):
30+
def skip_guidance(self, model, scale, start_percent, end_percent, double_layers="", single_layers="", rescaling_scale=0):
3031
# check if layer is comma separated integers
3132
def skip(args, extra_args):
3233
return args
@@ -65,6 +66,11 @@ def post_cfg_function(args):
6566
if scale > 0 and sigma_ >= sigma_end and sigma_ <= sigma_start:
6667
(slg,) = comfy.samplers.calc_cond_batch(model, [cond], x, sigma, model_options)
6768
cfg_result = cfg_result + (cond_pred - slg) * scale
69+
if rescaling_scale != 0:
70+
factor = cond_pred.std() / cfg_result.std()
71+
factor = rescaling_scale * factor + (1 - rescaling_scale)
72+
cfg_result *= factor
73+
6874
return cfg_result
6975

7076
m = model.clone()

0 commit comments

Comments
 (0)