Skip to content

Keep the pre-filled thinking block out of the Nemotron 3 assistant-only loss - #8217

Merged
albertvillanova merged 1 commit into
mainfrom
nemotron3-training-think-prefill
Nov 12, 2026
Merged

albertvillanova merged 1 commit into
mainfrom
nemotron3-training-think-prefill

Conversation

@albertvillanova

@albertvillanova albertvillanova commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

This PR stops the Nemotron 3 training templates from training the part of the thinking block that the generation prompt already ends with (<think>\n, or <think></think> with enable_thinking=False).

Fix #8216.
Part of #8109.

Solution

Render the assistant turn first, then emit what the generation prompt pre-fills just before the {% generation %} block when the turn starts with it, and the rest inside. The rendered text is unchanged: only the assistant mask changes.

Changes

  • Move the pre-filled part of the thinking block out of the generation block in nemotron_3_nano_training.jinja, nemotron_3_super_training.jinja, nemotron_3_ultra_training.jinja and nemotron_3_5_lightning_training.jinja.
  • Remove Nemotron 3 from the strict xfails of test_assistant_masks_exclude_generation_prompt and test_assistant_masks_exclude_generation_prompt_without_reasoning.
  • Document the placement in the chat templates README and docs.

Note

Medium Risk
Changes which tokens get gradient during Nemotron 3 SFT; incorrect masking would skew training, but scope is limited to training templates and mask boundaries.

Overview
Updates Nemotron 3 training chat templates (Nano, Super, Ultra, 3.5 Lightning) so SFT with assistant_only_loss does not apply loss on tokens the generation prompt already pre-fills at the start of the thinking block (<think>\n, or empty <think></think> when enable_thinking=False).

Each template now builds the assistant turn as a string, prints the matching prefill outside {% generation %}, and wraps only the remainder in {% generation %} — rendered text stays the same; only assistant token masks change. Nemotron 3 entries are removed from the strict xfails on test_assistant_masks_exclude_generation_prompt* in tests/test_chat_template_utils.py, and the chat template docs/README describe this placement.

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

@bot-ci-comment

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.

Pages changed in this PR:

@qgallouedec qgallouedec 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, checked on my side.

@albertvillanova
albertvillanova merged commit df64ea5 into main Nov 12, 2026
14 checks passed
@albertvillanova
albertvillanova deleted the nemotron3-training-think-prefill branch November 12, 2026 10:14
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.

SFT with assistant_only_loss trains the pre-filled thinking block on Nemotron 3

2 participants