Repository navigation
Support assistant-only loss for the DeepSeek-V4.1-Flash chat templates - #8569
Open
albertvillanova wants to merge 1 commit into
Open
albertvillanova wants to merge 1 commit into
albertvillanova wants to merge 1 commit into
Conversation
15 of 39 tasks
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. Pages changed in this PR: |
qgallouedec
approved these changes
Nov 24, 2026
| ), | ||
| pytest.param( | ||
| ("trl-internal-testing/tiny-DeepseekV3ForCausalLM", deepseekv4_1_flash_chat_template), | ||
| id="deepseekv4.1-flash", |
Member
There was a problem hiding this comment.
To match the ids in #8563 (deepseek-v3, deepseek-v3-v5, ...):
Suggested change
| id="deepseekv4.1-flash", | |
| id="deepseek-v4.1-flash", |
| ), | ||
| pytest.param( | ||
| ("trl-internal-testing/tiny-DeepseekV3ForCausalLM", deepseekv4_1_flash_1017_chat_template), | ||
| id="deepseekv4.1-flash-1017", |
Member
There was a problem hiding this comment.
Suggested change
| id="deepseekv4.1-flash-1017", | |
| id="deepseek-v4.1-flash-1017", |
This branch has not been deployed
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.
This PR makes
assistant_only_loss=Truework for the chat templates shipped bydeepseek-ai/DeepSeek-V4.1-Flashanddeepseek-ai/DeepSeek-V4.1-Flash-1017.Part of #7962.
Motivation
TRL does not store these templates, and they have no
{% generation %}markers, soget_training_chat_templateraises andSFTTrainerwithassistant_only_loss=Truefails at init.Changes
deepseekv4_1_flash.jinjaanddeepseekv4_1_flash_1017.jinja, and add a training template for each that wraps the assistant output (reasoning and</think>, content, tool calls and<|end▁of▁sentence|>) with{% generation %}markers. The generation prompt (<|Assistant|><think>, or</think>with thinking off) stays outside.toolsare passed re-renders the earlier assistant turn without its thinking block (drop_thinking), which breaks prefix-preservation.<|System|>), but not the ones at the boundaries of the trained span.On the real tokenizers of both checkpoints, the training templates render like the originals (with and without thinking, with tools, multi-turn), the trained span of the last turn starts right after the generation prompt, and it ends with
<|end▁of▁sentence|>, the checkpoints' stop token.Note
Low Risk
Adds new Jinja templates and registry entries following existing DeepSeek patterns; impact is limited to users training those checkpoints with TRL’s template swapping.
Overview
Adds DeepSeek-V4.1-Flash and DeepSeek-V4.1-Flash-1017 to TRL’s bundled chat templates so
get_training_chat_templatecan swap in patched variants whenassistant_only_loss=True(SFT) or tools are used (GRPO).Reference templates (
deepseekv4_1_flash.jinja,deepseekv4_1_flash_1017.jinja) mirror the Hub checkpoints. Training templates wrap assistant spans (reasoning, content, tool calls,<|end▁of▁sentence|>) in{% generation %}/{% endgeneration %}. The Flash training template also treats user messages that only carry tool results as not starting a new user turn, fixing prefix-preservation whendrop_thinkingwould otherwise re-render prior assistant turns without thinking.Wiring in
chat_template_utils.py, docs, drift check repos, and pytest cases for the tiny DeepSeek-V3 tokenizer complete the integration.Reviewed by Cursor Bugbot for commit 89c2749. Bugbot is set up for automated code reviews on this repo. Configure here.