Skip to content

fix(calibration): use provided input_ids over a co-existing text column (#4635) - #4638

Merged
Qubitium merged 1 commit into
mainfrom
fix/issue-4635-input-ids-precedence
Nov 17, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/issue-4635-input-ids-precedence

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Root cause

prepare_calibration_dataset checked row keys in the order messages → text → input_ids. A row that carries both text and input_ids — the normal output of Dataset.map(tokenizer, truncation=True, max_length=N) and of dataset[:] — was therefore always re-tokenized from text with default settings:

  • truncation=True, max_length=N was undone and whole documents were fed (up to max_position_embeddings; 2455-5405 tokens instead of 256 in the report), inflating activation memory and capture time;
  • add_special_tokens=False, a custom BOS/EOS, a manually applied chat template, or ids from another pipeline were silently replaced;
  • nothing was logged, while the same dataset with remove_columns(["text"]) behaved as expected.

Change

gptqmodel/utils/calibration.py: explicit input_ids now win over text in the per-example mapping branch (covering lists of rows, BatchEncodings, and the rows produced by _columnar_mapping_examples for columnar mappings). Rows with only text still tokenize it, and messages handling is unchanged. This is the shared helper, so VLM definitions that route pre-tokenized rows through split_calibration_dataset inherit the fix.

Tests

New tests/test_calibration_text_and_ids_precedence_4635.py (4 tests):

  • a row with text + input_ids + attention_mask returns exactly the provided ids/mask and never calls the tokenizer;
  • a columnar mapping with text + input_ids columns keeps the provided ids per row;
  • an HF Dataset.map(...) result that still has the text column keeps the mapped ids;
  • a row with only text still tokenizes the text (precedence is not a blanket change).

On unmodified main the first three fail (the tokenizer is called and the ids are replaced); with the fix all four pass.

Regression run (CPU):

tests/test_calibration_text_and_ids_precedence_4635.py tests/test_calibration_mapping_input.py
tests/test_prepare_dataset.py tests/test_calibration_normalisation.py
tests/test_calibration_padding_mask.py tests/test_calibration_special_tokens_4191.py
tests/test_calibration_truncation.py tests/test_calibration_input_gaps_4311.py
tests/test_calibration_empty_text_4306.py tests/test_vlm_pretokenized_calibration.py
tests/test_vlm_mapping_calibration_4308.py tests/test_vlm_calibration_metadata_columns_4455.py
tests/test_vlm_multimodal_calibration_4371.py tests/test_internvl_chat_calibration.py
tests/test_multimodal_calibration_replay.py tests/test_multimodal_modality_calibration.py
-> 176 passed, 5 skipped

tests/test_calibration_data_device.py (2) and tests/test_generator_calibration_4307.py fail/abort identically on unmodified main (LAPACK SLASCL abort in this environment); unrelated.

Closes #4635.

prepare_calibration_dataset checked row keys in the order messages, text,
input_ids. A row carrying both text and input_ids is the normal output of
Dataset.map(tokenizer, truncation=True, max_length=N) and of dataset[:], so
those rows were silently re-tokenized from the full document: the caller's
truncation, special-token and chat choices were discarded and calibration
fed whole documents (up to max_position_embeddings) instead of the capped
ids.

Explicit token ids now win over text, for both per-row mappings and
columnar mappings. Rows with only text still tokenize it.

Issue #4635.
@Qubitium
Qubitium merged commit 835304b into main Nov 17, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/issue-4635-input-ids-precedence branch November 17, 2026 06:08
Qubitium added a commit that referenced this pull request Nov 17, 2026
…column (#4673)

#4638 made explicit input_ids win over text but left the messages branch
first in prepare_calibration_dataset. A row carrying both messages and
input_ids is the normal output of

    ds.map(lambda r: tok.apply_chat_template(r["messages"], tokenize=True, ...))

and of ds[:] / list(ds), so those rows were re-rendered through the chat
template and re-tokenized from the full conversation: the caller's
truncation, max_length and special-token choices were discarded and
calibration fed 3033 tokens where 256 were requested.

Check input_ids first for every mapping row, and log once how many rows
ignored a source column that way. messages-only rows still render the
template.

Issue #4670.
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