From 6dc63a1bc2b456d9b88a8f9d840c7e2baf04a68d Mon Sep 17 00:00:00 2001 From: silveroxides Date: Sun, 8 Feb 2026 05:22:00 +0100 Subject: [PATCH] restore debug nodes --- __init__.py | 25 +++++++- nodes_debug.py | 152 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 nodes_debug.py diff --git a/__init__.py b/__init__.py index 17ed4a4..b5f32bc 100644 --- a/__init__.py +++ b/__init__.py @@ -5,6 +5,7 @@ import comfy.utils import logging import re from comfy.sd1_clip import token_weights, escape_important, unescape_important +from .nodes_debug import PromptEmbeddingFixer, InspectEmbeddingForClip def tokenize_preserving_weights(clip, text): """ @@ -33,6 +34,17 @@ def tokenize_preserving_weights(clip, text): found_any = False + # Try standard tokenization first to get a baseline for all parts + # This ensures we don't lose parts that we can't manually tokenize + try: + # Some tokenizers might not support llama_template, so we try with and without + try: + out = clip.tokenize(text, llama_template="{}") + except TypeError: + out = clip.tokenize(text) + except Exception: + out = {} + for attr in potential_parts: if hasattr(tokenizer, attr): sub_tok = getattr(tokenizer, attr) @@ -187,7 +199,14 @@ def tokenize_preserving_weights(clip, text): import traceback traceback.print_exc() - if not found_any: + # If manual tokenization was attempted and succeeded for at least one part, + # 'out' now contains a mix of standard tokenization (for skipped parts) + # and manual tokenization (for parts that needed weight preservation). + # If no manual tokenization happened, we rely entirely on the initial clip.tokenize result. + + if not found_any and not out: + # If both failed (e.g. clip.tokenize failed earlier and no manual parts found) + # Try one last time or return empty return clip.tokenize(text, llama_template="{}") return out @@ -875,6 +894,8 @@ NODE_CLASS_MAPPINGS = { "SaveWeightedEmbeddings": SaveWeightedEmbeddings, "SaveA1111WeightedEmbeddings": SaveA1111WeightedEmbeddings, "SliceExistingEmbedding": SliceExistingEmbedding, + "PromptEmbeddingFixer": PromptEmbeddingFixer, + "InspectEmbeddingForClip": InspectEmbeddingForClip, } NODE_DISPLAY_NAME_MAPPINGS = { @@ -882,6 +903,8 @@ NODE_DISPLAY_NAME_MAPPINGS = { "SaveWeightedEmbeddings": "Save Weighted Embeddings", "SaveA1111WeightedEmbeddings": "Save A1111-style Weighted Embeddings", "SliceExistingEmbedding": "Slice Existing Embedding File", + "PromptEmbeddingFixer": "Prompt Embedding Fixer", + "InspectEmbeddingForClip": "Inspect Embedding For Clip", } __all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS'] \ No newline at end of file diff --git a/nodes_debug.py b/nodes_debug.py new file mode 100644 index 0000000..1a97741 --- /dev/null +++ b/nodes_debug.py @@ -0,0 +1,152 @@ +import torch +import os +import folder_paths +import comfy.utils +import re + +class PromptEmbeddingFixer: + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "text": ("STRING", {"multiline": True, "dynamicPrompts": True}), + } + } + + RETURN_TYPES = ("STRING",) + FUNCTION = "fix_prompt" + CATEGORY = "EmbeddingToolkit/Utils" + + def fix_prompt(self, text): + # Add space before embedding if missing + text = re.sub(r'(?= 2: + output_text.append(f" [CHECK] Checking single tensor fallback...") + if val.shape[-1] == expected_size: + output_text.append(f" [OK] Fallback match! Shape: {val.shape}") + match_found = True + else: + output_text.append(f" [FAIL] Fallback mismatch. {val.shape[-1]} vs {expected_size}") + + if not match_found: + output_text.append(f" [INFO] No compatible embedding found for this component.") + + except Exception as e: + output_text.append(f" Error inspecting model component: {e}") + else: + output_text.append(" (No transformer found)") + + return {"ui": {"text": ["\n".join(output_text)]}} + +NODE_CLASS_MAPPINGS = { + "PromptEmbeddingFixer": PromptEmbeddingFixer, + "InspectEmbeddingForClip": InspectEmbeddingForClip, +} +NODE_DISPLAY_NAME_MAPPINGS = { + "PromptEmbeddingFixer": "Prompt Embedding Fixer", + "InspectEmbeddingForClip": "Inspect Embedding For Clip", +}