fix: use shape index access in compute_3d_position_ids for Qwen VL models#44921
Open
s-zx wants to merge 1 commit intohuggingface:mainfrom
Open
fix: use shape index access in compute_3d_position_ids for Qwen VL models#44921s-zx wants to merge 1 commit intohuggingface:mainfrom
s-zx wants to merge 1 commit intohuggingface:mainfrom
Conversation
…dels batch_size, seq_length, _ = inputs_embeds.shape raises ValueError when inputs_embeds has more than three dimensions (e.g. when TRL SFT trainer passes inputs_embeds directly, or after NEFTune noise injection adds a leading dimension). Switching to explicit index access makes the code robust to any number of dimensions >= 2. Fixes: transformers#44918 Affected models: Qwen2.5-VL, Qwen3-VL, Qwen3.5
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: qwen2_5_vl, qwen3_5, qwen3_vl |
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.
What does this PR do?
Fixes #44918.
compute_3d_position_idsin the Qwen2.5-VL / Qwen3-VL / Qwen3.5 model families destructuresinputs_embeds.shapeinto exactly three variables:This raises
ValueError: too many values to unpack (expected 3)wheninputs_embedshas more than three dimensions, which can happen when:inputs_embedsdirectly (withoutinput_ids) after processing, producing a batch with an extra dimensionstale rope_deltasfrom a preceding generation step (e.g. during evaluation) causes theelifbranch to fire on a subsequent training forward passFix
Replace destructuring with explicit index access:
This is robust to any tensor with ≥ 2 dimensions and does not change behaviour for the standard 3-D case.
Affected files
models/qwen2_5_vl/modular_qwen2_5_vl.py— source modular definitionmodels/qwen2_5_vl/modeling_qwen2_5_vl.py— generated filemodels/qwen3_vl/modeling_qwen3_vl.py— generated file (inherits the method)models/qwen3_5/modeling_qwen3_5.py— generated file (inherits the method)