feat: add activation_offloading to GRPOTrainer and RLOOTrainer - #7143
Open
behroozazarkhalili wants to merge 4 commits into
Open
behroozazarkhalili wants to merge 4 commits into
behroozazarkhalili wants to merge 4 commits into
Conversation
8 tasks
|
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. |
…iner Wired the same way DPO and SFT do it: the offloading context manager is built right after super().__init__() and wraps training_step, with the init block byte-identical in both trainers and the config docstring and help matching the DPO/SFT one-liner. Based on huggingface#6621 with the review items from that PR applied. Fixes huggingface#3717.
behroozazarkhalili
force-pushed
the
reopen/6621
branch
from
September 9, 2026 17:25
6f96de4 to
59df916
Compare
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.
GRPO and RLOO lacked the activation offloading option available in DPO and SFT. I added
activation_offloadingto both configs and wrapped training steps to move activations to CPU during forward and retrieve them during backward. Lint, format, and documentation checks pass, and both trainer suites collect on CPU, but the new test requires the slow GPU lane.Fixes #3717.
Note
Medium Risk
Touches the core training loop for GRPO/RLOO; behavior only changes when the new flag is enabled, but offloading can affect memory, performance, and gradient correctness if the shared manager misbehaves on some setups.
Overview
Adds optional activation offloading to GRPO and RLOO training, matching the existing DPO/SFT pattern.
GRPOConfigandRLOOConfiggainactivation_offloading(defaultFalse). When enabled, each trainer buildsget_act_offloading_ctx_managerafter init and wrapssuper().training_step()so activations can be held on CPU during forward and restored for backward, reducing peak GPU memory at some compute cost.A new slow GPU parametrized test in
test_grpo_trainer.pyruns a short GRPO train withactivation_offloading=Trueand checks loss is logged and weights update.Reviewed by Cursor Bugbot for commit 280ad50. Bugbot is set up for automated code reviews on this repo. Configure here.