feat: add Gemma/Gemma2 training chat templates with generation markers#5523
Merged
Conversation
24 tasks
|
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. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes 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 b4e5485. Configure here.
5 tasks
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
{% generation %}markers for Gemma/Gemma2 training chat templates. Part of #5471.gemma.jinja: unmodified reference template (fromgoogle/gemma-7b-it).gemma_training.jinja: training variant. Split the unified output line into role-specific branches so<start_of_turn>model\nstays outside the generation block and assistant content +<end_of_turn>\ngoes inside.get_training_chat_templateto return the training variant.TestGetTrainingChatTemplateGemmaclass, parametrized over both tiny fixtures, asserting text equivalence vs the original and mask correctness across multi-turn conversations.One extra change worth flagging: reordered the
andin the no-patching-needed check so the substring check runs beforeis_chat_template_prefix_preserving. Gemma's template raisesTemplateErroron tool-role probes, and without the reorder the Gemma branch is unreachable. Happy to move this to a separate PR if preferred.Before submitting
{% generation %}chat templates for common model families #5471AI writing disclosure
Who can review?
@qgallouedec (created #5471)
Note
Medium Risk
Medium risk because it changes chat-template selection logic and tool-calling detection fallbacks, which can affect how prompts/masks are generated during training across multiple model families.
Overview
Adds Gemma/Gemma2 support to TRL’s chat-template patching by introducing a reference
gemma.jinjaand a newgemma_training.jinjathat wraps only the assistant-generated portion in{% generation %}markers (keeping<start_of_turn>model\noutside) for correctassistant_only_lossmasking.Updates
get_training_chat_template()to recognize Gemma templates and to skip prefix-preservation checks for templates that don’t support tool messages, and hardenssupports_tool_calling()with aTypeErrorfallback for templates that reject dict tool arguments (notably DeepSeek-V3). Tests and docs are adjusted accordingly (new Gemma/Gemma2 fixtures inTestGetTrainingChatTemplate, skips for tool-less templates, and removal of the DeepSeek tool-callingxfail).Reviewed by Cursor Bugbot for commit 1dad468. Bugbot is set up for automated code reviews on this repo. Configure here.