Skip to content

fix(async-grpo): fail fast on generation worker errors - #2368

Merged
terrykong merged 1 commit into
NVIDIA-NeMo:mainfrom
jthomson04:jthomson04/fix-async-collector-per-target-counts
Aug 11, 2026
Merged

terrykong merged 1 commit into
NVIDIA-NeMo:mainfrom
jthomson04:jthomson04/fix-async-collector-per-target-counts

Conversation

@jthomson04

@jthomson04 jthomson04 commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Async GRPO can otherwise leave the trainer waiting for replay-buffer data when rollout batch workers fail in the background. This change makes those failures visible while preserving recovery from transient failures:

  • Count consecutive failed _run_rollout_batch_worker invocations and reset the streak after a successful batch.
  • Preserve failure timing, traceback logging, target release, and worker-thread cleanup.
  • Store the first fatal diagnostic after failures exceed max_generation_failures, including the backend, generation weight, target weight, count, threshold, original exception, and worker traceback.
  • Raise a fresh RuntimeError from check_health() and check health during initial buffer fill and once per training-loop iteration.
  • Give AsyncGRPOConfig.max_generation_failures the documented Pydantic default of 0, while keeping explicit YAML values in runnable async-GRPO configs and the reference snapshot.
  • Wake paused collection after a tolerated worker failure so released targets can be gap-filled, and re-arm the pause event on every limit check.
  • Exclude errors raised only because normal dataloader exhaustion stopped the collector, while preserving reservation release and worker-thread cleanup.
  • Set the four Nemotron-3-Super stage recipes, two Qwen SWE recipes, and seven Nemotron-3-Ultra recipes to tolerate 3 consecutive failures, aborting on the fourth.
  • Document the setting in both copyable async-GRPO guide examples.

Superseded original fix

This PR originally targeted incomplete per-target prompt-group accounting. That original bugfix is no longer part of this PR: a separate batched reservation and gap-filling fix landed on main and superseded it.

The rebase therefore drops obsolete commit 96ee36e72, preserves the target-accounting behavior now on main, and contains no replay-buffer or target-accounting delta.

Failure semantics

max_generation_failures: 0 is fail-fast. Positive values tolerate that many consecutive failed batch-worker invocations. A successful batch resets the streak. Once the threshold is exceeded, the first fatal diagnostic remains sticky and subsequent check_health() calls raise fresh exceptions carrying that diagnostic.

Validation

  • Parameterized worker-health coverage for healthy checks, immediate failure, positive tolerance, success reset, threshold crossing, sticky first-fatal diagnostics, fresh exceptions, traceback context, and reservation release.
  • Regression coverage for tolerated-failure wake-up at max_trajectory_age_steps: 1 and for normal shutdown errors not affecting worker health.
  • Async trainer coverage for unconditional per-step health propagation and cleanup.
  • Pydantic default-model and router-replay compatibility after the config migration on main.
  • Normal async trainer max-step path.
  • Config-reference validation, including the current GRPO contract for all seven Nemotron-3-Ultra recipes.
  • Focused and broader unit validation: 93 tests passed.
  • Ruff check and format validation on affected Python files.
  • git diff --check.

@jthomson04
jthomson04 requested review from a team as code owners April 29, 2026 21:46
@copy-pr-bot

copy-pr-bot Bot commented Apr 29, 2026

Copy link
Copy Markdown

Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@jthomson04

Copy link
Copy Markdown
Contributor Author

/ok to test 24e0667

@yuki-97 yuki-97 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.

@jthomson04 thanks for fixing this, overall lgtm. left some comments.

Comment thread nemo_rl/algorithms/async_utils.py Resolved
Comment thread nemo_rl/algorithms/async_utils.py Resolved
jthomson04 added a commit to jthomson04/RL that referenced this pull request May 8, 2026
Address review feedback from @yuki-97 on PR NVIDIA-NeMo#2368:
- Move `from collections import Counter` to the top of the file instead
  of importing it inside three separate methods.
