fix(sft): tolerate trace-shape tool calls; opt-in skip for unrenderable samples#3081
Open
mikasenghaas wants to merge 1 commit into
Open
fix(sft): tolerate trace-shape tool calls; opt-in skip for unrenderable samples#3081mikasenghaas wants to merge 1 commit into
mikasenghaas wants to merge 1 commit into
Conversation
…le samples
Verifiers rollout datasets store tool_calls as flat JSON strings
({"id","name","arguments"}); deserialize_tool_calls crashed on them with
AttributeError before the renderer ever ran. Normalize both the string
encoding and the flat shape to the OAI form.
Renderer/template raises inside SFTDataset._process previously
propagated out of the dataloader and killed the run on the first bad
sample. New opt-in data.skip_invalid_samples (default False so data
problems still fail loudly) skips-and-logs those samples, mirroring the
existing zero-trainable-tokens skip.
Measured motivation: scaleswe rlm traces (SyntheticData-GLM5.2) crash on
the first tool-call sample without the deserialize fix, and carry ~1%
degenerate samples (garbage tool names, missing code arg) that the rlm
renderer correctly rejects.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Problem
Plugging a verifiers rollout dataset (e.g.
PrimeIntellect/SyntheticData-GLM5.2-scaleswe-reward0,scaleswe_rlm_glm51) into SFT crashes twice over:tool_callsentries as flat JSON strings ('{"id", "name", "arguments"}'), anddeserialize_tool_callscalls.geton them →AttributeError(src/prime_rl/utils/chat_template.py).SFTDataset.__iter__calls_processbare, so a rendererValueErrorpropagates through the dataloader and kills the run. Measured on the dataset above: ~1% of samples are degenerate teacher outputs (garbage tool names like'ipy'/'ipython<tool_call>ipython…', missingcodearg) that a strict renderer correctly refuses.Change
deserialize_tool_callsnow accepts tool-call entries as JSON strings and normalizes the flat verifiers shape into the OAI{"function": {...}}form (id/type preserved). Dict-shaped OAI entries behave exactly as before.data.skip_invalid_samples: bool = False: when on,SFTDataset.__iter__catchesValueErrorfrom_process, warns (mirroring the existing zero-trainable-tokens skip log), and continues. Default off — data problems keep failing loudly.Tests
tests/unit/train/sft/test_sft_dataset.py: trace-shape + OAI-shape deserialization; raising sample crashes with the knob off and is skipped (good samples still yielded) with it on. Full file: 22 passed.🤖 Generated with Claude Code
Note
Low Risk
Localized SFT data preprocessing and an opt-in flag; default behavior stays fail-loud, with no auth or persistence changes.
Overview
Makes SFT usable on verifiers rollout datasets that store tool calls differently and may include a small fraction of unrenderable rows.
deserialize_tool_callsnow accepts each tool-call entry as a JSON string or a flat{id, name, arguments}dict, normalizes them to the OAIfunctionshape, and still parses stringargumentsthe same way as before for dict-shaped entries.data.skip_invalid_samples(defaultfalse) wires through toSFTDataset: when enabled,ValueErrorfrom rendering/_processis logged and the example is skipped instead of aborting the run; when off, behavior is unchanged (fail fast).Unit tests cover trace vs OAI deserialization and the skip knob.
Reviewed by Cursor Bugbot for commit c9acf6b. Bugbot is set up for automated code reviews on this repo. Configure here.