Add validation to prevent empty prompts causing tokenization errors

Co-authored-by: jags111 <5968619+jags111@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-03 23:01:19 +00:00
parent f9692f29ff
commit b083ff3f6c
4 changed files with 14 additions and 0 deletions

Binary file not shown.

View File

@@ -72,6 +72,12 @@ def encode_prompts(positive_prompt, negative_prompt, token_normalization, weight
refiner_clip, refiner_clip_skip, ascore, is_sdxl, empty_latent_width, empty_latent_height,
return_type="both"):
# Ensure prompts are valid strings to prevent tokenization errors
if positive_prompt is None or (isinstance(positive_prompt, str) and not positive_prompt.strip()):
positive_prompt = " "
if negative_prompt is None or (isinstance(negative_prompt, str) and not negative_prompt.strip()):
negative_prompt = " "
positive_encoded = negative_encoded = refiner_positive_encoded = refiner_negative_encoded = None
# Process base encodings if needed

Binary file not shown.

View File

@@ -237,6 +237,9 @@ def prepareXL(embs_l, embs_g, pooled, clip_balance):
return embs_g, pooled
def advanced_encode(clip, text, token_normalization, weight_interpretation, w_max=1.0, clip_balance=.5, apply_to_pooled=True):
# Ensure text is a valid string to prevent tokenization errors
if text is None or (isinstance(text, str) and not text.strip()):
text = " "
tokenized = clip.tokenize(text, return_word_ids=True)
if isinstance(clip.cond_stage_model, (SDXLClipModel, SDXLRefinerClipModel, SDXLClipG)):
embs_l = None
@@ -265,6 +268,11 @@ def advanced_encode(clip, text, token_normalization, weight_interpretation, w_ma
lambda x: (clip.encode_from_tokens({'l': x}), None),
w_max=w_max)
def advanced_encode_XL(clip, text1, text2, token_normalization, weight_interpretation, w_max=1.0, clip_balance=.5, apply_to_pooled=True):
# Ensure texts are valid strings to prevent tokenization errors
if text1 is None or (isinstance(text1, str) and not text1.strip()):
text1 = " "
if text2 is None or (isinstance(text2, str) and not text2.strip()):
text2 = " "
tokenized1 = clip.tokenize(text1, return_word_ids=True)
tokenized2 = clip.tokenize(text2, return_word_ids=True)