Skip to content

fix(capture): keep mRoPE position ids for multimodal calibration (#4933) - #4961

Merged
Qubitium merged 1 commit into
mainfrom
fix/issue-4933
Nov 17, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/issue-4933

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4933 — a regression from #4930.

Root cause

#4930 made run_input_capture call _with_capture_position_ids, which derived 2-D mask.cumsum(-1) - 1 ids for every model whose forward accepts position_ids. mRoPE VL models (Qwen3-VL/Qwen3.5/GLM-4V/Hunyuan-VL/...) compute their 3-D/4-D image-grid ids inside forward only when position_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 Qwen3VLForConditionalGeneration with one 4x4-patch image row:

eager (no position_ids):  language_model gets (3, 1, 9)   t/h/w grid
parent capture:           language_model gets (1, 9) = [0..8]
fixed capture:            the same (3, 1, 9) grid as eager

Fix

_model_computes_own_position_ids(model) walks model.modules() and returns True for a callable compute_3d_position_ids, get_rope_index or compute_mrope_position_ids — the capability lives on the inner multimodal model, not the outer *ForConditionalGeneration wrapper. No model-name allowlist. BaseQModel.CAPTURE_DERIVE_POSITION_IDS: Optional[bool] = None is an explicit override (None auto, False never derive, True force). _with_capture_position_ids takes derive=; 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.

  • Red on parent: 3 failed, 10 passed (the mRoPE fake, the override, the Qwen3-VL row).
  • Green: new file 4 passed; test_calibration_left_pad_positions_4861.py + test_calibration_padding_mask.py 16 passed; focused set 37 passed, 5 skipped; multimodal family set 15 passed, 6 skipped.
  • Broader capture set: 51 passed, 8 skipped, 2 failed — both are test_positional_mask_capture_4660.py::test_replayed_layers_reproduce_native_layer_output (GPT-2 replay mismatch), identical with main's base.py.
  • ruff check gptqmodel tests: clean.

Residual risk

#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant