Skip to content

feat(sc): tolerate and replace dropped rollouts in the SingleController - #3665

Merged
terrykong merged 2 commits into
NVIDIA-NeMo:mainfrom
saumishr:fix/sc-tolerate-failed-rollouts
Aug 19, 2026
Merged

terrykong merged 2 commits into
NVIDIA-NeMo:mainfrom
saumishr:fix/sc-tolerate-failed-rollouts

Conversation

@saumishr

@saumishr saumishr commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do ?

Add a one line overview of what this PR aims to accomplish.

Make the SingleController path survive rollout failures: drop a prompt within budget instead of ending the run, close the affected training step short so an in_order sampler cannot hang on a group nobody is generating, and optionally replace the lost prompt so the step keeps its configured batch size.

Issues

List issues that this PR closes (syntax):

Builds directly on #3589, which added the failure taxonomy and per-prompt retry budgets but always ended the run once a budget was exhausted.

Usage

  • You can potentially add a usage example below

All knobs live under async_rl.rollout_failure. Defaults are inert — a run that does not set these behaves exactly as it does on main.

async_rl:
  rollout_failure:
    # Ride out a shard outage instead of losing the job: CONSECUTIVE prompts that may
    # exhaust their infra budget and be dropped. Any committed rollout resets the count,
    # so this bounds an outage rather than the run's lifetime. 0 (default) fails on the
    # first one, which is today's behaviour and v1's default.
    max_consecutive_dropped_prompts: 8

    # Smallest batch a step may close on, as a fraction of num_prompts_per_step. Neither
    # drop budget can bound this on its own, since both are run-scoped.
    min_step_batch_fraction: 0.9

    # "shrink" (default) trains the step on fewer groups, bounded by the floor above.
    # "replace" substitutes a fresh prompt so the step keeps its configured batch size.
    on_dropped_prompt: replace
    max_replacement_attempts: 1     # fresh prompts tried per lost group
    replacement_reserve_prompts: 1  # low-water mark for the spare-prompt pool

Additional Information

Three commits, each standalone:

  1. feat(sc): tolerate dropped rollouts instead of failing the run: max_consecutive_dropped_prompts, plus the shortfall credit. InOrderSampler stamps each batch with a target step and selects on an exact match, so a group that never arrives leaves that step permanently short and the train pump waits forever, turning a crash into a hang. The pump now credits the shortfall against the stamped step and closes it early. This also fixes the pre-existing max_skipped_prompts path, which could already strand an in-order step.

  2. fix(sc): bound how short a dropped-prompt step may close: min_step_batch_fraction. Both drop budgets are run-scoped (the consecutive counter is cleared by any commit, including commits for other steps), so drops concentrated on one step could shrink it without limit. A fraction rather than a count, so it holds across batch sizes and protects small batches more strictly.

  3. feat(sc): replace a dropped prompt so its step keeps its batch size — on_dropped_prompt, the spare-prompt pool, and borrowing.

Design notes worth reviewer attention:

Only stamping samplers are affected. With weight_fifo or windowed, admit returns None and a step fills from whatever is ready, so a drop costs throughput but strands nothing. Nothing is diverted into the spare pool until the sampler has actually stamped a batch, so an unstamped run does not lose prompts to a pool it can never draw on.
The spare pool is refilled from the pump loop, by diverting one whole dataloader batch before admit(). The pump is the sole owner of the StatefulDataLoader, and advancing that iterator from a dispatch task which is where a drop is discovered, arbitrarily later would race the ordering that checkpoint/resume accounting depends on. Diverting before admit() also means a diverted batch never burns a target step.

Leftover spares are trained on. Once the dataloader is exhausted the pool is dispatched as ordinary steps, so the diverted batch is neither discarded nor silently subtracted from max_num_steps (which is derived from len(dataloader)). Partial pools are held back rather than dispatched as a step that is short by construction.
Borrowing is an optimization inside replace, not a mode. A fresh rollout puts the wait on the critical path — the trainer has closed the previous step and idles until the substitute commits. When a later step already holds a finished group, TQReplayBuffer.promote_ready_group re-stamps it into the dropped step (which then closes immediately) and the fresh prompt repays the lender, which is not due for another step. A borrow is only taken with a spare in hand: an unrepaid loan is the same hole one step later, walking forward to the final step, which has nobody to borrow from. Both paths hold the batch size, so selecting between them is not worth exposing; the two counters report which one ran.

promote_ready_group is deliberately synchronous. TQReplayBuffer.remove deletes its indices before its first await, so as long as the re-stamp does not yield, the index it picks cannot be shifted out from under it by a concurrent selection.

The fallback chain always terminates: borrow → fresh replacement → shrink, bounded by max_replacement_attempts and the pool. Without the shrink fallback, a step whose replacements keep failing would never close at all.

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.

