Skip to content

fix(calibration): use provided input_ids over a co-existing messages column (#4670) - #4673

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

Qubitium merged 1 commit into
mainfrom
fix/issue-4670-messages-input-ids

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Root cause

#4638 made explicit input_ids win over a text column, but prepare_calibration_dataset still checked messages first. 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, return_dict=True,
                                         truncation=True, max_length=N))

and of ds[:] / list(ds). Those rows were re-rendered through the chat template and re-tokenized from the full conversation, discarding the caller's truncation / max_length / special-token choices: 3033 tokens fed where 256 were requested (12x the capture work and memory), while the same rows with remove_columns("messages") behaved as expected.

Change

gptqmodel/utils/calibration.py: the input_ids check is now the first branch for every mapping row, so it covers per-row mappings, HF Dataset rows, and the rows _columnar_mapping_examples builds from ds[:]. Rows that only carry messages still render the template, and the messages+text fallback path is unchanged. A single info line reports how many rows used their provided ids instead of a source column.

Tests

New tests/test_calibration_messages_ids_precedence_4670.py (4 tests):

  • a row with messages + input_ids + attention_mask returns exactly the provided ids/mask and never calls the tokenizer or the chat template;
  • the columnar ds[:] shape keeps the provided ids per row;
  • an HF Dataset.map(...) result that still has the messages column keeps the mapped ids;
  • a messages-only row still renders the template (precedence is not a blanket change).

On unmodified main the first three fail (the template is re-rendered and the ids are replaced); with the fix all four pass.

Regression run (CPU):

tests/test_calibration_messages_ids_precedence_4670.py
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 -> 95 passed

tests/test_vlm_pretokenized_calibration.py tests/test_vlm_mapping_calibration_4308.py
tests/test_vlm_calibration_metadata_columns_4455.py -> 179 passed

Closes #4670.

…column

#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.
@Qubitium
Qubitium merged commit 9019b6b into main Nov 17, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/issue-4670-messages-input-ids branch November 17, 2026 09:30
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