Repository navigation
Support assistant-only loss for the DeepSeek-V4.1-Flash chat templates - #8569
Merged
Merged
Conversation
21 of 44 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", |
…-1-assistant-only-loss # Conflicts: # docs/source/chat_templates.md
…-1-assistant-only-loss # Conflicts: # docs/source/chat_templates.md
albertvillanova
deleted the
support-deepseek-v4-1-assistant-only-loss
branch
November 26, 2026 08:05
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
Additive chat-template support with tests and docs; no changes to core training or auth paths beyond enabling assistant-only loss for two new model families.
Overview
Adds DeepSeek-V4.1-Flash and DeepSeek-V4.1-Flash-1017 to TRL’s bundled chat templates so
SFTTrainerwithassistant_only_loss=Truecan recognize these models and swap in patched templates at init.The PR stores reference Jinja templates for both checkpoints plus training variants that wrap assistant output (reasoning, content, tool calls, end-of-turn) in
{% generation %}/{% endgeneration %}. The V4.1-Flash training template also treats user messages that contain only tool results as not starting a new user turn, fixing prefix-preservation whendrop_thinkingwould otherwise re-render earlier assistant turns after tool append.Wiring includes
chat_template_utilslookup, pytest coverage on the tiny DeepSeek-V3 tokenizer, drift checks for both Hub repos, and docs/README updates listing the new family and training templates.Reviewed by Cursor Bugbot for commit ac15497. Bugbot is set up for automated code reviews on this repo. Configure here.