Repository navigation
fix(calibration): use provided input_ids over a co-existing text column (#4635) - #4638
Merged
Merged
Conversation
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.
This was referenced Nov 17, 2026
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause
prepare_calibration_datasetchecked row keys in the ordermessages→text→input_ids. A row that carries bothtextandinput_ids— the normal output ofDataset.map(tokenizer, truncation=True, max_length=N)and ofdataset[:]— was therefore always re-tokenized fromtextwith default settings:truncation=True, max_length=Nwas undone and whole documents were fed (up tomax_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;remove_columns(["text"])behaved as expected.Change
gptqmodel/utils/calibration.py: explicitinput_idsnow win overtextin the per-example mapping branch (covering lists of rows,BatchEncodings, and the rows produced by_columnar_mapping_examplesfor columnar mappings). Rows with onlytextstill tokenize it, andmessageshandling is unchanged. This is the shared helper, so VLM definitions that route pre-tokenized rows throughsplit_calibration_datasetinherit the fix.Tests
New
tests/test_calibration_text_and_ids_precedence_4635.py(4 tests):text+input_ids+attention_maskreturns exactly the provided ids/mask and never calls the tokenizer;text+input_idscolumns keeps the provided ids per row;Dataset.map(...)result that still has thetextcolumn keeps the mapped ids;textstill tokenizes the text (precedence is not a blanket change).On unmodified
mainthe first three fail (the tokenizer is called and the ids are replaced); with the fix all four pass.Regression run (CPU):
tests/test_calibration_data_device.py(2) andtests/test_generator_calibration_4307.pyfail/abort identically on unmodifiedmain(LAPACKSLASCLabort in this environment); unrelated.Closes #4635.