Skip to content

[BugFix] Fix cuda cache empty in GRPO scripts #3016

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 2 commits into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions sota-implementations/grpo/grpo-async.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ def train(
with timeit("update_policy_weights"):
torchrl_logger.info("Updating policy weights...")
weight_updater.push_weights(policy_training)
torch.cuda.empty_cache()
# TODO: do we need this? Does it interfere with other processes?
# torch.cuda.empty_cache()
gc.collect()

# Checkpointing disabled to prevent disk space issues
Expand All @@ -380,7 +381,8 @@ def train(

# Clear memory
del loss_val
torch.cuda.empty_cache()
# TODO: do we need this? Does it interfere with other processes?
# torch.cuda.empty_cache()
gc.collect()

pbar.close()
Expand Down
6 changes: 4 additions & 2 deletions sota-implementations/grpo/grpo-sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ def train(

# Clear memory
del loss_val
torch.cuda.empty_cache()
# TODO: do we need this? Does it interfere with other processes?
# torch.cuda.empty_cache()
gc.collect()

# Update metrics
Expand Down Expand Up @@ -387,7 +388,8 @@ def train(
with timeit("update_policy_weights"):
torchrl_logger.info("Updating policy weights...")
weight_updater.push_weights(policy_training)
torch.cuda.empty_cache()
# TODO: do we need this? Does it interfere with other processes?
# torch.cuda.empty_cache()
gc.collect()

timeit.print(prefix="timeit")
Expand Down
2 changes: 2 additions & 0 deletions torchrl/collectors/llm/ray_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class RayLLMCollector(LLMCollector):
>>> for data in collector: # non-blocking
... # expensive operation - collector is collecting data

This is somehwat equivalent to using :class:`~torchrl.collectors.MultiSyncDataCollector` (`sync_iter=True`) or
:class:`~torchrl.collectors.MultiAsyncDataCollector` (`sync_iter=False`).
Defaults to `True`.
verbose (bool, optional): if ``True``, the collector will print progress information.
Defaults to `False`.
Expand Down
Loading