-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
🐦🔥 6x faster GRPO with multi-step optimization #2899
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. |
@@ -224,6 +228,14 @@ class GRPOConfig(TrainingArguments): | |||
"training speed." | |||
}, | |||
) | |||
num_iterations: int = field( | |||
default=1, |
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.
Should we set another default? eg 4?
trl/trainer/grpo_trainer.py
Outdated
@@ -638,6 +731,10 @@ def _prepare_inputs(self, inputs: dict[str, Union[torch.Tensor, Any]]) -> dict[s | |||
logits_to_keep = completion_ids.size(1) # we only need to compute the logits for the completion tokens | |||
|
|||
with torch.inference_mode(): | |||
old_per_token_logps = self._get_per_token_logps( |
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.
if num_iterations == 1
, I think we do a redundant forward pass here as the same thing will be recalculated at the optimization step. Would it be better to only calculate this if num_iterations > 1
, and then at the optimization step ?
For example:
if num_iterations==1:
old_per_token_logps = per_token_logps.detach()
else:
old_per_token_logps = inputs["old_per_token_logps"]
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.
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.
clearer when one realizes that the integers are the indices of the prompts! |
I'll add it, thanks for the feedback |
What does this PR do?
This PR implements the multi-step trick. It allows the generation to be reused several times, speeding up training.
It requires to implement the importance sampling and the clipping logic.
Results with various mu (note that mu=1 matches the current implementation in main):
For reproduction:
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines.
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.