-
Notifications
You must be signed in to change notification settings - Fork 2.1k
👎 [GRPO] Adds option to disable dropout #3234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice feature - LGTM.
trl/trainer/grpo_trainer.py
Outdated
@@ -359,6 +366,10 @@ def __init__( | |||
reward_funcs[i] = AutoModelForSequenceClassification.from_pretrained( | |||
reward_func, num_labels=1, **model_init_kwargs | |||
) | |||
if args.disable_dropout: | |||
if isinstance(reward_funcs[i], nn.Module): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think AutoModelForSequenceClassification
is loaded in eval model by default, so technically we don't need this here (happy to keep it though if we want to be safe)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed!
>>> from transformers import AutoModelForSequenceClassification
>>> model = AutoModelForSequenceClassification.from_pretrained("trl-lib/Qwen2-0.5B-Reward", num_labels=1)
>>> model.training
False
trl/trainer/grpo_config.py
Outdated
@@ -101,6 +101,9 @@ class GRPOConfig(TrainingArguments): | |||
speed, but may be numerically unstable for long training runs. | |||
num_iterations (`int`, *optional*, defaults to `1`): | |||
Number of iterations per batch (denoted as μ in the algorithm). | |||
disable_dropout (`bool`, *optional*, defaults to `False`): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the other trainers this is set to True
, maybe we should do the same here?
trl/trainer/grpo_trainer.py
Outdated
if args.disable_dropout: | ||
if isinstance(model, nn.Module): | ||
disable_dropout_in_model(model) | ||
if self.ref_model is not None and isinstance(self.ref_model, nn.Module): | ||
disable_dropout_in_model(self.ref_model) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we only support PreTrainedModel
, which are nn.Module
(what else could it be?)
if args.disable_dropout: | |
if isinstance(model, nn.Module): | |
disable_dropout_in_model(model) | |
if self.ref_model is not None and isinstance(self.ref_model, nn.Module): | |
disable_dropout_in_model(self.ref_model) | |
if args.disable_dropout: | |
disable_dropout_in_model(model) | |
if self.ref_model is not None: | |
disable_dropout_in_model(self.ref_model) | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, in the future we could use a default to True (let's see if it improve stability)
Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com> Co-authored-by: Quentin Gallouédec <gallouedec.quentin@gmail.com>
What does this PR do?
Adds an option to disable dropout.
The RLOOTrainer disables dropout in policy, ref_model and reward model. This PR adds the option to disable dropout to the GRPOTrainer, which may improve training stability.
The N+ Implementation Details of RLHF with PPO: A Case Study on TL;DR Summarization
Provides more insight about why this option may improve training stability: