From 03f70b77e76c8274ada5584ba956436bd6ceb6fb Mon Sep 17 00:00:00 2001 From: Osamaali313 <86572800+Osamaali313@users.noreply.github.com> Date: Sun, 21 Jun 2026 16:24:36 +0300 Subject: [PATCH] Fix ValueError in _encode_prompt truncation check for long prompts The CLIP truncation warning used `not np.equal(text_input_ids, untruncated_ids)`. `np.equal` returns an element-wise boolean array, so applying `not` raises `ValueError: The truth value of an array with more than one element is ambiguous` when the shapes match, and a broadcasting `ValueError` when they differ (the actual truncation case). Since text_input_ids is always padded to model_max_length (77), this branch is reached for any prompt that tokenizes to >= 77 tokens, crashing prompt encoding before generation -- including exactly the truncation case the warning is meant to report. Use `np.array_equal`, which returns a scalar bool and safely returns False for differing shapes (matching the `torch.equal` semantics this was ported from), so the warning fires correctly instead of raising. --- python_coreml_stable_diffusion/pipeline.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python_coreml_stable_diffusion/pipeline.py b/python_coreml_stable_diffusion/pipeline.py index c7ab63de..e3d46c50 100644 --- a/python_coreml_stable_diffusion/pipeline.py +++ b/python_coreml_stable_diffusion/pipeline.py @@ -161,7 +161,7 @@ def _encode_prompt(self, # tokenize without max_length to catch any truncation untruncated_ids = tokenizer(prompt, padding="longest", return_tensors="np").input_ids - if untruncated_ids.shape[-1] >= text_input_ids.shape[-1] and not np.equal( + if untruncated_ids.shape[-1] >= text_input_ids.shape[-1] and not np.array_equal( text_input_ids, untruncated_ids ): removed_text = tokenizer.batch_decode(untruncated_ids[:, tokenizer.model_max_length - 1: -1])