Skip to content

fix(vlm): reject multimodal calibration rows instead of dropping tensors (#4371) - #4402

Merged
Qubitium merged 1 commit into
mainfrom
fix/vlm-calibration-4371
Nov 16, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/vlm-calibration-4371

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4371.

Problem

is_pretokenized_sample() in gptqmodel/models/definitions/_vlm_calibration.py classified any mapping containing input_ids as pre-tokenized text. split_calibration_dataset() then routed processor-produced rows to the base text path, which keeps only input_ids/attention_mask. A row from processor(text=..., images=...) therefore kept its image placeholder tokens but silently lost pixel_values / image_grid_thw.

Fix

A token-id row is pre-tokenized only when its extra columns are text-only (token_type_ids, labels, special_tokens_mask, position_ids, tokenizer metadata, text/messages). Rows carrying any other column are rejected with an actionable ValueError naming the offending columns.

Rejecting is the correct contract here: split_calibration_dataset() returns only (pretokenized_rows, conversations), and all VLM prepare_dataset overrides dispatch on that binary result. Neither path can forward arbitrary processor tensors without changing every caller plus model-specific batching/truncation/pixel alignment. This restores the pre-2b51d4d loud failure, but with a clear message instead of an accidental processor crash. Columnar processor output (BatchEncoding) is validated before _columnar_mapping_examples() unpacking, which previously dropped the same tensors silently.

Tests

  • New tests/test_vlm_multimodal_calibration_4371.py: 4 passed.
    • Fails before the fix: the three multimodal cases fail; the text-only case passes before and after.
  • tests/test_vlm_pretokenized_calibration.py tests/test_vlm_mapping_calibration_4308.py tests/test_calibration_mapping_input.py: 146 passed (150 together with the new file).
  • ruff check on both changed files: clean.

Residual risk

  • The text-only column set is an allowlist, so an exotic text-only tokenizer column is now rejected rather than silently ignored (fail-closed).
  • A dataset whose first row is a conversation and a later row is processor-produced multimodal is not eagerly scanned; that later row still fails loudly at the processor path.
  • Non-columnar {"text": ..., "pixel_values": ...} rows (no input_ids) remain on the pre-existing conversation path.

is_pretokenized_sample() treated any mapping with input_ids as text, so
processor(text=..., images=...) rows lost pixel_values/image_grid_thw on
the base text path. Only text-only extra columns now count as
pre-tokenized; rows with other columns raise an actionable error instead
of silently dropping them. Columnar processor output (BatchEncoding) is
validated before unpacking, which previously dropped those columns too.
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.

[BUG] VLM calibration silently drops pixel_values / image_grid_thw from processor-produced rows (regression from 2b51d4d, #4311)

1 participant