From c2fbe299e0fda0ac7e897d86bd9dcaf6870051e8 Mon Sep 17 00:00:00 2001 From: Haoming Date: Mon, 8 Dec 2025 17:42:22 +0800 Subject: [PATCH] llm --- backend/text_processing/gemma_engine.py | 2 +- backend/text_processing/qwen3_engine.py | 2 +- backend/text_processing/qwen_engine.py | 2 +- backend/text_processing/umt5_engine.py | 14 +++++++------- modules/prompt_parser.py | 7 +------ modules/sd_models.py | 2 ++ 6 files changed, 13 insertions(+), 16 deletions(-) diff --git a/backend/text_processing/gemma_engine.py b/backend/text_processing/gemma_engine.py index b0c7416f..bf180ada 100644 --- a/backend/text_processing/gemma_engine.py +++ b/backend/text_processing/gemma_engine.py @@ -119,7 +119,7 @@ class GemmaTextProcessingEngine: zs.extend(line_z_values) - return torch.stack(zs) + return zs def process_embeds(self, batch_tokens): device = memory_management.text_encoder_device() diff --git a/backend/text_processing/qwen3_engine.py b/backend/text_processing/qwen3_engine.py index adb9ce18..9b1b005e 100644 --- a/backend/text_processing/qwen3_engine.py +++ b/backend/text_processing/qwen3_engine.py @@ -86,7 +86,7 @@ class Qwen3TextProcessingEngine: zs.extend(line_z_values) - return torch.stack(zs) + return zs def process_embeds(self, batch_tokens): device = memory_management.text_encoder_device() diff --git a/backend/text_processing/qwen_engine.py b/backend/text_processing/qwen_engine.py index 558d7e72..91a529d2 100644 --- a/backend/text_processing/qwen_engine.py +++ b/backend/text_processing/qwen_engine.py @@ -99,7 +99,7 @@ class QwenTextProcessingEngine: zs.extend(line_z_values) - return torch.stack(zs) + return zs def strip_template(self, out, tokens): template_end = 0 diff --git a/backend/text_processing/umt5_engine.py b/backend/text_processing/umt5_engine.py index 34247ced..b3e19862 100644 --- a/backend/text_processing/umt5_engine.py +++ b/backend/text_processing/umt5_engine.py @@ -113,18 +113,18 @@ class UMT5TextProcessingEngine: line_z_values = [] # pad all chunks to length of longest chunk - # max_tokens = 0 - # for chunk in chunks: - # max_tokens = max(len(chunk.tokens), max_tokens) + max_tokens = 0 + for chunk in chunks: + max_tokens = max(len(chunk.tokens), max_tokens) for chunk in chunks: tokens = chunk.tokens multipliers = chunk.multipliers - # remaining_count = max_tokens - len(tokens) - # if remaining_count > 0: - # tokens += [self.pad_token] * remaining_count - # multipliers += [1.0] * remaining_count + remaining_count = max_tokens - len(tokens) + if remaining_count > 0: + tokens += [self.id_pad] * remaining_count + multipliers += [1.0] * remaining_count z = self.process_tokens([tokens], [multipliers])[0] line_z_values.append(z) diff --git a/modules/prompt_parser.py b/modules/prompt_parser.py index b9aab8d9..466e8ba6 100644 --- a/modules/prompt_parser.py +++ b/modules/prompt_parser.py @@ -199,12 +199,7 @@ def get_learned_conditioning(model, prompts: SdConditioning | list[str], steps, continue texts = SdConditioning([x[1] for x in prompt_schedule], copy_from=prompts) - try: - conds = model.get_learned_conditioning(texts) - except RuntimeError as e: - if "stack expects each tensor to be equal size" in repr(e): - raise NotImplementedError("Prompt Editing/Alternating is not supported in LLM Text Encoders") - raise e + conds = model.get_learned_conditioning(texts) cond_schedule = [] for i, (end_at_step, _) in enumerate(prompt_schedule): diff --git a/modules/sd_models.py b/modules/sd_models.py index da5a1f63..3665bf47 100644 --- a/modules/sd_models.py +++ b/modules/sd_models.py @@ -383,6 +383,8 @@ def forge_model_reload(): _cond = sd_model.get_learned_conditioning(SdConditioning([opts.empty_prompt_template])) if isinstance(_cond, dict): _cond = DictWithShape(_cond) + elif isinstance(_cond, list): + _cond = torch.stack(_cond) sd_model.empty_cond = _cond.to(devices.cpu) timer.record("calculate empty prompt")