Skip to content

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

Force min length 1 when tokenizing for text generation. (#12538)

comfyanonymous5f2117528a6b
diff --git a/comfy/sd1_clip.py b/comfy/sd1_clip.py
index 17e2b4816..d89550840 100644
--- a/comfy/sd1_clip.py
+++ b/comfy/sd1_clip.py
@@ -573,6 +573,8 @@ class SDTokenizer:
min_length = tokenizer_options.get("{}_min_length".format(self.embedding_key), self.min_length)
min_padding = tokenizer_options.get("{}_min_padding".format(self.embedding_key), self.min_padding)
+ min_length = kwargs.get("min_length", min_length)
+
text = escape_important(text)
if kwargs.get("disable_weights", self.disable_weights):
parsed_weights = [(text, 1.0)]
diff --git a/comfy_extras/nodes_textgen.py b/comfy_extras/nodes_textgen.py
index dd4f6b0d3..14cff14a6 100644
--- a/comfy_extras/nodes_textgen.py
+++ b/comfy_extras/nodes_textgen.py
@@ -42,7 +42,7 @@ class TextGenerate(io.ComfyNode):
@classmethod
def execute(cls, clip, prompt, max_length, sampling_mode, image=None) -> io.NodeOutput:
- tokens = clip.tokenize(prompt, image=image, skip_template=False)
+ tokens = clip.tokenize(prompt, image=image, skip_template=False, min_length=1)
# Get sampling parameters from dynamic combo
do_sample = sampling_mode.get("sampling_mode") == "on"