@saumishr
saumishr requested review from a team as code owners August 16, 2026 16:02
@copy-pr-bot

copy-pr-bot Bot commented Aug 16, 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.

@cursor

cursor Bot commented Aug 16, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@rohitrango

Copy link
Copy Markdown
Contributor

this feature can potentially be combined/merged with allowing partial rollout groups depending on an eviction countdown and time(latest rollout)/time(p50) factor

@saumishr saumishr added the CI:L1 Run doctests, unit tests, and functional tests label Aug 18, 2026
@saumishr
saumishr force-pushed the fix/sc-tolerate-failed-rollouts branch from 953355c to f0a059c Compare August 18, 2026 03:41

@saumishr saumishr 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.

Team review of this PR: four analysis agents (RL/guidelines, bug hunting, tests, design) followed by two independent adversarial passes over every finding. Rebased onto main at 42f449161 first; the diff applies clean with no file overlap.

Two of the eight are worth acting on before merge: a torn read of the step target that can crash the train pump with ValueError: min_prompt_groups must be >= 1, got 0 — converting a tolerated drop back into a run failure — and a spare pool that is not checkpointed while the dataloader position is, so a resumed replace run silently loses a batch. The rest are test gaps and one-line text fixes.

Verified rather than assumed, since the PR makes these claims explicitly:

  • promote_ready_group really does contain no yield point, and remove really does delete its indices before its first await. Every other mutator of those indices was checked too: reserve, commit and load_state_dict only append or re-resolve idx by group_id after their awaits, so the re-stamp cannot have its index shifted out from under it. The docstring's contract holds as written.
  • The borrow -> replace -> shrink chain always terminates. Every exit either commits, raises, or credits a shortfall; no path leaves a step neither closing nor aborting.
  • The default path is a genuine no-op. With both budgets at 0 neither SKIPPED return is reachable, so the floor, the shortfall credit and all three reserve helpers are unreachable, and the added cost is one dict lookup and a ceil per pump iteration. No convergence A/B is warranted for this PR, which is why there is no [PERF-EVIDENCE] ask.

Findings that did not survive the adversarial pass, noted because they look plausible and may come up again: that _take_replacement needs the target_step < self._trainer_version guard _promote_into_step has, and that promotion can target a step that has closed but not yet advanced the trainer version. Both die on the same invariant — at loop exit groups_dispatched + shortfall == N exactly, so no slot can still be in flight against a closed step, and no ready group remains stamped for one. Adding that guard would be dead code.

Generated by Claude Code

Comment thread nemo_rl/algorithms/single_controller.py Resolved
Comment thread nemo_rl/algorithms/single_controller.py Resolved
Comment thread nemo_rl/experience/rollout_manager.py Resolved
@saumishr

Copy link
Copy Markdown
Contributor Author

this feature can potentially be combined/merged with allowing partial rollout groups depending on an eviction countdown and time(latest rollout)/time(p50) factor

@rohitrango agreed the decision point is shared: a straggler that trips rollout_timeout_s already ends up in this PR's drop/replace path, and a p50 ratio is a better trigger than a fixed wall clock, since it retunes itself as generations get longer over a run.

The delta is granularity. Partial groups need a variable N, which the replay buffer forbids on restore today ("a changed group size silently breaks the group-relative baseline"), and min_step_batch_fraction bounds groups per step, not rows per group. Worth noting too that evicting the slowest rows preferentially discards the longest generations on every step, not just failing ones, so it carries a length bias this PR's failure-driven drops do not.

Both seem like follow-up work on top of this rather than part of it — the drop path here is the natural place to hang the eviction decision once groups can be short.

@saumishr
saumishr force-pushed the fix/sc-tolerate-failed-rollouts branch from 2146b67 to 4158ddc Compare August 18, 2026 11:48
@saumishr
saumishr requested a review from terrykong August 18, 2026 11:49
@saumishr

Copy link
Copy Markdown
Contributor Author

/ok to test 4158ddc

@saumishr
saumishr force-pushed the fix/sc-tolerate-failed-rollouts branch from 4158ddc to ad048f9 Compare August 18, 2026 12:22
@saumishr

Copy link
Copy Markdown
Contributor Author

/ok to test ad048f9

@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 by a team of three agents (bug hunt, async/concurrency + sampler-buffer interaction, config/tests). Focused on functionality per the review request — no style or prose comments.

📊 The comments below are visualised here: three problems this review found — one diagram per finding, including the exact boundary mismatch that makes weight_fifo stop making progress. Two companion pages explain the PR itself, if useful: what problem it solves and how the fix works, the latter with a table of which of the four batch-size numbers are settings and which are recomputed each pass.

