Skip to content

fix(calibration): declare IMAGE_TO_TEXT modality for 4 multimodal wrappers - #3558

Merged
Qubitium merged 2 commits into
mainfrom
fix/multimodal-modality-calibration
Nov 6, 2026
Merged

Qubitium merged 2 commits into
mainfrom
fix/multimodal-modality-calibration

Conversation

@ZX-ModelCloud

@ZX-ModelCloud ZX-ModelCloud commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

BaseQModel.modality defaults to [MODALITY.TEXT] (gptqmodel/models/base.py:423). Four multimodal wrappers never overrode it, so tests/models/model_test.py took the text-only calibration branch (is_image_to_text_model = False) even though their language towers consume image embeddings at inference time:

Model Base class Missing
GlmOCRGPTQ BaseQModel IMAGE_TO_TEXT
MiniMaxM3VLGPTQ BaseQModel IMAGE_TO_TEXT
Qwen3OmniMoeGPTQ BaseQModel IMAGE_TO_TEXT
NemotronOmniQModel NemotronHQModel IMAGE_TO_TEXT

Adding modality alone is not enough: none of the four implemented a multimodal prepare_dataset, so get_calib_dataset() would have hit its NotImplementedError.

Related:
The only open PR mentioning this area is #3457, a docs-only draft that explicitly does not resolve #2928.

Changes

  • GlmOCRGPTQ: now inherits BaseQwen3VLGPTQ (its model.visual + model.language_model layout matches), reuses the shared multimodal calibration path, and sets require_mm_token_type_ids = True because GLM-OCR's forward requires it. Keeps its original module_tree, pre_lm_head_norm_module, and rotary_embedding.
  • MiniMaxM3VLGPTQ: declares IMAGE_TO_TEXT; builds the native MiniMaxM3VLProcessor from AutoImageProcessor + AutoTokenizer + AutoVideoProcessor (loading the remote processor with trust_remote_code=True also swaps in a config that cannot rebuild the model); adds process_vision_info() / prepare_dataset().
  • Qwen3OmniMoeGPTQ: declares IMAGE_TO_TEXT; require_load_processor = True; image+text calibration through the native processor.
  • NemotronOmniQModel: declares IMAGE_TO_TEXT; AutoProcessor(trust_remote_code=True); calibration keeps pixel_values, imgs_sizes, num_patches, num_tokens; run_input_capture() uses model.generate() for multimodal batches because the top-level forward() requires image_flags and calls torch.distributed.get_rank() unconditionally.
  • tests/models/ovis/image_to_test_dataset.py: routes MiniMaxM3VLGPTQ/NemotronOmniQModel to format_qwen2_vl_dataset and Qwen3OmniMoeGPTQ to format_qwen2_5_omni_dataset. GlmOCRGPTQ is covered by the existing BaseQwen3VLGPTQ branch.
  • tests/models/test_minimax_m3.py: LOAD_PROCESSOR = False because AutoProcessor.from_pretrained(..., trust_remote_code=False) fails for MiniMax-M3.
  • tests/test_multimodal_modality_calibration.py: 9 regression tests covering modality declarations, GLM-OCR's shared-base contract and mm_token_type_ids requirement, real fake-processor prepare_dataset outputs for all families, Nemotron's generate-based capture, and get_calib_dataset() dispatch.

Validation

CPU-only unit tests (ROCm env):

37 passed
ruff check: All checks passed

Real processors (prepare_dataset, batch=1 and batch=2) all emit pixel_values:

  • GLM-OCR: input_ids, attention_mask, mm_token_type_ids, pixel_values, image_grid_thw
  • MiniMax-M3: input_ids, attention_mask, pixel_values, image_grid_thw
  • Qwen3-Omni: input_ids, attention_mask, pixel_values, image_grid_thw
  • Nemotron Omni: input_ids, attention_mask, pixel_values, num_patches, num_tokens, imgs_sizes

Real GLM-OCR text-vs-image calibration on AMD ROCm GPUs 2/3 (2 samples, final-token logits vs dense bf16):

cell cosine to dense ↑ KL ↓ MSE ↓
gptq-text (old behavior) 0.983488 0.14231 0.39388
gptq-multimodal (this PR) 0.995017 0.04704 0.12250

Image-conditioned calibration is materially closer to dense on multimodal inference. This is a smoke-level comparison (2 samples), not a statistical result.

Scope / limitations

  • MiniMax-M3 (666G), Qwen3-Omni (66G), and Nemotron-Omni (62G) cannot be really quantized on the 2×R9700 budget available here; those three are validated at the real-processor + calibration-construction + unit-test level.

Notes for reviewers

  • This PR intentionally does not change NemotronOmniQModel.forward(). It still delegates to the model's top-level forward for multimodal calls; only the calibration input-capture path avoids the image_flags / torch.distributed.get_rank() requirements.
  • Draft while the GLM-OCR eval regression (tests/models/test_glm_ocr.py) is run end-to-end.

…ppers

GlmOCRGPTQ, MiniMaxM3VLGPTQ, Qwen3OmniMoeGPTQ, and NemotronOmniQModel
inherited BaseQModel.modality = [MODALITY.TEXT], so model_test.py and the
quantize path calibrated their language towers on text-only activations
while inference feeds image-conditioned activations.

- GlmOCRGPTQ now inherits BaseQwen3VLGPTQ and requires mm_token_type_ids
- MiniMaxM3VLGPTQ/Qwen3OmniMoeGPTQ/NemotronOmniQModel build image+text
  calibration batches through their native processors
- Nemotron input capture uses generate() because the top-level forward
  requires image_flags and calls torch.distributed.get_rank()
- get_calib_dataset routes the new models to image calibration sets
- add regression tests for modality, processor output, and dispatch

GLM-OCR text-vs-image calibration on ROCm (2 samples, final logits vs
dense): text cosine 0.9835 / KL 0.1423; image cosine 0.9950 / KL 0.0470.
@ZX-ModelCloud
ZX-ModelCloud marked this pull request as ready for review November 6, 2026 10:13
The dynamic-resolution image processor returns pixel_values as a list when
image sizes differ, but the remote generate() only accepts a stacked tensor.
Disable batch quantization for Nemotron Omni so heterogeneous images cannot
be mixed into one calibration batch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Qwen3_5_MoeQModel is a VL (image-text-to-text) model but only quantizes the language tower — does text-only calibration hurt multimodal task accuracy?

2 participants