Skip to content

Commit

Permalink
CLIPTextEncodeSDXL now works when prompts are of very different sizes.
Browse files Browse the repository at this point in the history
  • Loading branch information
comfyanonymous committed Jul 7, 2023
1 parent e7bee85 commit 2c9d98f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions comfy_extras/nodes_clip_sdxl.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ def INPUT_TYPES(s):
def encode(self, clip, width, height, crop_w, crop_h, target_width, target_height, text_g, text_l):
tokens = clip.tokenize(text_g)
tokens["l"] = clip.tokenize(text_l)["l"]
if len(tokens["l"]) != len(tokens["g"]):
empty = clip.tokenize("")
while len(tokens["l"]) < len(tokens["g"]):
tokens["l"] += empty["l"]
while len(tokens["l"]) > len(tokens["g"]):
tokens["g"] += empty["g"]
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}]], )

Expand Down

0 comments on commit 2c9d98f

Please sign in to comment.