Add DeepSeek-R1-Distill chat template - #6766
Open
qgallouedec wants to merge 1 commit into
Open
Conversation
Adds the R1-Distill chat template (shared byte-identically by every distill checkpoint), a new-style response template that splits out reasoning_content, and a training variant with generation markers that keeps the reasoning in the SFT target.
|
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. |
qgallouedec
force-pushed
the
r1-distill-chat-template
branch
from
August 15, 2026 01:32
aa62a8e to
65edd5f
Compare
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.
Ports the R1-Distill chat template support from https://github.com/huggingface/trl-internal/pull/256, reworked to match how the other reasoning families are handled here.
deepseek_r1_distill.jinja— the template as shipped, byte-identical across every distill checkpoint (Qwen and Llama).deepseek_r1_distill_template— new-style response template only, like LFM2.5 and Gemma 4. Splits outreasoning_content(the internal version folded the whole<think>block intocontent); the start anchor consumes the prefilled<|Assistant|><think>\n, so a turn without a closing</think>parses as pure content. No tool calls: the template dropstool_callswhenevercontentis set, sosupports_tool_callingrejects it.deepseek_r1_distill_training.jinja— adds{% generation %}markers for SFT assistant-only loss, and stops splitting on</think>so the reasoning stays in the training target.trl-internal-testing/tiny-Qwen2ForCausalLM-R1-Distillfixture, added to the training-template and tool-calling suites.Note
Low Risk
Additive chat-template and test coverage only; no auth, data, or core training-path refactors beyond optional template swapping for matching tokenizers.
Overview
Adds first-class DeepSeek-R1-Distill support in TRL’s chat-template stack so SFT can keep reasoning in the loss and response parsing matches the prefilled
<|Assistant|><think>\nformat.Ships
deepseek_r1_distill.jinja(byte-identical to upstream distill checkpoints) anddeepseek_r1_distill_training.jinja, which drops the native</think>split on assistant content and wraps assistant output in{% generation %}markers.get_training_chat_templateandadd_response_schemarecognize the family via template identity and attachdeepseek_r1_distill_template(reasoning_content+content; no tool-call parsing). Tool calling is explicitly not supported (native template dropstool_callswhencontentis set).Docs/README list the family; tests cover
trl-internal-testing/tiny-Qwen2ForCausalLM-R1-Distillin training-template andsupports_tool_callingsuites, plus a script to build the tiny hub fixture fromDeepSeek-R1-Distill-Qwen-1.5B.Reviewed by Cursor Bugbot for commit 65edd5f. Bugbot is set up for automated code reviews on this repo. Configure here.