Skip to content

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

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

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

Conversation

@qgallouedec
Copy link
Copy Markdown
Member

@qgallouedec qgallouedec commented Apr 5, 2026

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.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

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".

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

Copy link
Copy Markdown

@cursor cursor bot left a comment

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.

Copy link
Copy Markdown
Member

@albertvillanova albertvillanova left a comment

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