Skip to content

Studio: keep tool-call arguments when training on tool-calling datasets - #12487

Merged
Lyxot merged 4 commits into
unslothai:mainfrom
NilayYadav:training-tool-call-arguments
Oct 2, 2026
Merged

Lyxot merged 4 commits into
unslothai:mainfrom
NilayYadav:training-tool-call-arguments

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

Fine-tuning on a chat dataset in the usual OpenAI tool-calling format, where each tool call's arguments are a JSON string, trained the wrong thing. Qwen3.5 learned tool calls with every argument missing (<function=get_weather> and nothing inside), and Gemma 4 learned the raw JSON instead of its own call format. On Llama 3.1, 3.2 and 3.3 training would not start at all ("Chat template failed on all N rows: object of type 'NoneType' has no len()"), because loading the file fills every message with empty tool_calls and similar keys that the template trips over. Nothing warned about the first two.

Each conversation is now cleaned up before the chat template renders it: empty keys added by the loader are dropped, and arguments stored as a JSON string are read as an object, as chat already does. Qwen3.5 and Gemma 4 now train on their real call format with the arguments in place, and Llama 3.x trains normally.

Datasets without tool calls render exactly as before, and arguments that are not valid JSON are left as they are.

… row is dropped

When every render attempt failed, the error came from the row as loaded, so the dropped-row warning named a None key filled by the loader (e.g. "object of type 'NoneType' has no len()" for Llama parallel tool calls) instead of the template's real error. Raise the first attempt's error, document why the as-loaded fallback exists and that dict-typed arguments lose explicit nulls, and tighten the tests: the Qwen3.5 stand-in rejects string arguments like the real template, only None is dropped, and the template probe counts cleaned rows.
@Lyxot

Lyxot commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Pushed 8224cb5 on top.

  • When a tool-call row is dropped, the warning now shows the cleaned row's template error. It used to show the error from the row as loaded, so a Llama 3.x row with two tool calls was reported as "object of type 'NoneType' has no len()" (a key the loader filled with None) instead of "This model only supports single tool-calls at once!". Rendered text is unchanged.
  • A comment notes that dict-typed arguments lose explicit nulls: after loading, a call that left out an optional parameter and one that passed null are identical. JSON-string arguments keep their nulls.
  • Tests: the Qwen3.5 stand-in template now rejects string arguments like the real one, and new tests check that only None is dropped (empty content stays) and that the template probe counts cleaned rows.

Checked by rendering a JSONL fixture through load_dataset("json") and Studio's apply_chat_template_to_dataset with 26 real chat templates (Qwen3.5, Qwen3.8, Gemma 4, Llama 3.2 / 4, Unsloth's llama-3.1 and gpt-oss, Qwen2.5 / Hermes, Qwen3, GLM-4.7 / 5.2, DeepSeek-V3, Kimi K2.5, Seed-OSS, FunctionGemma, Mistral Small 3.1 and others). The fixture covers string, dict, {}, nested, invalid-JSON and parallel-call arguments plus tool results. Text and trained spans are byte-identical to the previous head on every template.

@Lyxot

Lyxot commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Codex review on 8224cb5ff9 (current head): Didn't find any major issues.

CI on the same head: upstream checks passed (44 passed, 3 skipped). The staging run had 3 failing jobs, all from the older merge base it was based on, not from this change: diffusers / sentence_transformers not installed on that runner, the encoding lint on the diffusion offload tests, and the date-dependent client-tools tests. main has since fixed these in #12447, #12444 and #12446, which is why upstream (merged with current main) is green.

@Lyxot Lyxot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Checked by rendering tool-calling rows through Studio's real dataset path with 26 chat templates, on this head merged with current main: tool-call arguments now render in each template's own format inside the trained span, and rows without tool calls are unchanged.

@Lyxot
Lyxot merged commit 666ad7b into unslothai:main Oct 2, 2026
Etherll added a commit to NilayYadav/unsloth that referenced this pull request Oct 2, 2026
Resolve the conflict in chat_templates.py with unslothai#12487: rows now render
through _render_conversation (tool-call cleanup) for both the
system-column attempt and the fallback without it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants