mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-03-13 09:10:12 +00:00
Compare commits
4 Commits
fix/static
...
rename-mah
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa6c7eb86f | ||
|
|
8c41e2393b | ||
|
|
93175036fb | ||
|
|
4528ff9870 |
@@ -10,7 +10,7 @@ class Mahiro(io.ComfyNode):
|
|||||||
def define_schema(cls):
|
def define_schema(cls):
|
||||||
return io.Schema(
|
return io.Schema(
|
||||||
node_id="Mahiro",
|
node_id="Mahiro",
|
||||||
display_name="Mahiro CFG",
|
display_name="Positive-Biased Guidance",
|
||||||
category="_for_testing",
|
category="_for_testing",
|
||||||
description="Modify the guidance to scale more on the 'direction' of the positive prompt rather than the difference between the negative prompt.",
|
description="Modify the guidance to scale more on the 'direction' of the positive prompt rather than the difference between the negative prompt.",
|
||||||
inputs=[
|
inputs=[
|
||||||
@@ -20,27 +20,35 @@ class Mahiro(io.ComfyNode):
|
|||||||
io.Model.Output(display_name="patched_model"),
|
io.Model.Output(display_name="patched_model"),
|
||||||
],
|
],
|
||||||
is_experimental=True,
|
is_experimental=True,
|
||||||
|
search_aliases=[
|
||||||
|
"mahiro",
|
||||||
|
"mahiro cfg",
|
||||||
|
"similarity-adaptive guidance",
|
||||||
|
"positive-biased cfg",
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def execute(cls, model) -> io.NodeOutput:
|
def execute(cls, model) -> io.NodeOutput:
|
||||||
m = model.clone()
|
m = model.clone()
|
||||||
|
|
||||||
def mahiro_normd(args):
|
def mahiro_normd(args):
|
||||||
scale: float = args['cond_scale']
|
scale: float = args["cond_scale"]
|
||||||
cond_p: torch.Tensor = args['cond_denoised']
|
cond_p: torch.Tensor = args["cond_denoised"]
|
||||||
uncond_p: torch.Tensor = args['uncond_denoised']
|
uncond_p: torch.Tensor = args["uncond_denoised"]
|
||||||
#naive leap
|
# naive leap
|
||||||
leap = cond_p * scale
|
leap = cond_p * scale
|
||||||
#sim with uncond leap
|
# sim with uncond leap
|
||||||
u_leap = uncond_p * scale
|
u_leap = uncond_p * scale
|
||||||
cfg = args["denoised"]
|
cfg = args["denoised"]
|
||||||
merge = (leap + cfg) / 2
|
merge = (leap + cfg) / 2
|
||||||
normu = torch.sqrt(u_leap.abs()) * u_leap.sign()
|
normu = torch.sqrt(u_leap.abs()) * u_leap.sign()
|
||||||
normm = torch.sqrt(merge.abs()) * merge.sign()
|
normm = torch.sqrt(merge.abs()) * merge.sign()
|
||||||
sim = F.cosine_similarity(normu, normm).mean()
|
sim = F.cosine_similarity(normu, normm).mean()
|
||||||
simsc = 2 * (sim+1)
|
simsc = 2 * (sim + 1)
|
||||||
wm = (simsc*cfg + (4-simsc)*leap) / 4
|
wm = (simsc * cfg + (4 - simsc) * leap) / 4
|
||||||
return wm
|
return wm
|
||||||
|
|
||||||
m.set_model_sampler_post_cfg_function(mahiro_normd)
|
m.set_model_sampler_post_cfg_function(mahiro_normd)
|
||||||
return io.NodeOutput(m)
|
return io.NodeOutput(m)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user