Skip to content

Add DeepSeek-R1-Distill chat template - #6766

Open
qgallouedec wants to merge 1 commit into
mainfrom
r1-distill-chat-template
Open

Add DeepSeek-R1-Distill chat template#6766
qgallouedec wants to merge 1 commit into
mainfrom
r1-distill-chat-template

Conversation

@qgallouedec

@qgallouedec qgallouedec commented Aug 15, 2026

Copy link
Copy Markdown
Member

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 out reasoning_content (the internal version folded the whole <think> block into content); 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 drops tool_calls whenever content is set, so supports_tool_calling rejects 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.
  • Tests: new trl-internal-testing/tiny-Qwen2ForCausalLM-R1-Distill fixture, 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>\n format.

Ships deepseek_r1_distill.jinja (byte-identical to upstream distill checkpoints) and deepseek_r1_distill_training.jinja, which drops the native </think> split on assistant content and wraps assistant output in {% generation %} markers. get_training_chat_template and add_response_schema recognize the family via template identity and attach deepseek_r1_distill_template (reasoning_content + content; no tool-call parsing). Tool calling is explicitly not supported (native template drops tool_calls when content is set).

Docs/README list the family; tests cover trl-internal-testing/tiny-Qwen2ForCausalLM-R1-Distill in training-template and supports_tool_calling suites, plus a script to build the tiny hub fixture from DeepSeek-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.

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.
@bot-ci-comment

Copy link
Copy Markdown

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
qgallouedec force-pushed the r1-distill-chat-template branch from aa62a8e to 65edd5f Compare August 15, 2026 01:32

@AmineDiro AmineDiro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition 👍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants