Repository navigation
fix(capture): keep mRoPE position ids for multimodal calibration (#4933) - #4961
Merged
Merged
Conversation
#4930 derived 2-D position_ids from the attention mask for every model whose forward accepts the parameter. Qwen3-VL/Qwen3.5/GLM-4V/Hunyuan-VL-class models compute their 3-D/4-D image-grid ids inside forward only when position_ids is None, so the derived ids replaced the mRoPE grid with sequential text positions and image calibration rows ran on hidden states up to 45% off. Derive only when the model does not own the computation. The predicate walks the module tree for compute_3d_position_ids / get_rope_index / compute_mrope_position_ids (the capability lives on the inner multimodal model, not the outer conditional-generation wrapper), and a new CAPTURE_DERIVE_POSITION_IDS definition attribute can force it either way. Models without the capability (GPT-2/GPT-Neo/OPT) keep the #4861 left-pad fix.
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.
Fixes #4933 — a regression from #4930.
Root cause
#4930 made
run_input_capturecall_with_capture_position_ids, which derived 2-Dmask.cumsum(-1) - 1ids for every model whoseforwardacceptsposition_ids. mRoPE VL models (Qwen3-VL/Qwen3.5/GLM-4V/Hunyuan-VL/...) compute their 3-D/4-D image-grid ids insideforwardonly whenposition_ids is None, so the derived 2-D tensor replaced the grid ids and image tokens were calibrated at sequential positions.Reproduced on a tiny real
Qwen3VLForConditionalGenerationwith one 4x4-patch image row:Fix
_model_computes_own_position_ids(model)walksmodel.modules()and returns True for a callablecompute_3d_position_ids,get_rope_indexorcompute_mrope_position_ids— the capability lives on the inner multimodal model, not the outer*ForConditionalGenerationwrapper. No model-name allowlist.BaseQModel.CAPTURE_DERIVE_POSITION_IDS: Optional[bool] = Noneis an explicit override (Noneauto,Falsenever derive,Trueforce)._with_capture_position_idstakesderive=; when auto-detection finds the capability it returns the example untouched, and models without it (GPT-2/GPT-Neo/OPT) keep #4861's left-pad derivation.Tests
New
tests/test_capture_mrope_position_ids_4933.py(4 tests): mRoPE fake keeps its own ids, plain text model still gets the corrected 1-D ids, the override works both ways, and a real tiny Qwen3-VL image row's captured ids equal the eager 3-D mRoPE ids.test_calibration_left_pad_positions_4861.py+test_calibration_padding_mask.py16 passed; focused set 37 passed, 5 skipped; multimodal family set 15 passed, 6 skipped.test_positional_mask_capture_4660.py::test_replayed_layers_reproduce_native_layer_output(GPT-2 replay mismatch), identical with main'sbase.py.ruff check gptqmodel tests: clean.Residual risk
CAPTURE_DERIVE_POSITION_IDS = False.run_input_capturefor image rows; their text-row path now also skips derivation (RoPE positions are shift-invariant for attention, so [BUG] Left-padded batch_size>1 calibration shifts absolute position embeddings (GPT-2/GPT-Neo): capture forward passes no position_ids derived from the mask #4861's absolute-embedding concern does not apply).