- Stop discarding prompts when one target's reservation is smaller than
  the batch. `_process_batch` now keeps reserving against successive
  targets in the age window until the batch is exhausted or no target
  still needs generation.

Signed-off-by: jthomson04 <[email protected]>
@jthomson04 jthomson04 added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label May 8, 2026
@jthomson04

Copy link
Copy Markdown
Contributor Author

/ok to test 105aa4d

jthomson04 added a commit to jthomson04/RL that referenced this pull request May 8, 2026
Address review feedback from @yuki-97 on PR NVIDIA-NeMo#2368:
- Move `from collections import Counter` to the top of the file instead
  of importing it inside three separate methods.
- Stop discarding prompts when one target's reservation is smaller than
  the batch. `_process_batch` now keeps reserving against successive
  targets in the age window until the batch is exhausted or no target
  still needs generation.

Signed-off-by: jthomson04 <[email protected]>
@jthomson04
jthomson04 force-pushed the jthomson04/fix-async-collector-per-target-counts branch from 105aa4d to 333c87c Compare May 8, 2026 00:16
@jthomson04

Copy link
Copy Markdown
Contributor Author

/ok to test 333c87c

yuki-97
yuki-97 previously approved these changes May 8, 2026

@yuki-97 yuki-97 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 @jthomson04 , lgtm!
@terrykong @mehraakash could you help to take a review as well?

@terrykong

Copy link
Copy Markdown
Collaborator

@jthomson04 IIUC, this now allows backfill for failing prompts instead of stalling/hanging. Please correct me if I'm wrong. If my understanding is correct, I feel like we should actually be erroring out (surface the error) b/c this kind of behavior seems like it can allow a lot of issues to be swept under the rug and ignored

@ananthsub to opine on gym surfacing errors and how this could happen

@jthomson04
jthomson04 force-pushed the jthomson04/fix-async-collector-per-target-counts branch from 333c87c to 1affe55 Compare May 12, 2026 20:20
@jthomson04
jthomson04 requested a review from yuki-97 May 13, 2026 15:58
@jthomson04

Copy link
Copy Markdown
Contributor Author

Pushed an update to set a threshold for errors we tolerate. It loudly logs errors, and throws an exception after a certain amount of errors have been reached. By default, we retain the prior behavior of considering any generation error as fatal.

yuki-97
yuki-97 previously approved these changes May 15, 2026

@yuki-97 yuki-97 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 @jthomson04 , lgtm. could you help to rebase main and fix the conflict?

@terrykong @mehraakash could you help to take a review as well?

@jthomson04
jthomson04 force-pushed the jthomson04/fix-async-collector-per-target-counts branch from 1affe55 to 3fc9465 Compare May 19, 2026 02:16
@copy-pr-bot

copy-pr-bot Bot commented May 19, 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.

@jthomson04

Copy link
Copy Markdown
Contributor Author

/ok to test 3fc9465

@yuki-97
yuki-97 enabled auto-merge (squash) July 30, 2026 14:29
@jthomson04
jthomson04 force-pushed the jthomson04/fix-async-collector-per-target-counts branch from 52f5a72 to a168378 Compare July 30, 2026 16:18
@jthomson04

Copy link
Copy Markdown
Contributor Author

/ok to test a168378

@jthomson04
jthomson04 force-pushed the jthomson04/fix-async-collector-per-target-counts branch from a168378 to 777ba10 Compare July 30, 2026 18:18
@jthomson04

Copy link
Copy Markdown
Contributor Author

/ok to test 777ba10

@yuki-97

yuki-97 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

/ok to test 30c98ad

@yuki-97

yuki-97 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

/ok to test 5244f6e

@yuki-97
yuki-97 disabled auto-merge July 31, 2026 10:43
@yuki-97
yuki-97 requested a review from yfw July 31, 2026 10:44
yuki-97
yuki-97 previously approved these changes Jul 31, 2026

@yuki-97 yuki-97 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.

@terrykong @yfw could you help to take a review as well?

