Skip to content

Remove redundant is_peft_available from core trainers#5682

Merged
albertvillanova merged 6 commits into
mainfrom
simplify-is_peft_model
Apr 29, 2026
Merged

Remove redundant is_peft_available from core trainers#5682
albertvillanova merged 6 commits into
mainfrom
simplify-is_peft_model

Conversation

@albertvillanova

@albertvillanova albertvillanova commented Apr 29, 2026

Copy link
Copy Markdown
Member

Remove redundant is_peft_available from core trainers.

This PR simplifies the logic for checking PEFT (Parameter-Efficient Fine-Tuning) availability in several trainer classes. The main change is the removal of redundant is_peft_available() checks, relying solely on is_peft_model(model) to determine if PEFT-specific logic should be applied. This results in cleaner and more maintainable code across multiple trainers.

Trainer logic simplification:

  • Removed redundant is_peft_available() checks in favor of only using is_peft_model(model) when determining if PEFT-related operations (such as adding adapters or enabling input gradients) should be performed in DPOTrainer, GRPOTrainer, RLOOTrainer, RewardTrainer, and SFTTrainer.

Note

Low Risk
Small conditional-logic simplification around PEFT paths; behavior should be unchanged as long as is_peft_model() remains the single source of truth for PEFT detection.

Overview
Simplifies PEFT-specific control flow across DPOTrainer, GRPOTrainer, RLOOTrainer, RewardTrainer, and SFTTrainer by removing redundant is_peft_available() guards and keying PEFT behavior solely off is_peft_model(model).

This affects when trainers create a ref adapter for reference-policy comparisons and when they call enable_input_require_grads() under gradient checkpointing, without changing the underlying PEFT operations themselves.

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

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7f89777. Configure here.

Comment thread trl/trainer/dpo_trainer.py
@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 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.

lgtm

@albertvillanova albertvillanova merged commit 95719e2 into main Apr 29, 2026
7 of 13 checks passed
@albertvillanova albertvillanova deleted the simplify-is_peft_model branch April 29, 2026 15:44
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.

3 participants