Add Idefics3 original and training chat template with generation markers#5871
Open
aazizyan wants to merge 2 commits into
Open
Add Idefics3 original and training chat template with generation markers#5871aazizyan wants to merge 2 commits into
aazizyan wants to merge 2 commits into
Conversation
qgallouedec
reviewed
May 27, 2026
Member
qgallouedec
left a comment
There was a problem hiding this comment.
thanks, can you ensure we keep an alphabetical ordering?
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b91d52d. Configure here.
b91d52d to
6da6491
Compare
Contributor
Author
|
done |
6da6491 to
3d4c468
Compare
3d4c468 to
311f0a8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What does this PR do?
Adds a training chat template for Idefics3, wiring it into
get_training_chat_template.The new template patches
idefics3.jinjawith a single modification: split the assistant message into its own branch so the{% generation %}/{% endgeneration %}markers wrap the assistant content (everything after theAssistant:prompt cue, up to and including the trailing<end_of_utterance>\n). The vision-content rendering inside the assistant branch is duplicated from the original non-assistant branch unchanged. This enablesreturn_assistant_tokens_mask=Trueto produce correct masks for SFT assistant-only loss.Idefics3 does not ship tool-calling support, so no prefix-preservation changes are needed.
Changes
trl/chat_templates/:idefics3.jinja– new original templateidefics3_training.jinja– new training templatetrl/chat_template_utils.py:idefics3_chat_template, used for identity comparison.get_training_chat_template()mapping the source template to its training variant.tests/test_chat_template_utils.py— one new entry inTestGetTrainingChatTemplate's parametrize block (idefics3).Docs — Idefics3 added to the supported-families list, training-template section added in:
docs/source/chat_templates.mdtrl/chat_templates/README.mdPart of #5471
cc: @qgallouedec
Note
Low Risk
Template-only addition following existing VLM patterns; no auth, data, or core training logic changes beyond automatic template swap for matching tokenizers.
Overview
Adds Idefics3 to TRL’s bundled chat-template support so SFT with
assistant_only_loss=Truecan use correct assistant token masks on multimodal Idefics3 checkpoints.New
idefics3.jinjaandidefics3_training.jinjamirror the shipped format (role lines, text/image blocks,<end_of_utterance>). The training template gives assistant turns their own branch and wraps assistant output in{% generation %}/{% endgeneration %}(after theAssistant:cue). No tool-calling or prefix-preservation changes.get_training_chat_templatemaps the reference template to the training variant; docs list Idefics3 as supported;TestGetTrainingChatTemplategains anidefics3parametrize case.Reviewed by Cursor Bugbot for commit 311f0a8. Bugbot is set up for automated code reviews on this repo. Configure here.