Skip to content

feat(sft): make only_unmask_final configurable in SFTConfig#2268

Open
Ai-chan-0411 wants to merge 1 commit intoNVIDIA-NeMo:mainfrom
Ai-chan-0411:feat/configurable-only-unmask-final
Open

feat(sft): make only_unmask_final configurable in SFTConfig#2268
Ai-chan-0411 wants to merge 1 commit intoNVIDIA-NeMo:mainfrom
Ai-chan-0411:feat/configurable-only-unmask-final

Conversation

@Ai-chan-0411
Copy link
Copy Markdown

Context

While working on a multi-turn SFT setup, I noticed that add_loss_mask_to_message_log already supports an only_unmask_final parameter (which masks all messages except the last one), but there was no way to set it through the SFT configuration — it was hardcoded to False at both call sites in sft.py.

This came up when trying to train on only the final assistant response in a multi-turn conversation, which is a common pattern for instruction-following tasks where prior turns serve as context.

Changes

  • Added only_unmask_final: bool field to SFTConfig TypedDict
  • Wired the config value through to add_loss_mask_to_message_log in both validate() and sft_train()
  • Added only_unmask_final: false to the base sft.yaml config (other configs inherit this default)

The default is false, so existing behavior is unchanged. Setting it to true causes only the final message in each conversation to be unmasked for loss computation, regardless of role.

Closes #2219

For multi-turn SFT tasks where only the final assistant response
should be trained on, the only_unmask_final flag in
add_loss_mask_to_message_log was not accessible through SFTConfig.

Add only_unmask_final as a configurable boolean in SFTConfig and
wire it through to both training and validation loss mask calls.
Defaults to false to preserve existing behavior.

Closes NVIDIA-NeMo#2219

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Ai-chan-0411 Ai-chan-0411 requested a review from a team as a code owner April 15, 2026 03:35
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot bot commented Apr 15, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make only_unmask_final flag configurable for SFT.

2 participants