@jthomson04
jthomson04 force-pushed the jthomson04/fix-async-collector-per-target-counts branch from 5244f6e to 109036f Compare August 3, 2026 17:24
@jthomson04

Copy link
Copy Markdown
Contributor Author

/ok to test 109036f

@jthomson04
jthomson04 force-pushed the jthomson04/fix-async-collector-per-target-counts branch from 109036f to b5c7dee Compare August 4, 2026 16:06
@jthomson04

Copy link
Copy Markdown
Contributor Author

/ok to test b5c7dee

@terrykong terrykong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed with a team of five agents plus an adversarial pass; the main finding has a runnable repro attached to the first comment (verbatim-extracted methods, no GPU/ray/torch, deterministic 3/3).

The fast-fail is correctly wired for max_generation_failures: 0, and the bare raise at grpo.py:5104 is load-bearing rather than incidental — without it check_health()'s RuntimeError would be caught and swallowed by that same block and the feature would be a no-op. It also fixes a real pre-existing bug where a crashed async run exited 0. Docs, exemplar and the reference config are updated in lockstep.

The one thing I'd hold on: at max_trajectory_age_steps: 1 — which all 13 recipes this PR sets to max_generation_failures: 3 resolve to — once a batch worker exhausts its in-worker retries, the #2651 gap-fill that would top the short target back up never executes. The collection loop parks while the worker is in flight and a released slot can't wake it, so trajectories_needed is never recomputed and the step never completes. 0 aborts cleanly on such a failure; 3 hangs silently. Two-line fix, verified by the repro.

Two smaller independent items: a config default that contradicts its own documentation, and a miscount that turns normal dataloader exhaustion into a fatal generation failure.

Generated by Claude Code

Comment thread nemo_rl/algorithms/grpo.py Resolved
@jthomson04
jthomson04 force-pushed the jthomson04/fix-async-collector-per-target-counts branch from b5c7dee to 87f55d4 Compare August 6, 2026 18:28
@jthomson04

Copy link
Copy Markdown
Contributor Author

/ok to test 87f55d4

@jthomson04 jthomson04 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 87f55d4. The collector now tracks consecutive failures, preserves the first formatted diagnostic, raises fresh health exceptions, wakes gap filling after tolerated failures, and excludes shutdown-induced enqueue errors from failure accounting. AsyncGRPOConfig.max_generation_failures now defaults to 0, long-running agentic recipes explicitly tolerate 3, the trainer checks health every iteration, and the copyable docs/config references are updated. Validation passed: 93 broader unit tests, 4 focused post-format worker regressions, Ruff lint/format, and git diff --check.

Comment thread nemo_rl/algorithms/grpo.py Resolved
Comment thread nemo_rl/algorithms/grpo.py Resolved
Comment thread nemo_rl/algorithms/grpo.py Resolved
@jthomson04
jthomson04 force-pushed the jthomson04/fix-async-collector-per-target-counts branch from 87f55d4 to 07be815 Compare August 7, 2026 17:13
@jthomson04

Copy link
Copy Markdown
Contributor Author

/ok to test 07be815

Track consecutive rollout batch-worker failures in AsyncTrajectoryCollector
and surface fatal health errors through async trainer startup and per-step
checks. Add max_generation_failures with fail-fast defaults, resilient async
recipe overrides including Nemotron-3-Ultra, documentation, and focused
coverage.

Co-authored-by: Yuki Huang <[email protected]>
Signed-off-by: Yuki Huang <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
@jthomson04
jthomson04 force-pushed the jthomson04/fix-async-collector-per-target-counts branch from 07be815 to d585f13 Compare August 8, 2026 20:21
@terrykong
terrykong enabled auto-merge (squash) August 10, 2026 21:05
@terrykong

Copy link
Copy Markdown
Collaborator

/ok to test d585f13

@terrykong
terrykong merged commit 18b38b5 into NVIDIA-NeMo:main Aug 11, 2026
141 of 143 checks passed
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) Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants