Skip to content

[docs] Add code example for completion_only_loss in SFT trainer docs - #5494

Merged
qgallouedec merged 1 commit into
huggingface:mainfrom
RudrenduPaul:docs/sft-completion-only-loss-example
Apr 10, 2026
Merged

qgallouedec merged 1 commit into
huggingface:mainfrom
RudrenduPaul:docs/sft-completion-only-loss-example

Conversation

@RudrenduPaul

@RudrenduPaul RudrenduPaul commented Apr 9, 2026 •

Copy link
Copy Markdown
Contributor

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.md documentation that shows:

  • How to load a prompt-completion dataset (trl-lib/kto-mix-14k)
  • How to pass completion_only_loss=True to SFTConfig
  • A comment clarifying that True is the default for prompt-completion datasets

Fixes #5324

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline, Pull Request section?
  • Was this discussed/approved via a GitHub issue? Please add a link to it if that's the case.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

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.

  • No AI usage: the PR was written entirely by a human.
  • AI-assisted: some parts were suggested or improved by AI, but the PR was written and reviewed by a human.
  • AI-generated: the PR was mostly or fully generated by an AI tool.

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 only section of sft_trainer.md, showing how to load a prompt-completion dataset and configure SFTConfig(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.

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

@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.

ok looks good

@HuggingFaceDocBuilderDev

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.

@qgallouedec
qgallouedec merged commit b48c788 into huggingface:main Apr 10, 2026
3 checks passed
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.

completion_only_loss

3 participants