Skip to content

fix(async-grpo): add startup barrier to prevent checkpoint-resume deadlock - #3066

Merged
snowmanwwg merged 4 commits into
mainfrom
fix/async-grpo-resume-pipeline-barrier
Jul 23, 2026
Merged

snowmanwwg merged 4 commits into
mainfrom
fix/async-grpo-resume-pipeline-barrier

Conversation

@snowmanwwg

Copy link
Copy Markdown
Contributor

Problem

When resuming async GRPO from a checkpoint whose replay-buffer snapshot already contains a complete batch for the current training step, training silently deadlocks — no Python traceback, no error, just a stall that eventually hits the job timeout.

Root cause:

  1. The startup wait loop checks has_complete_batch(step) and breaks immediately when True.
  2. After consuming those restored trajectories and triggering a refit, the collector's _calculate_target_weights takes the non-initial branch and returns [weight_version+1, ...], skipping the just-refitted step entirely.

Timeline on a step-30 resume with 8 trajectories for target 30 in the checkpoint:

Event State
load_state_dict(step=30) 8 trajectories for target 30 in buffer
Startup wait: has_complete_batch(30) → True, break Target 31 never checked
sample(weight_version=30) consumes 8 trajectories
Refit → weight_version = 31
_calculate_target_weights(31): non-initial → reserves target 32 Target 31 nobody generates
sample(weight_version=31) → 0 found → stall

This race is invisible during normal uninterrupted training because target N+1 is generated while step N trains, so the lookahead is always present before a refit. On a checkpoint resume, target N is already complete, so startup returns before the lookahead exists. First surfaced by PR #2651 (replay-buffer checkpointing).

Fix

Before breaking out of the startup wait, also require has_complete_batch(step+1) to be True (or step+1 >= max_num_steps). The collector's initial branch of _calculate_target_weights already covers [start_step, start_step + max_age], so it fills the lookahead while the barrier holds. Once both targets are ready, consuming the current step and refitting is safe.

The barrier is a no-op on fresh starts (target 0 is not in the buffer, so the loop never reaches the if current_step_ready branch until both targets have been filled naturally).

Changes

  • nemo_rl/algorithms/grpo.py — lookahead check inside the if current_step_ready branch, guarded by max_trajectory_age_steps > 0 and step + 1 < max_num_steps
  • tests/unit/algorithms/test_async_utils.py — test_resume_deadlock_precondition_detectable constructs the exact buffer state (current complete, lookahead absent) and asserts the readiness values the barrier branches on

Related

Co-authored-by: Claude Sonnet 4.6 [email protected]

@snowmanwwg
snowmanwwg requested review from a team as code owners July 5, 2026 22:56
@copy-pr-bot

copy-pr-bot Bot commented Jul 5, 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.

@snowmanwwg
snowmanwwg requested a review from macandro96 July 5, 2026 23:08
@snowmanwwg

Copy link
Copy Markdown
Contributor Author

/ok to test 8c970d4

snowmanwwg and others added 2 commits July 21, 2026 14:23
When resuming from a checkpoint whose replay-buffer snapshot already
contains a complete batch for the current training step, the startup
wait loop broke immediately.  The main loop then consumed all target-N
trajectories, triggered a refit, and advanced the collector's weight
version to N+1.  The collector's post-refit _calculate_target_weights
takes the non-initial branch and returns [N+2, N+3, ...], skipping
N+1 entirely.  Training then waited for target N+1 indefinitely —
a silent deadlock with no Python traceback.

Fix: before breaking out of the startup wait, verify that
has_complete_batch(step+1) is also True (or step+1 >= max_num_steps).
The collector's initial branch already covers [start_step, start_step +
max_age], so it generates the lookahead while the barrier holds.
Once both the current and lookahead targets are ready, consuming the
current target and refitting is safe.

Also add a regression test that constructs the exact precondition state
(current target complete, lookahead absent) to document what the barrier
is guarding against and to prevent silent regressions.

Fixes: async-GRPO resume stall first observed at step 30→31 boundary
where replay_buffer.pt was restored from checkpoint but the lookahead
target-31 trajectories had not yet been generated before the checkpoint.

Signed-off-by: Wenwen Gao <[email protected]>
Removed detailed comments explaining the checkpoint-resume pipeline deadlock and its fix.

Signed-off-by: Wenwen Gao <[email protected]>
Signed-off-by: Wenwen Gao <[email protected]>
@snowmanwwg
snowmanwwg force-pushed the fix/async-grpo-resume-pipeline-barrier branch from 8c970d4 to 3865a85 Compare July 21, 2026 21:24
@snowmanwwg snowmanwwg changed the title fix(async-grpo): add startup pipeline barrier to prevent checkpoint-resume deadlock fix(async-grpo): add startup barrier to prevent checkpoint-resume deadlock Jul 21, 2026

@macandro96 macandro96 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tracking down this silent resume deadlock — the root-cause writeup and timeline table made the fix easy to follow.

The barrier logic checks out against the collector: initial_weight_version = start_step, so on resume the initial branch of _calculate_target_weights covers [step, step+1] and fills the lookahead while the barrier holds. step+1 is exactly the unique orphan target (covered by the initial branch but skipped by the post-refit non-initial branch [step+2, ...]), so the fix is as narrow as it needs to be. The max_num_steps / max_trajectory_age_steps > 0 guards and the fresh-start no-op behavior all look right.

Just one nit

Generated by Claude Code

@snowmanwwg

Copy link
Copy Markdown
Contributor Author

/ok to test 3865a85

@snowmanwwg snowmanwwg added the CI:L0 Run doctests and unit tests label Jul 22, 2026
@snowmanwwg

Copy link
Copy Markdown
Contributor Author

/ok to test 5d76eed

@snowmanwwg
snowmanwwg requested review from macandro96 and removed request for a team July 22, 2026 02:35
@snowmanwwg snowmanwwg added CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) and removed CI:L0 Run doctests and unit tests labels Jul 22, 2026
The if not next_step_ready block only fires during an async-GRPO
checkpoint resume in a live Ray cluster with specific buffer state.
Unit-testing it would require a full training loop fixture; the buffer-layer
precondition is already verified by test_resume_deadlock_precondition_detectable.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
Signed-off-by: Wen Weng <[email protected]>
@snowmanwwg
snowmanwwg force-pushed the fix/async-grpo-resume-pipeline-barrier branch from ebaa504 to e4903a8 Compare July 22, 2026 18:53
@snowmanwwg

Copy link
Copy Markdown
Contributor Author

/ok to test e4903a8

@snowmanwwg
snowmanwwg merged commit d4a9d0f into main Jul 23, 2026
80 checks passed
@snowmanwwg
snowmanwwg deleted the fix/async-grpo-resume-pipeline-barrier branch July 23, 2026 06:40
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.

2 participants