Repository navigation
fix(grpo): ReplayBuffer checkpointing and fix reservation leaks - #2651
Conversation
2ba5f1d to
de7bbd3
Compare
|
/ok to test de7bbd3 |
There was a problem hiding this comment.
Team review — PR #2651
The replay-buffer checkpointing looks sound: state_dict / load_state_dict are symmetric, the snapshot is taken under the buffer lock, the state is saved alongside the other checkpoint artifacts inside finalize_checkpoint, and resume validates the checkpoint shape, drops past targets, evicts stale trajectories, keeps incomplete future targets for gap-fill, and truncates to max_size without dropping the current step's batch or creating target gaps. Restore from a pre-checkpointing run falls back to an empty buffer gracefully. It's well covered at the unit level (state_dict / load_state_dict round-trips, torch.save round-trip, gap-fill accounting, stale eviction, empty-state reset, max_size change, and validation errors).
Also fixes two real bugs in the async replay buffer: (1) premature reservation release (the old code released at prompt_idx == 0 while later workers were still in flight, letting a subsequent batch re-reserve the same target and over-generate), and (2) premature watermark advancement in add() that could skip a partially-filled target and stall training.
@macandro96 Let's fold the close #2632 and just work on merging this one. Can you also add some docs to docs/guides/async-grpo.md about the replay buffer checkpointing since this is new behavior?
Generated by Claude Code
Do you think its a good idea to add a function test for replay-buffer checkpointing? @yfw |
388000e to
60fde00
Compare
|
/ok to test 60fde00 |
Yes makes sense! If it is easy to do, would be good to have an e2e functional test |
6c2a2b2 to
96f50ef
Compare
c121045 to
817aaed
Compare
|
/ok to test 817aaed |
Signed-off-by: Anish Mahishi <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
Advance last_target_weight_already_generated in sample() (on batch consumption) instead of add(), and release per-target generation reservations only once all spawned workers complete. This prevents reservation leaks and premature target-skipping in the async collector. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
- Add test_process_batch_gap_fill_spawns_only_needed to cover the partial gap-fill branch in _process_batch (num_prompts_to_generate < num_prompts_in_batch), addressing review feedback from yfw. - Add Checkpointing section to docs/guides/async-grpo.md documenting replay_buffer.pt save/restore behaviour, the restore cleanup sequence, and gap-fill after resume. Co-Authored-By: Claude Sonnet 4.6 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
Add grpo_async_replay_buffer_checkpoint.sh functional test that runs async GRPO for 2 steps, saves a checkpoint, resumes for 2 more steps, and asserts the replay buffer was restored from replay_buffer.pt. Co-Authored-By: Claude Sonnet 4.6 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
Co-authored-by: Terry Kong <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
Added a one-line comment so a future reader doesn't "harden" this to weights_only=True and silently break restore Co-authored-by: Terry Kong <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
817aaed to
5442990
Compare
|
/ok to test 5442990 |
…IA-NeMo#2651) Signed-off-by: Anish Mahishi <[email protected]> Signed-off-by: Anish Mahishi <[email protected]> Signed-off-by: Anish Mahishi <[email protected]> Co-authored-by: Anish Mahishi <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Co-authored-by: Anish Mahishi <[email protected]> Co-authored-by: Terry Kong <[email protected]>
What does this PR do ?
Adds replay-buffer checkpointing via
state_dict()/load_state_dict(), saved asreplay_buffer.ptalongside the dataloader state and restored on resume.Advance
last_target_weight_already_generatedinsample()(on batch consumption) instead ofadd(), and release per-target generation reservations only once all spawned workers complete. This prevents reservation leaks and premature target-skipping in the async collector.Note
Builds on top of #2632 and hence it needs to be merged before this is merged.
Issues
Fixes
increase last_target_weight_already_generated only when whole batch is generated and consumedpart of #1906Usage
# Add a code snippet demonstrating how to use thisBefore your PR is "Ready for review"
Pre checks:
Additional Information on checkpointing
Restore Behavior
On restore, the replay buffer is prepared for the current training step:
last_target_weight_already_generatedtocurrent_step - 1so the collector re-checks current/future targets by countmax_age_stepsis providedmax_sizeis smaller than the checkpointed bufferBehavioral Differences From Upstream Commit
Empty replay-buffer restore resets
last_target_weight_already_generatedtocurrent_step - 1.Restore truncation happens after resume cleanup, not before.
max_sizeshrank, this could keep past-step trajectories and discard current/future ones needed for resume.When
current_training_stepis known, max-size truncation prioritizes the nearest current/future target steps.Restore can remove trajectories that are already stale for their target step via
max_age_steps.sample()evicts them later. Cleaning them during restore makes the restored state match what training can actually consume.GRPO passes
max_trajectory_age_stepsinto replay-buffer restore.