Repository navigation
Description
Found on main @ e75181d, CPU (Qwen2.5-0.5B-Instruct, Qwen3-0.6B and Llama-3.2-1B-Instruct tokenizers, transformers 5.22.1, datasets).
What is wrong
#4997 (the fix for #4934) normalizes Arrow-unified values only in the tools/documents columns (_normalize_template_input_payload, gptqmodel/utils/calibration.py:967). The messages column of the same rows has the same Arrow problem, and it reaches apply_chat_template unchanged (_tokenize_messages_value(example["messages"], ...), calibration.py:1055).
When a function-calling dataset is loaded as a datasets.Dataset (the usual Hub layout: messages with tool_calls turns plus a tools column), Arrow unifies the struct schema across all rows and turns:
- every tool call's
argumentsgains the other rows' argument names with valueNone. For example,{"city": "Paris"}becomes{"city": "Paris", "query": None}; - every turn (user, system, tool, assistant) gains
"tool_calls": None, and likewise any other key that some turn has (name,tool_call_id,reasoning_content, ...).
The result depends on the template:
- Qwen2.5 / Qwen3 (silent): the assistant tool-call turn is rendered as
{"name": "get_weather", "arguments": {"city": "Paris", "query": null}}. Inference renders{"city": "Paris"}, so every tool-call row is calibrated on tokens the model never sees at inference (+5 tokens per call in this example; more with real datasets that have dozens of distinct argument names). - Llama-3.x (crash): the template tests
'tool_calls' in messageon every turn. The injectedtool_calls: Noneon a user turn reachesmessage.tool_calls|length, andquantize()fails withTypeError: object of type 'NoneType' has no len(). The same rows passed as a Python list work.
Every Arrow-backed input shape is affected: Dataset, Dataset[:], Dataset.to_pandas(), with_format("numpy"), list(Dataset).
Repro
import types
from datasets import Dataset
from transformers import AutoTokenizer, AutoConfig
from gptqmodel.utils.calibration import prepare_calibration_dataset
P = "Qwen/Qwen2.5-0.5B-Instruct" # or meta-llama/Llama-3.2-1B-Instruct
tok, cfg = AutoTokenizer.from_pretrained(P), AutoConfig.from_pretrained(P)
q = types.SimpleNamespace(tokenizer=tok, model=types.SimpleNamespace(config=cfg), support_batch_quantize=True)
def tool(name, arg): return [{"type": "function", "function": {"name": name, "description": name,
"parameters": {"type": "object", "properties": {arg: {"type": "string"}}, "required": [arg]}}}]
rows = [
{"messages": [{"role": "user", "content": "Weather in Paris?"},
{"role": "assistant", "content": "", "tool_calls": [{"type": "function", "function": {"name": "get_weather", "arguments": {"city": "Paris"}}}]},
{"role": "tool", "content": "18C"}, {"role": "assistant", "content": "18C in Paris."}], "tools": tool("get_weather", "city")},
{"messages": [{"role": "user", "content": "Tallest mountain?"},
{"role": "assistant", "content": "", "tool_calls": [{"type": "function", "function": {"name": "search", "arguments": {"query": "tallest mountain"}}}]},
{"role": "tool", "content": "Everest"}, {"role": "assistant", "content": "Everest."}], "tools": tool("search", "query")},
]
for label, data in (("list", rows), ("Dataset", Dataset.from_list(rows))):
b = prepare_calibration_dataset(q, data, calibration_data_min_length=0)
ids = b[0]["input_ids"][0][b[0]["attention_mask"][0].bool()]
print(label, len(ids), [l for l in tok.decode(ids).splitlines() if "arguments" in l])Output (Qwen2.5-0.5B-Instruct):
list 212 [..., '{"name": "get_weather", "arguments": {"city": "Paris"}}']
Dataset 217 [..., '{"name": "get_weather", "arguments": {"city": "Paris", "query": null}}']
Output (Llama-3.2-1B-Instruct): list -> 210 tokens; Dataset -> TypeError: object of type 'NoneType' has no len().
The full matrix on this box (3 rows: two tool-call rows and one plain row): Qwen2.5 and Qwen3 tool-call rows differ from the HF template by +5 tokens in every Arrow-backed shape; the plain row matches. Llama-3.2 raises in every Arrow-backed shape.
Suggested fix
Apply the #4934 normalization to the conversation as well, before templating: in each message, drop dict keys whose value is None, recursively and including tool_calls[*].function.arguments. The messages value can go through the same _normalize_template_input_value walk. Also decode arguments when it is a JSON string, since many Hub datasets store it that way. That walk already keeps a None inside a list and a JSON-schema "null" string.
Test that should have caught it
tests/test_calibration_tools_formats_4934.py covers Arrow unification only for the tools column. It needs a case with two tool_calls rows that have different argument names, loaded through Dataset.from_list, asserting token equality with the Python-list rows. Add a Llama-3.x template case for the crash.
Severity
Medium: silent calibration-token corruption for Qwen-family function-calling datasets, and a hard failure for Llama-3.x. This is the same input population #4858/#4934 were fixed for.
🤖 Generated with Claude Code
Activity
ZX-ModelCloud commentedon Nov 18, 2026
Claimed. I'm working on this issue and will submit a fix PR. Please avoid duplicate work in the meantime.
ZX-ModelCloud commentedon Nov 18, 2026
Agent claim released:
agent-47b6cff75d33is no longer working on this issue.The issue is free to claim.
Handing the claim to the continued session in this thread to finish the fix.
ZX-ModelCloud commentedon Nov 18, 2026
Agent claim released:
agent-5f3960840137finished this issue.Pull request: #5112
Fix pushed as draft PR; AWQ CPU (unit) regression suite running in CI
fix(calibration): drop Arrow's injected nulls from `messages` (#5082) (…