One finding is a defect — the sampler one. The other two are follow-up asks, both opening with "no action needed in this PR":

where what
config.py:442 [bug] with weight_fifo, any non-zero drop budget stops training for good; windowed fails at its final step. Pre-existing, but this PR adds a second way in and documents it as safe. Suggestion block included.
config.py:141 max_consecutive_dropped_prompts: 0 hides "end the run" inside a number, and duplicates what watchdog.stall_timeout_s measures — with the opposite default reaction.
config.py:156 how min_step_batch_fraction and min_groups_for_streaming_train relate is undocumented, and the natural guess is wrong.

Candidates raised and then dropped as not meeting the bar: a checkpoint reserve/buffer snapshot skew (real but bounded to one duplicated prompt group on one resume); a suspected behaviour change from the min_step_batch_fraction default (refuted — the path it affects already failed on main, so this is a fix); and a missing test for the chunk-size cap at single_controller.py:871 (the code is correct and the line is pre-existing, so it did not clear the bar for this review). Permit accounting across the new replacement loop, promote_ready_group re-stamp safety, the second TaskGroup closure rebind, _consumed_samples units, the consecutive-drop counter bounds, and the example YAML all checked out clean.

Note: this PR currently shows a merge conflict against main (mergeable: CONFLICTING) and will need a rebase.

Tests were reviewed statically only — they cannot run on this host (the lockfile is gated to linux/x86_64), so no local pass/fail is claimed, and no run of this feature exists yet. The single most useful thing before merge would be one short run with sampler.name: weight_fifo and max_consecutive_dropped_prompts: 1, forcing one prompt to fail, to confirm whether training keeps advancing.

Generated by Claude Code

A prompt that exhausts its infrastructure retry budget ended the run. On a
large fleet that means one unlucky prompt can kill a 68-node job, which is the
failure mode the v1 stack already handles: AsyncTrajectoryCollector abandons
the batch, keeps going, and only aborts once max_generation_failures
consecutive failures have gone by with nothing succeeding in between.

Give the SingleController path the same shape. max_consecutive_dropped_prompts
bounds how many prompts may be given up on with no commit in between; any
commit clears the count, so the budget measures an outage rather than the run's
lifetime. It is counted separately from max_skipped_prompts because a shared
allowance would let a bad dataset consume the headroom that exists to ride out
a shard outage. Both default to 0, so nothing changes unless asked.

Dropping a prompt is only safe if the trainer can still close its step.
InOrderSampler stamps each batch with a target step and selects on an exact
match, so a group that never arrives leaves that step permanently short and the
train pump waits on a group no one is generating -- converting a crash into a
hang. The pump now credits the shortfall against the stamped step and closes it
early, and reports dropped_prompt_groups so a short step is visible in the
metrics. This also covers the existing max_skipped_prompts path, which could
already strand an in-order step.

The step's target is read once per iteration, before it is turned into a batch
size. A prompt stamped for the step in progress can be dropped while the pump
is awaiting, so a target read a second time can come back lower than the first
-- and once it reaches what is already dispatched there is no batch left to ask
for, since the sampler rejects a minimum below 1. A non-positive remainder
closes the step instead. For the same reason _consumed_samples advances by the
groups the step actually dispatched rather than num_prompts_per_step, which
would overstate the dataset position written into the checkpoint on any short
step.

Shrinking without a bound is its own problem, because both drop budgets are
run-scoped: max_skipped_prompts is a lifetime total, and the consecutive infra
counter is cleared by any commit at all, including commits belonging to other
steps. Drops landing on one step while other steps succeed therefore keep
resetting the counter while that step shrinks freely, and a step is what the
gradient is computed from. min_step_batch_fraction sets the smallest batch a
step may close on, enforced where the target is computed. A fraction rather
than a count so it holds across batch sizes and protects small batches more
strictly: the floor is ceil(fraction * N), so at the 0.9 default a batch of 8
or fewer tolerates no drops. Being positive, it also makes the empty step
unreachable.

Shrinking is safe but it still changes the gradient estimate, and the floor
only bounds how far that goes. Both the v1 stack and verl hold the configured
batch size instead: v1 discards the batch and regenerates it, verl's async path
evicts the failed group and refills. So on_dropped_prompt="replace" substitutes
a fresh prompt for the lost group, bounded by max_replacement_attempts and by a
pool of spare prompts, falling back to shrinking when either runs out --
without that fallback a step whose replacements keep failing would never close
at all. The spares come from a pool refilled by diverting one whole dataloader
batch before admission, because the pump loop is the sole owner of the
StatefulDataLoader and advancing that iterator from a dispatch task -- which is
where a drop is discovered, arbitrarily later -- would race the ordering that
resume accounting depends on. Diverting before admit() keeps the stamp sequence
contiguous, and leftover spares are dispatched as ordinary steps once the
dataloader is exhausted, so the diverted batch is neither thrown away nor
silently subtracted from max_num_steps.

