mirror of
https://github.com/jags111/efficiency-nodes-comfyui.git
synced 2026-05-07 01:06:42 -03:00
Compare commits
4 Commits
copilot/fi
...
copilot/fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40105e68f0 | ||
|
|
c819d6135a | ||
|
|
b0e2632310 | ||
|
|
d79e4bc801 |
19
.gitignore
vendored
19
.gitignore
vendored
@@ -1,9 +1,26 @@
|
||||
# Python
|
||||
# Python cache
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
|
||||
# Virtual environments
|
||||
venv/
|
||||
|
||||
@@ -53,7 +53,6 @@ from .py import city96_latent_upscaler
|
||||
from .py import ttl_nn_latent_upscaler
|
||||
from .py import bnk_tiled_samplers
|
||||
from .py import bnk_adv_encode
|
||||
from .py.bnk_adv_encode import normalize_prompt_text
|
||||
sys.path.remove(my_dir)
|
||||
|
||||
from comfy import samplers
|
||||
@@ -72,9 +71,6 @@ SCHEDULERS = samplers.KSampler.SCHEDULERS + ["AYS SD1", "AYS SDXL", "AYS SVD", "
|
||||
def encode_prompts(positive_prompt, negative_prompt, token_normalization, weight_interpretation, clip, clip_skip,
|
||||
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
|
||||
positive_prompt = normalize_prompt_text(positive_prompt)
|
||||
negative_prompt = normalize_prompt_text(negative_prompt)
|
||||
|
||||
positive_encoded = negative_encoded = refiner_positive_encoded = refiner_negative_encoded = None
|
||||
|
||||
@@ -103,6 +99,16 @@ def encode_prompts(positive_prompt, negative_prompt, token_normalization, weight
|
||||
elif return_type == "both":
|
||||
return positive_encoded, negative_encoded, clip, refiner_positive_encoded, refiner_negative_encoded, refiner_clip
|
||||
|
||||
########################################################################################################################
|
||||
# Helper function for VAE error message
|
||||
def get_missing_vae_error(ckpt_name):
|
||||
"""Generate error message for checkpoints without embedded VAE"""
|
||||
return (
|
||||
f"Checkpoint '{ckpt_name}' does not contain an embedded VAE. "
|
||||
f"This checkpoint (likely an AIO model) requires an external VAE. "
|
||||
f"Please select a VAE file instead of 'Baked VAE'."
|
||||
)
|
||||
|
||||
########################################################################################################################
|
||||
# TSC Efficient Loader
|
||||
class TSC_EfficientLoader:
|
||||
@@ -170,6 +176,9 @@ class TSC_EfficientLoader:
|
||||
f"{warning('Efficiency Nodes:')} Baked VAE not found in cache, loading checkpoint to extract VAE...")
|
||||
_, _, vae = load_checkpoint(ckpt_name, my_unique_id, output_vae=True, cache=ckpt_cache,
|
||||
cache_overwrite=True)
|
||||
# Check if VAE extraction was successful
|
||||
if vae is None:
|
||||
raise ValueError(get_missing_vae_error(ckpt_name))
|
||||
else:
|
||||
model, clip, vae = load_checkpoint(ckpt_name, my_unique_id, cache=ckpt_cache, cache_overwrite=True)
|
||||
lora_params = None
|
||||
@@ -199,6 +208,9 @@ class TSC_EfficientLoader:
|
||||
# Check for custom VAE
|
||||
if vae_name != "Baked VAE":
|
||||
vae = load_vae(vae_name, my_unique_id, cache=vae_cache, cache_overwrite=True)
|
||||
elif vae is None:
|
||||
# If "Baked VAE" was selected but checkpoint has no embedded VAE
|
||||
raise ValueError(get_missing_vae_error(ckpt_name))
|
||||
|
||||
# Data for XY Plot
|
||||
dependencies = (vae_name, ckpt_name, clip, clip_skip, refiner_name, refiner_clip, refiner_clip_skip,
|
||||
|
||||
@@ -6,34 +6,6 @@ from math import gcd
|
||||
from comfy import model_management
|
||||
from comfy.sdxl_clip import SDXLClipModel, SDXLRefinerClipModel, SDXLClipG
|
||||
|
||||
def normalize_prompt_text(text):
|
||||
"""
|
||||
Normalize prompt text to prevent tokenization errors.
|
||||
|
||||
Converts None, empty strings, or whitespace-only strings to a single space.
|
||||
Ensures the input is a string type by converting non-string values.
|
||||
This function is designed to handle edge cases gracefully without crashing,
|
||||
which is important for ComfyUI workflows where users might have empty prompts.
|
||||
|
||||
Parameters:
|
||||
text: The input prompt text to normalize. Can be of any type, though
|
||||
string, None, or convertible types are expected.
|
||||
|
||||
Returns:
|
||||
str: A normalized string that is safe to pass to the tokenizer.
|
||||
Returns " " (single space) for None, empty, or whitespace-only inputs.
|
||||
Returns the original text unchanged if it's a valid non-empty string.
|
||||
Returns str(text) for non-string types.
|
||||
"""
|
||||
if text is None:
|
||||
return " "
|
||||
if not isinstance(text, str):
|
||||
# Convert non-string types to string
|
||||
text = str(text)
|
||||
if not text.strip():
|
||||
return " "
|
||||
return text
|
||||
|
||||
def _grouper(n, iterable):
|
||||
it = iter(iterable)
|
||||
while True:
|
||||
@@ -265,8 +237,6 @@ 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
|
||||
text = normalize_prompt_text(text)
|
||||
tokenized = clip.tokenize(text, return_word_ids=True)
|
||||
if isinstance(clip.cond_stage_model, (SDXLClipModel, SDXLRefinerClipModel, SDXLClipG)):
|
||||
embs_l = None
|
||||
@@ -295,9 +265,6 @@ 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
|
||||
text1 = normalize_prompt_text(text1)
|
||||
text2 = normalize_prompt_text(text2)
|
||||
tokenized1 = clip.tokenize(text1, return_word_ids=True)
|
||||
tokenized2 = clip.tokenize(text2, return_word_ids=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user