Repository navigation
SFT on multi-turn tool trajectories: messages datasets, assistant_only_loss markers, gpt-oss response marker - #1663
Conversation
…stant_only_loss marker fallback, fix role markers cut to a shared opener
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 69549ac08f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| truncate_messages = do_truncation and max_seq_length > 0 and \ | ||
| not locals().get("_unsloth_wrapped_packing", False) |
There was a problem hiding this comment.
Preserve full conversations when packing
When packing=True, this condition still enables per-row truncation because _unsloth_wrapped_packing is never defined anywhere in the repository and the actual packing argument is not checked. Consequently, _tokenize_messages slices every trajectory to max_seq_length before pack_dataset runs, silently discarding later tool calls and assistant answers instead of allowing the packer to chunk the full token stream; disable this truncation whenever packing is enabled.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Unsloth defines _unsloth_wrapped_packing when it rewrites this function into the trainer (rl_replacements.py _WRAPPED_PACKING_SETUP), true only for packing_strategy wrapped. For bfd packing rows are truncated before packing, the same as the text path and TRL.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 56a2181220
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if isinstance(template, dict): | ||
| return "\n".join(v for v in template.values() if isinstance(v, str)) |
There was a problem hiding this comment.
Resolve generation markers from the selected named template
The follow-up mapping fix concatenates every named template before detecting generation markers, which is incorrect when, for example, tool_use contains {% generation %} but default does not. A row without tools selects default, yet the marker found in tool_use disables marker fallback globally, so Transformers returns an all-zero assistant mask and this code drops the row; if all rows select the markerless template, preparation then raises StopIteration. Determine marker support from the template actually selected for each row rather than from the union of all entries.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Below the bar: it needs a named template set where only one entry carries {% generation %} markers. Those markers come from TRL's training templates, which are single strings; no shipped tokenizer has such a set.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4f0f8de048
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| truncate_messages = do_truncation and max_seq_length > 0 and \ | ||
| not locals().get("_unsloth_wrapped_packing", False) |
There was a problem hiding this comment.
Allow
max_length=None for message datasets
When packing is disabled and SFTConfig.max_length=None is used to request no truncation, do_truncation is set to true because None != 0, and this comparison then raises TypeError before any conversational row is tokenized. This is a supported configuration and affects message datasets regardless of whether assistant_only_loss is enabled; treat None as truncation disabled instead of comparing it with an integer.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in e38dfb2: a None max_length turns message truncation off. Test added.
| masks = masks[0] | ||
| result["assistant_masks"] = list(masks) | ||
| if truncate_messages: | ||
| result = {k: v[:max_seq_length] for k, v in result.items()} |
There was a problem hiding this comment.
Honor
keep_end when truncating conversations
For runs configured with truncation_mode="keep_end", this unconditional prefix slice keeps the beginning of the conversation instead of the requested tail. In multi-turn datasets that mode is commonly used to retain the final assistant answer; this can instead remove every supervised token and cause the subsequent filter to drop the row, silently changing the training data.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in e38dfb2: keep_end keeps the last max_length tokens, as TRL and Unsloth's other caps do. Test added (fails before).
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
SFT on multi-turn tool-calling trajectories (agent traces).
messagesdatasets: amessages(+ optionaltools) dataset with no text column and noformatting_funcraisedUnsloth: You must specify a formatting_func.sft_prepare_datasetnow tokenizes these rows with the chat template and tools, using TRL's training template when TRL swapped one in, and drops theNonekeys Arrow fills into messages (they crashed the Llama template).assistant_only_loss: when Unsloth set_unsloth_assistant_mask_fallback(TRL has no training template for this chat template), or the template in use has no{% generation %}markers (TRL < 1.7 never swaps one in, so masks would be all zero and train nothing), the assistant mask comes fromtrain_on_responses_onlymarkers. gpt-oss gets markers that keep its analysis, tool calls and final answer.train_on_responses_onlyshared opener: edge trimming cut gpt-ossresponse_part="<|start|>assistant"down to<|start|>, which every role shares, so system, user and tool turns were trained. Only that case changes: 249 cases (all 51 Unsloth chat templates plus hub tokenizers, auto-detected markers and every marker pair the notebooks use) give byte-identical labels except the 8 gpt-oss<|start|>assistantones, which now train only tool calls and final answers (107/115 trained tokens before).Tests:
tests/test_tool_trajectory_masks.py(11, CPU, TRL 1.0 / 1.13 / 1.15). Plain-text,formatting_funcandmessages+textdatasets tokenize to identical rows before and after. Pairs with the unsloth PR for theassistant_only_lossfallback.