Repository navigation
[docs] Add code example for completion_only_loss in SFT trainer docs - #5494
Merged
qgallouedec merged 1 commit intoApr 10, 2026
Merged
qgallouedec merged 1 commit into
qgallouedec merged 1 commit into
Conversation
The "Train on completion only" section in the SFT trainer documentation lacked a concrete code example, causing user confusion (see issue huggingface#5324). Added a minimal working example showing how to use a prompt-completion dataset with completion_only_loss=True, clarifying it is the default behavior for prompt-completion datasets. Built by Rudrendu Paul, developed with Claude Code
|
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. |
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?
The "Train on completion only" section in the SFT trainer documentation lacked a concrete code example, leaving users without a clear template for how to set up prompt-completion training with
completion_only_loss=True. This led to confusion, as reported in issue #5324, where users did not know what dataset format to use.This PR adds a minimal working example to the
sft_trainer.mddocumentation that shows:trl-lib/kto-mix-14k)completion_only_loss=TruetoSFTConfigTrueis the default for prompt-completion datasetsFixes #5324
Before submitting
AI writing disclosure
We welcome the use of AI tools to help with contributions. For transparency and to help us improve our review process, please indicate the level of AI involvement in this PR.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag members/contributors who may be interested in your PR.
@qgallouedec
Note
Low Risk
Low risk documentation-only change that adds an example snippet; no runtime or API behavior is modified.
Overview
Adds a concrete Python example to the
Train on completion onlysection ofsft_trainer.md, showing how to load a prompt-completion dataset and configureSFTConfig(completion_only_loss=True)(noting it’s the default for prompt-completion datasets).Reviewed by Cursor Bugbot for commit 4990891. Bugbot is set up for automated code reviews on this repo. Configure here.