From 6445abe8a0431691fb3c104b67cb0eb7d58285a7 Mon Sep 17 00:00:00 2001 From: Talmaj Marinc Date: Mon, 23 Feb 2026 22:10:15 +0100 Subject: [PATCH] Add a guard if no <|im_start|> token is found. --- comfy/text_encoders/longcat_image.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/comfy/text_encoders/longcat_image.py b/comfy/text_encoders/longcat_image.py index 3f91f7ce0..4560d1a2e 100644 --- a/comfy/text_encoders/longcat_image.py +++ b/comfy/text_encoders/longcat_image.py @@ -112,10 +112,13 @@ class LongCatImageTEModel(sd1_clip.SD1ClipModel): template_end = i count_im_start += 1 - if out.shape[1] > (template_end + 3): - if tok_pairs[template_end + 1][0] == 872: - if tok_pairs[template_end + 2][0] == 198: - template_end += 3 + if out.shape[1] > (template_end + 3): + if tok_pairs[template_end + 1][0] == 872: + if tok_pairs[template_end + 2][0] == 198: + template_end += 3 + + if template_end == -1: + template_end = 0 suffix_start = None for i in range(len(tok_pairs) - 1, -1, -1):