Repository navigation
fix(calibration): use provided input_ids over a co-existing messages column (#4670) - #4673
Merged
Merged
Conversation
…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.
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
#4638 made explicit
input_idswin over atextcolumn, butprepare_calibration_datasetstill checkedmessagesfirst. A row carrying bothmessagesandinput_idsis the normal output ofand 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 withremove_columns("messages")behaved as expected.Change
gptqmodel/utils/calibration.py: theinput_idscheck is now the first branch for every mapping row, so it covers per-row mappings, HFDatasetrows, and the rows_columnar_mapping_examplesbuilds fromds[:]. Rows that only carrymessagesstill render the template, and themessages+textfallback 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):messages+input_ids+attention_maskreturns exactly the provided ids/mask and never calls the tokenizer or the chat template;ds[:]shape keeps the provided ids per row;Dataset.map(...)result that still has themessagescolumn keeps the mapped ids;messages-only row still renders the template (precedence is not a blanket change).On unmodified
mainthe first three fail (the template is re-rendered and the ids are replaced); with the fix all four pass.Regression run (CPU):
Closes #4670.