Repository navigation
feat: add OLMo 3 training chat template with generation markers - #6690
Closed
RudrenduPaul wants to merge 1 commit into
Closed
RudrenduPaul wants to merge 1 commit into
RudrenduPaul wants to merge 1 commit into
Conversation
Adds trl/chat_templates/olmo3.jinja and olmo3_training.jinja so
get_training_chat_template() supports OLMo 3, wrapping assistant output
in {% generation %} / {% endgeneration %} markers for assistant-only
loss masking in SFT. Reuses the existing tiny-Olmo3ForCausalLM test
fixture from huggingface#5962.
5 of 6 tasks
19 of 41 tasks
Member
|
Thanks. OLMo 3 checkpoints ship 6 different chat templates, and this covers one of them (7B-Think, not the most used 7B-Instruct). It also puts in the loss the |
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-compatible variant of the OLMo 3 chat template with
{% generation %}/{% endgeneration %}markers, enablingreturn_assistant_tokens_mask=Truefor assistant-only loss masking in SFT training.OLMo 3 isn't in the family list originally tracked by #5471 (now closed), so this fills a gap that was left out of that sweep — the model's native chat template has no
{% generation %}markers andget_training_chat_template()currently raises for it.Files changed:
trl/chat_templates/olmo3.jinja— original OLMo 3 chat template (source of truth for the exact-match comparison inget_training_chat_template())trl/chat_templates/olmo3_training.jinja— training variant: same text output as the original, with{% generation %}/{% endgeneration %}wrapping the assistant output (content,function_calls, and the<|im_end|>/eos_tokenterminator)trl/chat_template_utils.py— loads both templates; adds an OLMo 3 branch toget_training_chat_template(); updates the docstringtests/test_chat_template_utils.py— addstrl-internal-testing/tiny-Olmo3ForCausalLM(the fixture from Add testing for Olmo3 #5962) toTestGetTrainingChatTemplate's parametrize list, gated ontransformers>=4.57.0to match its existing skip condition elsewhere in the filetrl/chat_templates/README.md,docs/source/chat_templates.md— document the new template pairTemplate design: OLMo 3 uses a bespoke function-calling schema (
functions/function_callsfields plus anenvironmentrole) instead of the standardtools/tool_calls/toolinterface, sosupports_tool_calling()isFalsefor it andget_training_chat_template()does not require prefix-preservation. Only the{% generation %}markers were needed — no structural prefix-preservation fix, matching the same reasoning already applied to Llama 3 and the Nemotron 3 family.Testing:
pytest tests/test_chat_template_utils.py -k olmo3→ 12 passed, 2 skipped (skips are the tool-calling-specific assertions, correctly skipped since OLMo 3 doesn't support standard tool calling). Full file:pytest tests/test_chat_template_utils.py→ 359 passed, 226 skipped, 0 failed.Before submitting
{% generation %}chat templates for common model families #5471 (closed; OLMo 3 was not in its tracked family list)AI writing disclosure
AI-assisted: Claude Code helped draft the training-template diff and test wiring, following the same pattern as my earlier merged PRs (#5493, #5522, #5526, #5527) for this repo. I reviewed and verified the change myself before submitting.
Who can review?
@qgallouedec
Note
Low Risk
Additive template wiring and tests only; no changes to training loops, auth, or shared inference paths beyond optional template swap at init.
Overview
Adds OLMo 3 to TRL’s supported chat-template families so SFT with
assistant_only_loss=Trueno longer fails onallenai/Olmo-3-*tokenizers.New
olmo3.jinja(reference copy for exact-match detection) andolmo3_training.jinja, which wraps assistantcontent,function_calls, and the turn terminator in{% generation %}/{% endgeneration %}without changing rendered text.get_training_chat_template()loads both and returns the training variant when the tokenizer template matches the reference.Docs and
TestGetTrainingChatTemplategain OLMo 3 (tiny-Olmo3ForCausalLM,transformers>=4.57.0). No prefix-preservation patch: Olmo 3’s customfunctions/function_callsschema is outside standard tool calling, so GRPO-style prefix checks do not apply.Reviewed by Cursor Bugbot for commit 3e39de2. Bugbot is set up for automated code reviews on this repo. Configure here.