Where the replacement is sent is an optimization rather than a knob. A fresh
rollout puts the wait on the critical path: the trainer has already closed the
previous step and idles until the substitute commits. So when a later step
already holds a finished group, that group is re-stamped into the step that was
dropped from -- which then closes immediately -- and the fresh prompt repays
the lender, which is not due for another training step and has the slack to
absorb it. A borrow is only taken with a spare in hand, because an unrepaid
loan is the same hole one step later, walking forward until it reaches the
final step that has nobody to borrow from. Both paths hold the batch size, so
choosing between them is not worth exposing; promoted_prompt_groups and
replaced_prompt_groups report which one ran.

The pool is part of the checkpoint. Diverting a batch has already advanced the
iterator by the time the dataloader state is captured, so that state counts
those prompts as consumed while they exist only in memory; saving one without
the other would leave a resumed run holding an empty pool and an iterator
positioned past the batch, losing it for good, since the drain only recovers
spares held by the process that diverted them. The pool is snapshotted in the
same await-free window as the dataloader state, written as
replacement_reserve.pt, and restored in run() beside the replay buffer --
without that restore's sampler-name guard, since spares never reached admit and
so carry no stamp. The drain is likewise not gated on on_dropped_prompt, so a
pool restored into a run that has since switched to "shrink" is trained on
rather than stranded.

Setup rejects the two ways "replace" can be configured but unable to ever
produce a replacement, and warns about three combinations that are coherent yet
self-defeating: a min_step_batch_fraction that rounds up to the full batch
while a drop budget is set (the first drop fails the run instead of shrinking
the step), "replace" under a sampler that never stamps a target step (every
drop behaves as "shrink"), and replacement_reserve_prompts above one batch
(several batches are diverted back to back before anything is dispatched).
Warnings rather than errors, because each is a defensible thing to have typed
while debugging; what is not defensible is discovering hours in that the
tolerance you configured could never have been exercised.

Signed-off-by: Saurabh Mishra <[email protected]>
Every part of the dropped-prompt path is keyed on target_step, and InOrderSampler
is the only built-in that stamps one: _GatedSampler._stamp returns None, neither
WeightFifoSampler nor ReadyFirstSampler overrides it, and WindowedSampler.admit
returns None outright. _credit_shortfall, _take_replacement and _promote_into_step
all early-return on None, so under any of those a prompt that is given up on is
never subtracted from the step waiting for it. The step's target stays at the full
num_prompts_per_step and min_step_batch_fraction is never consulted.

The consequence is not an inert knob. Under weight_fifo the run stalls with no
error at all: select always takes min(in_window) and _finalize_selection returns
(None, 0) below min_prompt_groups, while the default evict only drops weights
strictly below the window, so the short version is never cleared. The same
admit() gate that stops the rollout pump running ahead also stops it reaching
exhaustion, so _rollout_exhausted never sets, the train pump sleeps 5ms and
re-asks forever, and the job holds its GPUs until the wall clock kills it. Under
windowed and ready_first it is bounded but late -- the hole migrates batch to
batch and the final step has none left to borrow from, failing hours in with
"rollout exhausted before a complete training step was assembled".

Rejected rather than warned about, unlike its neighbours in this function: those
each describe a coherent thing to have asked for, whereas there is no run that
wants a tolerance setting to convert a recoverable prompt failure into a stall.
A zero budget stays exempt and keeps the existing warning, because no drop is
tolerated then and the shortfall path is unreachable regardless of sampler.

The guard names the exempt samplers rather than the affected ones, so a sampler
added later is covered by default. That is not hypothetical: ready_first (NVIDIA-NeMo#3582)
landed between this branch's base and this rebase, inheriting the None stamp like
the rest, and an allow-list -- along with a test restating the same list -- would
have let it through silently. The test reads the sampler names off the
discriminated union for the same reason.

Signed-off-by: Saurabh Mishra <[email protected]>
@saumishr
saumishr force-pushed the fix/sc-tolerate-failed-rollouts branch from 8e0a4d9 to b0ba2f7 Compare August 19, 2026 05:59
@saumishr

Copy link
Copy Markdown
Contributor Author

/ok to test b0ba2f7

@terrykong

Copy link
Copy Markdown
Collaborator

given urgency, fixing the in_order bug was priority, other two things can be left for later

@terrykong
terrykong enabled auto-merge (squash) August 19, 2026 06:23
@terrykong
terrykong merged commit fbe2c44 into NVIDIA-NeMo:main Aug 19, 2026
177 of 179 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:L1 Run doctests, unit tests, and functional tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants