[GOLD] Tool calling support for GOLDTrainer#6328
Open
Strongich wants to merge 23 commits into
Open
Conversation
… has no thinking switch)
…pt to match real tools
…etition_penalty=1.1
Contributor
Author
|
Hi @kashif! I've added multi-turn tool-calling support to this trainer -- would appreciate a review when you have time. Scope: same-family LMs and VLMs only. For VLMs, tool rollouts additionally require Two examples added, both pure on-policy (lmbda=1.0) with use_vllm=True:
A few caveats on the examples:
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d9b273c. Configure here.
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.



What does this PR do?
Adds multi-turn tool-calling support to the
GOLDTrainer, for same-family (shared-tokenizer) distillation. This builds on the recently merged [GOLD] VLM support (#5969).This addition was motivated by these 2 blogs about frontier models' training: first and second.
This PR wires tool calling through both paths: off and on policy, for text LLMs and same-family VLMs, and ports GRPO's
environment_factoryso environment methods become callable tools.What's included
max_tool_calling_iterations(cap on tool-loop turns per rollout);GOLDConfignow overridesremove_unused_columnsto defaultFalse(likeGRPOConfig) so custom dataset columns reachenvironment.reset(**kwargs).DataCollatorForChatML/DataCollatorForVisionLanguageChatML, and the pretokenized dataset-prep path): the prompt is masked, assistant turns — including the assistant's tool-call tokens — are supervised, and tool-result tokens are masked to-100. Mirrorssft_trainer.pysemantics._tool_call_loop/_get_tool_suffix_ids/_generate_single_turnported near-verbatim fromgrpo_trainer.py. Atool_masktracked during generation excludes tool-result tokens from the JSD/Liger loss.environment_factory: ported from GRPO (single-environment form) — pooled per-rollout instances,reset(**example)per rollout, observations injected back into the conversation.get_rewardis excluded from tool extraction, matching GRPO's reserved env-owned-reward hook (Environment-owned reward #6238).tools+use_uld_loss=True,tools+seq_kd=True, andtools+packing=TrueraiseValueError; VLM tool rollouts requireuse_vllm=True; multimodal tool responses (tools returning images) raiseNotImplementedError.Example scripts
Two runnable examples, both pure on-policy (
lmbda=1.0): the student generates and actually executes the tools, and the teacher scores the student's own rollouts.gold_tool_calling.py(text): Qwen3-8B → Qwen3-1.7B on a browser-agent dataset (DataCreatorAI/tool-calling-browser-agent-tasks), filtered to conversations using six executable browser-form tool stubs passed viatools=. Demonstrates the plain-toolspath: shared tokenizer, Qwen3's native tool-calling template, thinking disabled viachat_template_kwargs.gold_tool_calling_vlm.py(VLM): Qwen3-VL-8B-Instruct → Qwen3-VL-2B-Instruct on Search-VL VQA tasks (OpenSearch-VL/Search-VL-SFT-36K), with live tools: DuckDuckGo search (smolagents) plus a docling-basedlayout_parsingenvironment — this one exercisesenvironment_factory(pooled instances, per-exampleresetresolving image references). Tool outputs are capped and the tool loop is bounded bymax_tool_calling_iterations=10.Notable details
<think>blocks), all tool-flow renders — off-policy prep, both collators, and the on-policy_get_tool_suffix_ids— use a single training-safe template computed once at init.<image>) prompt IDs; the processor-expanded IDs remain the source of truth for length bookkeeping and the training forward pass.Testing
environment_factory, and validation-guard tests intests/experimental/test_gold_trainer.py.Before submitting
AI writing disclosure
Note
Medium Risk
Large changes to on-policy generation, loss masking, and VLM vLLM prompting affect core training correctness, but init guards and extensive tests reduce regression risk.
Overview
GOLDTrainer now supports multi-turn tool calling for same-family (shared tokenizer) distillation, aligned with GRPO-style
toolsand optionalenvironment_factory.Config adds
max_tool_calling_iterationsand defaultsremove_unused_columns=Falseso custom dataset columns reachenvironment.reset(**kwargs).Training behavior: off-policy paths mask tool-result tokens while supervising assistant (including tool-call) tokens via collators, pretokenized
tool_mask, and prompt boundaries at the first assistant turn; on-policy runs a multi-turn execute-and-regenerate loop, logs tool metrics, and appliestool_maskso tool results are excluded from the distillation loss. Init rejects incompatible combos (seq_kd, ULD, packing, VLM without vLLM, multimodal tool responses).VLM + vLLM: generation uses tokenizer-only unexpanded prompt IDs (#6294) while processor-expanded IDs stay authoritative for training bookkeeping.
Deliverables: runnable
gold_tool_calling.pyandgold_tool_calling_vlm.pyexamples plus a large expansion oftest_gold_trainer.py(masking, validation, mocked on-policy loop, environment factory).Reviewed by Cursor Bugbot for commit d9b273c. Bugbot is set up for automated code reviews on this repo. Configure here.