generated from fastai/nbdev_template
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[GRPO]: Sample from a Replay Buffer To Substitute Groups with 0 std. #4060
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
Merged
pramodith
merged 24 commits into
huggingface:main
from
pramodith:pramodith/grpo_replay_buffer
Sep 24, 2025
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
b34330c
Skeleton of what using a replay buffer would look like.
pramodith 2d8f491
Add tests
pramodith 8500784
Refactor tests.
pramodith 8593e26
minor refactor
pramodith 4fa6216
nit
pramodith cee65dd
Account for different sequence lengths.
pramodith 7c835b4
Merge branch 'main' into pramodith/grpo_replay_buffer
pramodith 1139182
Unpad buffer tensors to max seq len in group.
pramodith 1c759e9
pad_token_id
pramodith 2bfad0b
Refactor
pramodith cdcde4f
fix test case
pramodith da692b1
move to experimental
pramodith 16f74a5
precommit
pramodith d50cafd
Update docs
pramodith 50ccffb
revert
pramodith 43f1973
update docs
pramodith 0dba161
Merge branch 'main' into pramodith/grpo_replay_buffer
pramodith d325f9e
fix typing
pramodith 8cb3d4e
fix test
pramodith 7501d8f
Merge branch 'main' into pramodith/grpo_replay_buffer
pramodith c99cae1
nits and low prio tests
qgallouedec 195c2c9
Merge branch 'main' into pramodith/grpo_replay_buffer
qgallouedec d68dc02
style
qgallouedec 12b8a28
Merge branch 'main' into pramodith/grpo_replay_buffer
pramodith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright 2020-2025 The HuggingFace Team. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from .grpo_with_replay_buffer_config import GRPOWithReplayBufferConfig | ||
from .grpo_with_replay_buffer_trainer import GRPOWithReplayBufferTrainer, ReplayBuffer |
34 changes: 34 additions & 0 deletions
34
trl/experimental/grpo_with_replay_buffer/grpo_with_replay_buffer_config.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright 2020-2025 The HuggingFace Team. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from dataclasses import dataclass, field | ||
|
||
from trl.trainer.grpo_config import GRPOConfig | ||
|
||
|
||
@dataclass | ||
class GRPOWithReplayBufferConfig(GRPOConfig): | ||
""" | ||
New Parameters: | ||
replay_buffer_size (`int`, *optional*, defaults to `0`): | ||
A cache that stores the rollouts with the highest advantage scores and variance per group. If a new | ||
group has 0 variance, it is replaced with a group sampled from the replay buffer. | ||
""" | ||
|
||
replay_buffer_size: int = field( | ||
default=64, | ||
metadata={ | ||
"help": "A cache that stores the rollouts with the highest advantage scores and variance per group. If a new group has 0 variance, it is replaced with a group sampled from the replay buffer." | ||
}, | ||
) |
Oops, something went wrong.
Oops, something went wrong.
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.
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.