Skip to content

feat(grpo): checkpoint async replay buffer - #2632

Closed
macandro96 wants to merge 3 commits into
mainfrom
amahishi/replay-buffer-checkpointing
Closed

macandro96 wants to merge 3 commits into
mainfrom
amahishi/replay-buffer-checkpointing

Conversation

@macandro96

@macandro96 macandro96 commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do ?

Adds replay-buffer checkpointing via state_dict()/load_state_dict(), saved as replay_buffer.pt alongside the dataloader state and restored on resume.

Issues

Closes Allow replay buffer checkpointing and reloading capability part of #1906

Usage

  • You can potentially add a usage example below
# Add a code snippet demonstrating how to use this

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you run the unit tests and functional tests locally? Visit our Testing Guide for how to run tests
  • Did you add or update any necessary documentation? Visit our Document Development Guide for how to write, build and test the docs.

Additional Information

Restore Behavior

On restore, the replay buffer is prepared for the current training step:

  • drops trajectories for past target steps
  • preserves current/future target steps so incomplete restored batches can be gap-filled
  • resets last_target_weight_already_generated to current_step - 1 so the collector re-checks current/future targets by count
  • handles empty restored buffers without skipping the resumed step
  • removes restored trajectories that are stale for their target step when max_age_steps is provided
  • truncates after restore cleanup if current max_size is smaller than the checkpointed buffer

Behavioral Differences From Upstream Commit

  • Empty replay-buffer restore resets last_target_weight_already_generated to current_step - 1.

    • Reason: upstream only prepared the buffer when restored trajectories existed. If the restored buffer was empty but the checkpoint watermark was high, the collector could skip the resumed step and training would wait forever.
  • Restore truncation happens after resume cleanup, not before.

    • Reason: upstream truncated immediately and kept the oldest entries. If max_size shrank, this could keep past-step trajectories and discard current/future ones needed for resume.
  • When current_training_step is known, max-size truncation prioritizes the nearest current/future target steps.

    • Reason: after dropping past targets, the most useful restored trajectories are for the current training step first, then later steps. Keeping oldest-by-index is not necessarily the right behavior after resume.
  • Restore can remove trajectories that are already stale for their target step via max_age_steps.

    • Reason: without this, restored stale trajectories could remain in the buffer until sample() evicts them later. Cleaning them during restore makes the restored state match what training can actually consume.
  • GRPO passes max_trajectory_age_steps into replay-buffer restore.

    • Reason: restore needs the configured staleness window to remove stale restored trajectories consistently.

@macandro96
macandro96 requested review from a team as code owners May 29, 2026 18:05
@macandro96 macandro96 added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label May 29, 2026
@copy-pr-bot

copy-pr-bot Bot commented May 29, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@macandro96
macandro96 requested review from ananthsub, terrykong and yfw May 29, 2026 18:22
@macandro96

Copy link
Copy Markdown
Contributor Author

Notes for reviewers
This PR intentionally keeps the scope to replay-buffer checkpointing and direct restore bugs.

A few adjacent issues are not handled here and may be better as follow-ups:

  • prepare_for_checkpoint() / resume_after_checkpoint() style collector to drain remaining generations before checkpointing. This could make dataloader + replay-buffer snapshots more consistent, but may increase checkpoint-time generation GPU idle/wait.
  • Reworking _process_batch() to reuse unused prompts from a gap-fill batch for later target steps.
  • Tightening the public load_state_dict(..., current_training_step=None) fallback path. GRPO resume always passes current_training_step, but the fallback path has less information and may deserve stricter validation later.

@macandro96

Copy link
Copy Markdown
Contributor Author

/ok to test 87cfe62

@macandro96

Copy link
Copy Markdown
Contributor Author

/ok to test 251ebbd

@macandro96

Copy link
Copy Markdown
Contributor Author

This PR will be folded and will be merged as part of #2651

@macandro96 macandro96 closed this Jun 9, 2026

This branch was previously deployed

2 inactive deployments
public — 251ebbd0 Deployed Jun 1, 2026 by copy-pr-bot[bot] via release / finalize / publish-docs #572
nemo-ci — 251ebbd0 Deployed Jun 1, 2026 by copy-pr-bot[bot] via Docs_Tests #11847
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant