part 2 of 3 · the mechanism · what PR #3665 actually does

How a training step keeps its full batch when a rollout is lost

What NVIDIA-NeMo/RL #3665 actually does. Builds on #3589. All permalinks pin the PR head ad048f9. Companion page: why a lost rollout used to end the run.

The SingleController runs two loops at once: one generates completions ("rollout pump"), one trains on them ("train pump"), joined by a buffer. With the in_order sampler, every batch the rollout pump sends out is given the number of the training step it belongs to, and step N will only train on groups carrying the number N (staleness_sampler.py:409). So if a prompt fails every retry and is given up on, step N is one group short and nobody else's work can fill the hole. This PR adds three ways out, and picks between them automatically. The numbers below use a batch of 4 prompts per step.

The three things that can happen to a step that lost a prompt

One prompt (P2) fails every retry. What happens to training step 0, which was counting on it? finished, ready to train on given up on spare prompt (set aside earlier, not yet generated) finished work moved from a later step 1. shrink the default train on fewer step 0 P0 P1 P2 P3 step 0 trains on 3 groups instead of 4 the step is smaller, the run keeps going 2. replace generate a spare instead step 0 P0 P1 S0 P3 pool S0 S1 S2 S3 step 0 trains on all 4 but the trainer sits idle while S0 generates the pool is one whole batch set aside earlier 3. borrow, then pay it back used whenever it is possible before step 0 P0 P1 P2 P3 step 1 Q0 Q1 Q2 Q3 already finished โ€” not due for another step after step 0 P0 P1 Q0 P3 closes right now step 1 S0 Q1 Q2 Q3 has a whole step's time to wait for S0 Q0 moves back a step the spare repays step 1 Nothing waits on a new rollout in case 3 โ€” the work already existed, it just moved to where the hole was. Borrowing only happens with a spare in hand, so the lender is always paid back. Otherwise the hole just moves one step later. _credit_shortfall (case 1) _take_replacement (case 2) _promote_into_step (case 3) promote_ready_group

The same example, as the code runs it

Case 1 is just arithmetic. The train pump asks how many groups this step should wait for, every time around the loop, instead of assuming it is always the configured batch size:

# config for this example grpo.num_prompts_per_step = 4 min_step_batch_fraction = 0.75 # floor = ceil(4 * 0.75) = 3 # P2 is given up on _credit_shortfall(0) -> _batch_shortfall = {0: 1} _target_groups_for_step(0) -> 4 - 1 = 3 # 3 >= floor 3, allowed train pump: while groups_dispatched < 3 # closes on 3, no waiting metrics: dropped_prompt_groups = 1 # if a second prompt is also lost _target_groups_for_step(0) -> 4 - 2 = 2 # 2 < floor 3 RuntimeError: training step 0 lost 2 of 4 prompt group(s), leaving 2, below the floor of 3 set by min_step_batch_fraction=0.75

_target_groups_for_step ยท the loop that re-reads it every pass: single_controller.py:838 (on main this line was the fixed num_prompts_per_step) ยท the floor: min_step_batch_fraction

Cases 2 and 3 are the same code path โ€” the task that lost its prompt keeps running and tries again with a spare. Whether it works for step 0 or for step 1 is decided by whether a later step has finished work to lend:

on_dropped_prompt = "replace" pool = [S0, S1, S2, S3] # one whole batch set aside before it was given a step number # P2 is given up on, in the task that was generating it S0 = _take_replacement(target_step=0, used=0) # pool -> [S1, S2, S3] lender = _promote_into_step(0) -> step 1 has a finished group Q0, so re-label Q0 as step 0 -> returns 1 target_step = 1 # this task now works for step 1, not step 0 generate(S0) for step 1 step 0: P0 P1 Q0 P3 -> 4 groups, closes immediately step 1: S0 Q1 Q2 Q3 -> 4 groups once S0 finishes, and step 1 is not due yet metrics: step 0 promoted_prompt_groups = 1 step 1 replaced_prompt_groups = 1

the retry loop that keeps the task alive ยท _divert_batch_to_reserve fills the pool ยท _drain_reserve_into_steps trains on whatever spares are left at the end, so no data is thrown away

The four numbers, and which ones move

Four similar-sounding numbers decide how big a step is. Two are settings you write in YAML; two are working values the trainer recomputes as it goes. Mixing them up is the easiest way to misread this feature.

valuewhere it liveswhat it iswhen it changes
num_prompts_per_stepyour YAMLgroups a full step wantsnever
min_step_batch_fractionyour YAMLhow much of that is still acceptablenever
min_groups_for_streaming_trainyour YAMLsmallest chunk worth starting a training pass on โ€” a speed settingnever
floor = ceil(N × fraction)worked out at startupbelow this the run stops with an errornever
target_groupsworking valuewhat this step will actually train ononce per step, per lost prompt
max_prompt_groupsworking valuehow many this step still needs right nowevery pass of the loop
min_prompt_groupsworking valuesmallest chunk to ask for right nowevery pass of the loop

Two things that trip people up. The floor is a check, not a target โ€” losing 1 prompt out of 4 gives target_groups = 3, not 4 × fraction; the floor is only what 3 gets compared against. And min_prompt_groups is capped by what is left (single_controller.py:871), so a chunk size of 30 never blocks a step that only needs 17 โ€” and never reaches into the next step to top itself up, because the take is capped at max_prompt_groups and the groups for other steps carry a different step number anyway.

Does it work?

Nobody has posted a run. There is no W&B link, no before/after step-count, and no log from a job that actually lost a shard mid-training. The PR is covered by unit tests that drive the real rollout and train loops with fake samplers, and CI is green โ€” but that only shows the bookkeeping adds up, not that a real fleet outage is survived.

The one thing worth asking for before merge is a single long run with a generation worker killed on purpose part way through, reporting the three new per-step numbers (dropped_prompt_groups, replaced_prompt_groups, promoted_prompt_groups, single_controller.py:1043) and the reward curve next to a clean baseline. That would show both that the run survives and that training quality is unchanged.

What this means for you. Every setting here is off by default, so a run that sets nothing behaves exactly as it does today. Turning them on is a trade: shrink means some steps compute their gradient from a smaller batch, and min_step_batch_fraction is the guard that says how much smaller you will accept โ€” at the default 0.9, a batch of 8 or fewer prompts tolerates no losses at all. replace keeps the batch size but can leave the trainer waiting on a fresh completion, which is why the code borrows finished work from a later step whenever it can. One thing to know before you turn it on: these settings only do anything with the in_order sampler, because it is the only one that labels batches with a step number.