Skip to content

Align KTO with DPO: Align F import with the rest of the repo#6246

Merged
qgallouedec merged 5 commits into
mainfrom
align-kto-dpo-imports
Jul 3, 2026
Merged

Align KTO with DPO: Align F import with the rest of the repo#6246
qgallouedec merged 5 commits into
mainfrom
align-kto-dpo-imports

Conversation

@qgallouedec

@qgallouedec qgallouedec commented Jul 2, 2026

Copy link
Copy Markdown
Member

Part of the effort to align KTOTrainer (experimental) with DPOTrainer. (#4786)

kto_trainer.py was the only file using from torch.nn import functional as F. Switched it to import torch.nn.functional as F, which is the convention used everywhere else (22 files). Import block now matches dpo_trainer.py.

No behavior change.


Note

Low Risk
Single-file import reorder with no logic or API changes.

Overview
As part of aligning experimental KTOTrainer with DPOTrainer, kto_trainer.py now imports F the same way as the rest of TRL: import torch.nn.functional as F next to import torch, instead of from torch.nn import functional as F lower in the import block.

This is import-only; F.sigmoid usage in KTO loss paths is unchanged.

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

@bot-ci-comment

bot-ci-comment Bot commented Jul 2, 2026

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 c92ba7b into main Jul 3, 2026
5 checks passed
@qgallouedec qgallouedec deleted the align-kto-dpo-imports branch July 3, 2026 16:17
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.

2 participants