Skip to content

feat: add activation_offloading to GRPOTrainer and RLOOTrainer - #7143

Open
behroozazarkhalili wants to merge 4 commits into
huggingface:mainfrom
behroozazarkhalili:reopen/6621
Open

behroozazarkhalili wants to merge 4 commits into
huggingface:mainfrom
behroozazarkhalili:reopen/6621

Conversation

@behroozazarkhalili

@behroozazarkhalili behroozazarkhalili commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

GRPO and RLOO lacked the activation offloading option available in DPO and SFT. I added activation_offloading to 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.

GRPOConfig and RLOOConfig gain activation_offloading (default False). When enabled, each trainer builds get_act_offloading_ctx_manager after init and wraps super().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.py runs a short GRPO train with activation_offloading=True and 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.

@bot-ci-comment

bot-ci-comment Bot commented Sep 9, 2026

Copy link
Copy Markdown

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add activation checkpointing to DPO and GRPO

1 participant