Repository navigation
Description
Found on main @ 3867c82, CPU (tokenizer-only path), transformers 5.22.1, datasets as installed.
What is wrong
#4927 (fix of #4858) forwards a row's tools/documents to apply_chat_template exactly as stored (gptqmodel/utils/calibration.py:776, template_inputs[key] = value). It does not handle the two layouts that function-calling calibration data on the HF Hub actually arrives in:
toolsstored as a JSON string. Many HF tool-calling datasets storetoolsas a JSON string column, because Arrow cannot hold heterogeneous schemas.apply_chat_templateraisesValueError: Tools should either be a JSON schema, or a callable ..., and fix(calibration): render a messages row with its tools and documents (#4858) #4927's fallback re-renders the row without the tools. The schema still never reaches the Hessian, the exact [BUG] Calibration messages rows: the tools column is silently dropped; tool schemas never reach the Hessian (101 of 236 intended tokens on Qwen2.5) #4858 symptom, with one warning for the whole run.toolsstored as a list of dicts in an HFDataset. Arrow unifies the struct schema across rows, so every row's schema gains every other row's parameter names asnull, for example"properties": {"city": {...}, "tz": null}. The rendered tool block then differs from what inference sends. Nothing is logged.
Repro (Qwen2.5-0.5B-Instruct tokenizer, two rows with different one-tool schemas)
msgs = [{"role":"user","content":"What's the weather in Paris?"},{"role":"assistant","content":"Sunny."}]
# t1 = get_weather(city), t2 = get_time(tz)
ref = lambda t: len(tok(tok.apply_chat_template(msgs, tools=t, tokenize=False), add_special_tokens=False)["input_ids"])
prepare_calibration_dataset(m, calibration_dataset=[{"messages":msgs,"tools":json.dumps(t1)}, {"messages":msgs,"tools":json.dumps(t2)}], batch_size=1)
prepare_calibration_dataset(m, calibration_dataset=Dataset.from_list([{"messages":msgs,"tools":t1}, {"messages":msgs,"tools":t2}]), batch_size=1)
prepare_calibration_dataset(m, calibration_dataset=Dataset.from_list([{"messages":msgs,"tools":json.dumps(t1)}, {"messages":msgs,"tools":json.dumps(t2)}]), batch_size=1)ref no tools 41 ref t1 182 ref t2 179
WARN Quantize: this tokenizer's chat template rejected the calibration row's ['tools']; rendering without them: ValueError: Tools should either be a JSON schema, ...
list rows, JSON-string tools [41, 41] <- tools dropped (expected 182, 179)
HF Dataset, list tools [186, 184] <- schema rendered with injected nulls:
{"type": "function", "function": {"name": "get_weather", ..., "properties": {"city": {...}, "tz": null}, ...}}
HF Dataset, JSON-string tools [41, 41] <- tools dropped
A Python list of dict rows with real dict tools works (208/208 on a one-tool row; Llama-3.2-1B 229/229, Qwen3-0.6B 196/196).
Suggested fix
Normalize the template inputs before forwarding them. json.loads a str value of tools/documents, and recursively drop None values that Arrow injected into dict schemas (a JSON schema never legitimately carries a null property definition). The rejecting-template fallback should stay only for templates that truly don't support tools.
Test that should have caught it
tests/test_calibration_messages_tools_4858.py only feeds Python lists of dict rows. It needs one case with a datasets.Dataset built from rows with different tool schemas, and one with a JSON-string tools column, each asserting token equality with apply_chat_template(messages, tools=<original list>).
Severity: low-medium. Calibration on HF function-calling datasets still misses or distorts the tool schema block. That is the #4858 accuracy gap, now with a warning in case 1 and silent in case 2.
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 17, 2026
Agent claim:
agent-root-4934is working on this issue now.Qubitium commentedon Nov 17, 2026
Agent claim released:
agent-53ba17eb4d83finished this issue.Pull request: #5004
HF-datasets tools must reach the chat template exactly as at inference
test(calibration): raise the skip exception explicitly (#4934)
test(calibration): raise the tokenizer skip exception explicitly (#4934)
Qubitium commentedon Nov 17, 2026
Agent claim released:
agent-root-4934finished this issue.Pull request: #4997 — squash-merged to
mainas9c5efff3494ec416442225a0aae79eda398a1013.What landed (
gptqmodel/utils/calibration.py+ two regression files):_normalize_template_input_value()decodes an object/array JSON string and drops theNonemapping entries Arrow injects into a unified struct schema, while keeping a real JSON-schemanull({"type": "null"}) andNonelist elements; containers are copied, so the caller's rows are not mutated. A plain, non-JSON string ("the weather in Paris","42","true") is forwarded unchanged._normalize_template_input_payload()additionally presents a one-tooltoolspayload as the list the chat templates iterate (a one-object column was rejected outright)._tokenize_messages_value()now runs both before calling the template, so the schema block the model sees at inference is the one that reaches the Hessian. The rejecting-template fallback and its one-shot warning are unchanged.tests/test_calibration_messages_tools_4858.py(+5 nodes, +1 real-tokenizer matrix node) andtests/test_calibration_tools_formats_4934.py(ported from fix(calibration): normalize the tool schemas HF datasets store (#4934) #5004, all 5 nodes kept unweakened). Both run in the pre-mergeAWQ CPU (unit)suite;gptqmodel/utils/calibration.pyandtests/test_calibration_*.pynow trigger that workflow.calibration.pycitations indocs/decision-transformer-calibration.mdare symbol-anchored and guarded bytests/test_docs_contract_refs.py.Red → green: with both regression files copied onto unmodified
origin/main(2be068cc6): 9 failed, 7 passed; on the merged tree: 39 passed together with the docs contract. Real-tokenizer evidence: reference 164/164 ids; before, every Hub layout rendered 41/41 (tools dropped); after,listrows,Datasetrows,Dataset[:]andwith_format("numpy"|"pandas"|"arrow")[:]all render 164/164.PR #5004 (
fix/issue-4934, the duplicate that addedtests/test_calibration_tools_formats_4934.py) is closed as superseded, with a comment listing the adjustments.fix(calibration): drop Arrow's injected nulls from `messages` (#5082) (…
fix(calibration): render Hub `tools` columns the way inference does (M…