From 2b8a81390d3d296ec908da170d820e5bb4ddcc7d Mon Sep 17 00:00:00 2001 From: digital-garbage <133010426+digital-garbage@users.noreply.github.com> Date: Thu, 15 Oct 2026 15:59:16 +0300 Subject: [PATCH] fix: an enhancer rewrite with no real words (a non-chat encoder answered with 400 commas) is a failed rewrite, so the typed prompt is kept and the reason is said; found on a real GPU Co-Authored-By: Claude Sonnet 5.5 --- modules/conditioning/prompt_enhancer/enhance.py | 6 ++++++ .../prompt_enhancer/tests/test_prompt_enhancer.py | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/modules/conditioning/prompt_enhancer/enhance.py b/modules/conditioning/prompt_enhancer/enhance.py index 82a76b55..c4e4ec6b 100644 --- a/modules/conditioning/prompt_enhancer/enhance.py +++ b/modules/conditioning/prompt_enhancer/enhance.py @@ -373,5 +373,11 @@ def enhance(clip, text, *, system="", reference_text="", chat="", **sampling): if not out: return original, (status if "failed" in status or "unavailable" in status else "the model returned nothing; prompt unchanged"), info + visible = "".join(out.split()) + if not re.search(r"[^\W\d_]{2,}", out) or sum(c.isalpha() for c in visible) < len(visible) // 4: + # Seen on a real GPU: an encoder that is not a chat model answered with 400 commas, and that WAS sent + # on to the video model, which then made something unrelated to the prompt. + return original, ("the model wrote no usable words (" + out[:20].replace("\n", " ") + + "...); prompt unchanged. This text encoder may not be a chat model"), info info.update(after=out, ok=True) return out, f"{status}; prompt {len(original)} -> {len(out)} chars", info diff --git a/modules/conditioning/prompt_enhancer/tests/test_prompt_enhancer.py b/modules/conditioning/prompt_enhancer/tests/test_prompt_enhancer.py index 94061e8c..99a0963e 100644 --- a/modules/conditioning/prompt_enhancer/tests/test_prompt_enhancer.py +++ b/modules/conditioning/prompt_enhancer/tests/test_prompt_enhancer.py @@ -143,6 +143,13 @@ def test_every_failure_returns_the_original_prompt(clip): assert out == "a fox" and not info["ok"] and status +@pytest.mark.parametrize("answer", [",,,,,,,,,,,,,,,,,,,,", "... --- !!!", "1234 5678", "x ,,,,,,,,,,,,,,,,,,,, ,,,,,"]) +def test_an_answer_with_no_words_is_a_failure_not_a_prompt(answer): + """A text encoder that is not a chat model answered with 400 commas; the run used them as the prompt.""" + out, status, info = en().enhance(FakeClip(answer), "a red fox in the snow") + assert out == "a red fox in the snow" and not info["ok"] and "no usable words" in status + + def test_an_empty_prompt_is_skipped_not_sent(): clip = FakeClip() out, status, _ = en().enhance(clip, " ")