Simplify reference model handling in GRPO/RLOO#5877
Open
albertvillanova wants to merge 6 commits into
Open
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit e4d9e39. Configure here.
|
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.

Simplify reference model handling in GRPO/RLOO.
Follow-up to:
This PR refactors how reference models are handled in both
GRPOTrainerandRLOOTrainer, especially to improve support for PEFT (Parameter-Efficient Fine-Tuning) adapters. The main changes clarify and centralize the logic for reference model selection and usage, ensuring consistent behavior across different training setups.Changes
Reference model handling improvements:
Refactored the initialization of
self.ref_modelin bothgrpo_trainer.pyandrloo_trainer.pyto:ref_modelvariable during setup.self.ref_modelat the end based on whetherbetais zero, if PEFT is used, or if a reference model needs to be instantiated. This ensures that for PEFT, the base model is used as reference by disabling adapters, and for non-PEFT, an explicit reference model is created if needed.Updated all downstream usages to reference the new logic, including dropout disabling, model preparation (e.g., DeepSpeed/FSDP), and callbacks for syncing the reference model.
PEFT adapter support and scoring logic:
_generate_and_score_completionsto explicitly check for PEFT models and correctly switch adapters when computing reference log probabilities, covering both new and retrained adapters.These changes make the code more robust and maintainable when working with different model types and distributed training setups, and clarify how the reference model is selected and used throughout training.
Note
Medium Risk
Changes which module runs reference KL forwards (PEFT now consistently uses
self.ref_modelwith adapter switching) and when a duplicate ref weights copy is loaded; incorrect assignment would skew KL-regularized RL training.Overview
GRPO and RLOO trainers now build a separate reference checkpoint only when
beta != 0and the policy is not PEFT; setup uses a temporaryref_modelfor dropout, fp32 LM-head casting, and DeepSpeed/FSDP prep, then setsself.ref_modelin one place:Noneif KL is off, else the prepared duplicate orself.modelfor adapter-based reference.Reference log-probs no longer branch on
self.ref_model is not Nonevs PEFT. They useis_peft_model(self.ref_model)to runuse_adapterand forward throughself.ref_model(aligned with the training module for PEFT), with a single non-PEFT path that always calls the dedicated or policy model viaself.ref_model.Reviewed by Cursor Bugbot for commit 0e267aa. Bugbot is set up for automated code reviews on this repo. Configure here.