Skip to content

Fix GRPO profiling #2522

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
merged 3 commits into from
Apr 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions recipes/dev/grpo_full_finetune_distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ def _setup_profiler(
self.profiler_wait_steps = profiler_cfg["wait_steps"]
self.profiler_warmup_steps = profiler_cfg["warmup_steps"]
self.profiler_active_steps = profiler_cfg["active_steps"]
self.profiler_num_cycles = profiler_cfg["num_cycles"]

return profiler

Expand Down Expand Up @@ -949,6 +950,7 @@ def train(self) -> None:
and curr_epoch == 0
and self.profiler_profile_memory
and idx == self.profiler_wait_steps + self.profiler_warmup_steps
and self._device.type == "cuda"
):
torch.cuda.memory._record_memory_history()

Expand Down Expand Up @@ -983,6 +985,19 @@ def train(self) -> None:
if self._lr_scheduler is not None:
self._lr_scheduler.step()

# Stop tracking CUDA memory now that active steps are complete
if (
self._is_rank_zero
and curr_epoch == 0
and self.profiler_profile_memory
and idx
== self.profiler_wait_steps
+ self.profiler_warmup_steps
+ self.profiler_active_steps
and self._device.type == "cuda"
):
torch.cuda.memory._record_memory_history(enabled=None)

self._steps_run += 1
if self._steps_run % self._log_every_n_steps == 0:
extra_metrics = {}
Expand All @@ -997,6 +1012,8 @@ def train(self) -> None:
)

self.cleanup_after_step(trajectory, grpo_stats)
self._profiler.step()

pbar.update(1)

if self._steps_run == self._total_steps:
Expand Down