Skip to content

[docs] Add chat templates page to web docs#5581

Merged
qgallouedec merged 10 commits into
mainfrom
docs/chat-templates-web
Apr 20, 2026
Merged

[docs] Add chat templates page to web docs#5581
qgallouedec merged 10 commits into
mainfrom
docs/chat-templates-web

Conversation

@sergiopaniego

@sergiopaniego sergiopaniego commented Apr 17, 2026

Copy link
Copy Markdown
Member

What does this PR do?

Follow-up to #5545, adding the content to the web docs

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline, Pull Request section?
  • Was this discussed/approved via a GitHub issue? Please add a link to it if that's the case.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

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?

@albertvillanova @qgallouedec


Note

Low Risk
Documentation-only changes (new page, navigation entry, and links) with no runtime or API impact.

Overview
Adds a new Chat Templates conceptual guide documenting TRL’s bundled/patched training chat templates (prefix-preserving + generation markers) and which model families are supported.

Wires the page into the docs nav (_toctree.yml) and adds cross-references from chat_template_utils.md, plus contextual notes in grpo_trainer.md (tools require prefix-preserving templates) and sft_trainer.md (assistant-only loss requires generation markers and points to the bundled template list).

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

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

@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! Just a small suggestion due to recent code changes...

Comment thread docs/source/chat_templates.md Outdated
Co-authored-by: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com>
Comment thread docs/source/chat_template_utils.md Outdated
Comment thread docs/source/grpo_trainer.md Outdated
Comment thread docs/source/chat_templates.md Outdated

TRL ships a small collection of Jinja2 chat templates under [`trl/chat_templates/`](https://github.com/huggingface/trl/tree/main/trl/chat_templates). They serve two purposes:

1. **Identity comparison**: detecting which model is being used (by comparing `processing_class.chat_template` against known templates) to add the appropriate response schema ([`add_response_schema`]) or swap in a training template ([`get_training_chat_template`]).

@qgallouedec qgallouedec Apr 17, 2026

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.

- ([`add_response_schema`])
+ (`add_response_schema`)

now that it's not in the doc anymore

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!

I'd suggest a few modifications, flagging the rationale:

Reading the original intro cold, I felt it opened mid-thought: it jumped straight into "they serve two purposes: identity comparison and training patches", which is framed from the implementer's side (ie, why these files exist internally) rather than the reader's (=user) side: "why do I, a TRL user, care?". I reworked it along this arc:

  • Define what a chat template is (+ link to transformers docs, tiny apply_chat_template example).
  • Reassure: most users never touch them; TRL handles it transparently.
  • Motivate the page with the two user-facing scenarios (SFT -assistant_only_loss=True`, GRPO tool calls).
  • Say what to do: TRL auto-patches supported families; for others, you patch yourself.

Collapsed "Original templates" into "Supported model families". The per-file stubs ("Original Qwen3 chat template.", ...) weren't user-facing: those originals exist for TRL's internal identity-comparison; a user would never use them directly -> collapsed to a one-line family list

Comment thread docs/source/chat_templates.md Outdated
Comment thread docs/source/chat_templates.md Outdated
sergiopaniego and others added 5 commits April 17, 2026 18:16
Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com>
Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com>
Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com>
@qgallouedec qgallouedec merged commit 1d9b612 into main Apr 20, 2026
3 checks passed
@qgallouedec qgallouedec deleted the docs/chat-templates-web branch April 20, 2026 15:15
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.

4 participants