Skip to content

Move chat templates from inline strings to .jinja files#5459

Merged
qgallouedec merged 18 commits into
mainfrom
chat-templates-files
Apr 8, 2026
Merged

Move chat templates from inline strings to .jinja files#5459
qgallouedec merged 18 commits into
mainfrom
chat-templates-files

Conversation

@qgallouedec

@qgallouedec qgallouedec commented Apr 5, 2026

Copy link
Copy Markdown
Member

Moves the four inline Jinja2 chat template strings from chat_template_utils.py into separate .jinja files under trl/chat_templates/, with a README explaining their purpose and the training template diffs.

These templates are large (up to ~8K chars) and make chat_template_utils.py hard to navigate. Storing them as .jinja files makes them easier to read, diff, and edit and enables syntax highlighting in editors.

Requires #5458


Note

Medium Risk
Moderate risk because trl.chat_template_utils now reads template text from package files at import time; missing/incorrectly packaged template files would break schema detection and training template patching for Qwen models.

Overview
Moves the Qwen3/Qwen3.5 Jinja2 chat templates out of chat_template_utils.py into standalone files under trl/chat_templates/, and updates the Python constants to load them via Path(...).read_text().

Adds trl/chat_templates/README.md documenting the identity-comparison vs training-patch templates, and updates MANIFEST.in to include the new .jinja and .md template assets in source distributions.

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

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 08d4c518ec

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread trl/chat_template_utils.py
Comment thread trl/chat_template_utils.py
Comment thread trl/chat_template_utils.py
@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.

Comment thread trl/trainer/grpo_trainer.py
Comment thread trl/experimental/async_grpo/async_rollout_worker.py Outdated

@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 a0b81b1. Configure here.

Comment thread trl/experimental/async_grpo/async_rollout_worker.py

@albertvillanova albertvillanova 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.

Thanks.

@qgallouedec qgallouedec merged commit f44cf20 into main Apr 8, 2026
13 of 14 checks passed
@qgallouedec qgallouedec deleted the chat-templates-files branch April 8, 2026 12:31
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