Fix crash in Qwen2_5_VLProcessor when using batched input with padding=False#44535
Open
Anakintano wants to merge 2 commits intohuggingface:mainfrom
Open
Fix crash in Qwen2_5_VLProcessor when using batched input with padding=False#44535Anakintano wants to merge 2 commits intohuggingface:mainfrom
Anakintano wants to merge 2 commits intohuggingface:mainfrom
Conversation
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: qwen2_5_vl |
…se (huggingface#44521) `mm_token_type_ids` was constructed by calling `np.array()` and `np.zeros_like()` on the full `text_inputs["input_ids"]` list, which is ragged (variable-length sequences) when `padding=False`. NumPy ≥ 1.24 raises `ValueError: setting an array element with a sequence` for inhomogeneous shapes. Fix: iterate per-sequence so each `np.array()` call receives a 1-D list, avoiding the ragged-array construction entirely.
|
Hi @Anakintano! It looks like this PR fixes a different issue — the ValueError from constructing a ragged numpy array during batched processing without padding. That's a valid bug, but issue #44521 is specifically about assistant_masks being all zeros when multimodal inputs are present. These seem like two separate problems - would it make sense to unlink this PR from #44521 and open a separate issue for the batched padding crash instead? |
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Qwen2_5_VLProcessor.apply_chat_templateraisesValueError: setting an array element with a sequencewhen called with a batch of ≥2 conversations that include images under the defaultpadding=Falsesetting.Root cause:
mm_token_type_idswas built by callingnp.array(text_inputs["input_ids"])on a ragged list (variable-length sequences whenpadding=False). NumPy ≥ 1.24 rejects inhomogeneous shapes for this operation.Fix
Iterate per-sequence instead of constructing a 2D array from a ragged list. Each
ids_arr = np.array(ids)call receives a 1-D list, so the shape is always homogeneous.Changed in both:
src/transformers/models/qwen2_5_vl/modular_qwen2_5_vl.pysrc/transformers/models/qwen2_5_vl/processing_qwen2_5_vl.py(auto-generated copy, manually synced sincemakeis unavailable on Windows)Test
Added
test_batched_apply_chat_template_no_paddingintests/models/qwen2_5_vl/test_processing_qwen2_5_vl.pyto guard against regression.Closes #44545