From 1470719db6b0740020baf455e168e90efa53ba30 Mon Sep 17 00:00:00 2001 From: Jedrzej Kosinski Date: Tue, 12 Nov 2024 10:55:19 -0600 Subject: [PATCH] Added clip scheduling support to all other native ComfyUI text encoding nodes (sdxl, flux, hunyuan, sd3) --- comfy_extras/nodes_clip_sdxl.py | 4 ++++ comfy_extras/nodes_flux.py | 2 ++ comfy_extras/nodes_hunyuan.py | 2 ++ comfy_extras/nodes_sd3.py | 2 ++ 4 files changed, 10 insertions(+) diff --git a/comfy_extras/nodes_clip_sdxl.py b/comfy_extras/nodes_clip_sdxl.py index 3087b917b..9dcfcacb8 100644 --- a/comfy_extras/nodes_clip_sdxl.py +++ b/comfy_extras/nodes_clip_sdxl.py @@ -17,6 +17,8 @@ class CLIPTextEncodeSDXLRefiner: def encode(self, clip, ascore, width, height, text): tokens = clip.tokenize(text) + if clip.use_clip_schedule: + return (clip.encode_from_tokens_scheduled(tokens, add_dict={"aesthetic_score": ascore, "width": width, "height": height}), ) cond, pooled = clip.encode_from_tokens(tokens, return_pooled=True) return ([[cond, {"pooled_output": pooled, "aesthetic_score": ascore, "width": width,"height": height}]], ) @@ -47,6 +49,8 @@ class CLIPTextEncodeSDXL: tokens["l"] += empty["l"] while len(tokens["l"]) > len(tokens["g"]): tokens["g"] += empty["g"] + if clip.use_clip_schedule: + return (clip.encode_from_tokens_scheduled(tokens, add_dict={"width": width, "height": height, "crop_w": crop_w, "crop_h": crop_h, "target_width": target_width, "target_height": target_height}), ) cond, pooled = clip.encode_from_tokens(tokens, return_pooled=True) return ([[cond, {"pooled_output": pooled, "width": width, "height": height, "crop_w": crop_w, "crop_h": crop_h, "target_width": target_width, "target_height": target_height}]], ) diff --git a/comfy_extras/nodes_flux.py b/comfy_extras/nodes_flux.py index b690432b5..1c5c3b0cf 100644 --- a/comfy_extras/nodes_flux.py +++ b/comfy_extras/nodes_flux.py @@ -18,6 +18,8 @@ class CLIPTextEncodeFlux: tokens = clip.tokenize(clip_l) tokens["t5xxl"] = clip.tokenize(t5xxl)["t5xxl"] + if clip.use_clip_schedule: + return (clip.encode_from_tokens_scheduled(tokens, add_dict={"guidance": guidance}), ) output = clip.encode_from_tokens(tokens, return_pooled=True, return_dict=True) cond = output.pop("cond") output["guidance"] = guidance diff --git a/comfy_extras/nodes_hunyuan.py b/comfy_extras/nodes_hunyuan.py index b03eaf6a2..38988aaa6 100644 --- a/comfy_extras/nodes_hunyuan.py +++ b/comfy_extras/nodes_hunyuan.py @@ -15,6 +15,8 @@ class CLIPTextEncodeHunyuanDiT: tokens = clip.tokenize(bert) tokens["mt5xl"] = clip.tokenize(mt5xl)["mt5xl"] + if clip.use_clip_schedule: + return (clip.encode_from_tokens_scheduled(tokens), ) output = clip.encode_from_tokens(tokens, return_pooled=True, return_dict=True) cond = output.pop("cond") return ([[cond, output]], ) diff --git a/comfy_extras/nodes_sd3.py b/comfy_extras/nodes_sd3.py index bbdedef79..2567a413c 100644 --- a/comfy_extras/nodes_sd3.py +++ b/comfy_extras/nodes_sd3.py @@ -78,6 +78,8 @@ class CLIPTextEncodeSD3: tokens["l"] += empty["l"] while len(tokens["l"]) > len(tokens["g"]): tokens["g"] += empty["g"] + if clip.use_clip_schedule: + return (clip.encode_from_tokens_scheduled(tokens), ) cond, pooled = clip.encode_from_tokens(tokens, return_pooled=True) return ([[cond, {"pooled_output": pooled}]], )