Skip to content

feat: add Phi-3.5 training chat templates with generation markers#5746

Merged
qgallouedec merged 6 commits into
huggingface:mainfrom
DagaBhai:add-phi35-generation-marker
May 11, 2026
Merged

feat: add Phi-3.5 training chat templates with generation markers#5746
qgallouedec merged 6 commits into
huggingface:mainfrom
DagaBhai:add-phi35-generation-marker

Conversation

@DagaBhai

@DagaBhai DagaBhai commented May 10, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

contributing to #5471

Adds a training-compatible variant of the Phi-3.5 chat template with {% generation %} / {% endgeneration %} markers, enabling return_assistant_tokens_mask=True for assistant-only loss masking in SFT training.

-phi3_5.jinja: template from microsoft/Phi-3.5-mini-instruct
-phi3_5_training.jinja: modified the phi3_5.jinja to turn the training chat template
-get_training_chat_template: registered Phi-3.5
-tests/test_chat_template_utils.py: added param "trl-internal-testing/tiny-Phi3ForCausalLM-3.5", id="phi3.5"

Before submitting

AI writing disclosure

We welcome the use of AI tools to help with contributions. For transparency and to help us improve our review process, please indicate the level of AI involvement in this PR.

  • No AI usage: the PR was written entirely by a human.
  • AI-assisted: some parts were suggested or improved by AI, but the PR was written and reviewed by a human.
  • AI-generated: the PR was mostly or fully generated by an AI tool.

Who can review?

@qgallouedec (opened #5471)


Note

Low Risk
Low risk: additive support for a new model family template plus a small conditional in get_training_chat_template, with coverage via existing template utility tests.

Overview
Adds Phi-3.5 to TRL’s recognized chat-template families and introduces phi3_5.jinja plus a training variant phi3_5_training.jinja that wraps assistant output in {% generation %} / {% endgeneration %} for assistant-only loss masking.

Registers the new Phi-3.5 templates in get_training_chat_template, updates docs/README to list the new family and training template, and extends test_chat_template_utils.py to exercise the Phi-3.5 tiny model in the existing training-template test matrix.

Reviewed by Cursor Bugbot for commit 22c1909. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 1f26dea. Configure here.

Comment thread trl/chat_templates/phi3_5_training.jinja
@HuggingFaceDocBuilderDev

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 merged commit 5f9a2f3 into huggingface:main May 11, 2026
1 check passed
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.

3 participants