You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Calibration rows with both text and input_ids are silently re-tokenized from text: Dataset.map(tokenize, truncation=True, max_length=256) feeds 2455-5405-token documents instead of 256 #4635
Found on main @ 597b39b, RTX 4090 host (repro is CPU-only, real Qwen2.5-0.5B-Instruct tokenizer).
What is wrong
gptqmodel/utils/calibration.py:600-611 (prepare_calibration_dataset) checks the row keys in this order: messages, then text, then input_ids. A row that carries both text and input_ids is always re-tokenized from text with default settings, and the user's input_ids / attention_mask are dropped without a message.
Rows like that are the normal output of the most common pre-tokenization recipe. Dataset.map(lambda x: tok(x["text"], truncation=True, max_length=N)) keeps the text column next to the new input_ids/attention_mask, as does ds[:] of such a dataset. So any tokenization choice the user made is silently undone:
truncation=True, max_length=N (the usual way to cap calibration memory/time): the full documents are fed instead, up to max_position_embeddings (32768 for Qwen2.5). Activation memory and capture time grow by more than 20x in the repro below.
add_special_tokens=False, a custom BOS/EOS, a manually applied chat template on the ids, or ids from another preprocessing pipeline: all replaced by tokenizer(text).
Nothing is logged. The same dataset with remove_columns(["text"]) gives the expected result, so the text column alone, which looks harmless, changes the calibration set.
Repro
importgzip, json, typesfromtransformersimportAutoTokenizer, AutoConfigfromdatasetsimportDatasetfromgptqmodel.utils.calibrationimportprepare_calibration_datasetP="Qwen/Qwen2.5-0.5B-Instruct"tok=AutoTokenizer.from_pretrained(P)
q=types.SimpleNamespace(tokenizer=tok, model=types.SimpleNamespace(config=AutoConfig.from_pretrained(P)),
support_batch_quantize=True) # same call quantize() makes via BaseQModel.prepare_datasettexts= [...] # 4 C4 documents longer than 6000 charsds=Dataset.from_dict({"text": texts}).map(lambdax: tok(x["text"], truncation=True, max_length=256))
print(ds.column_names, [len(r) forrinds["input_ids"]])
print([int(b["attention_mask"].sum()) forbinprepare_calibration_dataset(q, ds)])
print([int(b["attention_mask"].sum()) forbinprepare_calibration_dataset(q, ds.remove_columns(["text"]))])
print(prepare_calibration_dataset(q, [{"text": "hello world "*20, "input_ids": [1, 2, 3] *20}])[0]["input_ids"][0][:6])
Output:
['text', 'input_ids', 'attention_mask'] [256, 256, 256, 256]
[2455, 1628, 5405, 1690] # tokens actually fed to layer 0: user truncation ignored
[256, 256, 256, 256] # same data without the text column
tensor([14990, 1879, 23811, 1879, 23811, 1879]) # user ids [1, 2, 3, ...] discarded
Suggested fix
When a row (or a columnar mapping) supplies input_ids, use them: explicit token ids should win over text. If keeping text precedence is intended, log a warning (once) that input_ids were ignored, and document the precedence. VLM definitions route such rows through split_calibration_dataset (which classifies them as pre-tokenized) into this same base path, so they inherit the fix.
Test that should have caught it
tests/test_prepare_dataset.py / tests/test_calibration_mapping_input.py have no row with both text and input_ids. Add a Dataset.map(tokenize, truncation=True, max_length=N) case that asserts the prepared rows equal the mapped input_ids (or that a warning is raised).
Severity
Low-medium. The input form is standard, the override is silent, and it changes both the calibration set and the memory/time budget (an OOM risk on long-document corpora). No crash.
Taking this. Explicit input_ids will win over text (the row's tokenization is the caller's decision), with the row/columnar paths covered by a regression test built from a Dataset.map(tokenize, truncation=True, max_length=N) result.
Activity
Qubitium commentedon Nov 17, 2026
Claimed. This issue is now owned by a dedicated worker; a fix PR referencing it will follow. Please avoid duplicating work on it in the meantime.
Qubitium commentedon Nov 17, 2026
Taking this. Explicit
input_idswill win overtext(the row's tokenization is the caller's decision), with the row/columnar paths covered by a regression test built from aDataset.map(tokenize, truncation=True, max_length=N)result.fix(calibration): use provided input_ids over a co-existing text colu…