Skip to content

fix(single_controller): drop the slot of a below-threshold finalizer group - #4958

Closed
joyang-nv wants to merge 3 commits into
mainfrom
joyang/sc-below-threshold-drop
Closed

joyang-nv wants to merge 3 commits into
mainfrom
joyang/sc-below-threshold-drop

Conversation

@joyang-nv

@joyang-nv joyang-nv commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Bug

When a token-capture group falls below token_capture.min_valid_fraction_per_group, the controller deletes its rows from TQ but leaves its replay-buffer slot in place, still marked ready. The buffer then holds a reference to data that no longer exists, and the sampler can select it for training.

Why

  1. commit_finalized marks the group's slot ready.
  2. The controller then sees the valid-row fraction is below the threshold and calls _discard_committed_group.
  3. That reuses the cleanup written for failures before commit: it clears the rows, then calls TQReplayBuffer.abort().
  4. abort() only drops unready slots. It returns False for a ready slot, and the return value is not checked.

The existing test mocked the buffer and only asserted that abort was called, so it never checked that the slot actually left the buffer.

Impact

This only triggers when min_valid_fraction_per_group is set and a group falls below it. From reading the code (not reproduced in a training run):

  • select and promote_ready_group only check target_step and ready, so they can pick the dangling slot. The train fetch then asks TQ for cleared sample ids.
  • The step's replacement group makes N+1 ready slots for N picks, so a valid group can be left out and later evicted as stale.
  • The slot occupies buffer space the capacity accounting thinks is free.
  • The next checkpoint's _validate_replay_inventory fails on the missing sample ids.

Fix

Decide the threshold inside the finalize mutation cut, before commit_finalized marks the slot ready:

  • A rejected group is cleaned up like a structural finalizer drop: rows cleared, still-unready slot aborted. It is never selectable and its post-write enricher never runs.
  • In the same cut, take its replacement from the spare pool and, with rollout recovery, reserve the spare in the ledger. With no spare, credit the step short. A rollout snapshot therefore never sees the group gone without its replacement or shortfall credit.
  • _finalize_with_actor returns _BelowValidFraction for this case; the rollout pump dispatches the spare under the reserved lineage, or closes the step short.
  • Behaviour change: a rejected group is no longer committed, so it no longer counts toward committed_groups_per_second / committed_output_tokens_per_second. Those now match stats.committed, which already excluded it.

The first commit dropped the ready slot after the row clears. Review found that still left a window: while the clear RPCs were awaited, a starved train pump could claim the still-ready group, train on rows being cleared, and the later drop then raised unknown group_ids. The second commit replaces that approach, so drop_committed_group is gone.

Testing

  • test_below_threshold_group_never_becomes_selectable uses a real TQReplayBuffer and checks the slot is never ready during the clears, the group leaves the buffer, nothing is enriched, and the step is credited short.
  • test_below_threshold_replacement_is_reserved_in_the_cleanup_cut checks the ledger discard and the spare's reservation use the same cut, and that nothing is reserved when rollout recovery is off.
  • test_below_valid_fraction_outcome_substitutes_or_closes_short covers the pump side with a stamped step: it passes target_step and the replacement count into the finalize cut and adds no shortfall credit of its own. The row/owner counting rule is tested directly on _valid_fraction_counts.
  • Review injected three regressions (dropping those arguments, a double shortfall credit, reserving the spare with recovery off); each now fails a test.
  • test_finalizer_lifecycle.py, test_rollout_pump.py, test_tq_replay_buffer.py and test_checkpoint_dispatch_races.py pass locally (CPU), except one pump test that needs a HuggingFace download blocked in my environment.

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Oct 28, 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.

@joyang-nv joyang-nv added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Oct 28, 2026
@joyang-nv

Copy link
Copy Markdown
Member Author

/ok to test 5fcdfa4

@joyang-nv
joyang-nv force-pushed the joyang/sc-below-threshold-drop branch 2 times, most recently from 8cfcdd5 to d96d0e7 Compare November 2, 2026 06:36
@joyang-nv

Copy link
Copy Markdown
Member Author

/ok to test e191272

@joyang-nv
joyang-nv force-pushed the joyang/sc-below-threshold-drop branch from e191272 to c88336b Compare November 3, 2026 14:51

@jinglinglingling jinglinglingling 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 the fix. Deciding the threshold inside the finalize cut, before commit_finalized, closes both the dangling-slot bug and the train-pump race described in the second commit. No blocking issues.

Scope: the full diff at head c88336b.

Checked:

  • _finalize_with_actor has one production caller, the rollout pump, which handles all three outcomes; the shortfall is credited once.
  • The rejected slot is never marked ready, and abort() drops an unready slot.
  • The ledger discard, the spare's reservation, _replacement_reserve and _batch_shortfall change in one cut, and the last two are part of the rollout snapshot.
  • Rejected groups never populate _finalizer_metrics_by_group / _finalizer_rewards_by_group, so dropping the old pops is safe.

nit

  • Fix the "no spare prompt left" log, which is wrong under the default on_dropped_prompt: shrink.
  • Drop the defaults on target_step / replacements_used so that a forgotten argument fails loudly.

The main CI test jobs have not run on this head; the last /ok to test was on e191272. Validation here was source inspection only. The changed unit tests could not run locally, because Ray failed to start on a node without GPUs, and no GPU training was run.

Generated by Claude

Comment thread nemo_rl/algorithms/single_controller.py Resolved
Comment thread nemo_rl/algorithms/single_controller.py Resolved
joyang-nv and others added 3 commits November 12, 2026 18:22
…e commit

Dropping the slot after the row clears (previous commit) still left a
window: while the clear RPCs are awaited the slot is ready, so a starved
train pump can claim it and train on rows being cleared, and the later
drop then fails with "unknown group_ids".

Decide token_capture.min_valid_fraction_per_group inside the finalize cut,
before commit_finalized. A rejected group is cleaned up like a structural
finalizer drop (rows cleared, unready slot aborted), so it is never
selectable and never enriched; drop_committed_group is no longer needed.
Its replacement is taken in the same cut, and with rollout recovery the
spare's ledger reservation is too (or the step is credited short), so no
rollout snapshot sees the group gone without its replacement.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Jonas Yang <[email protected]>
Review injected three regressions the suite missed; each now fails:
- the pump dropping target_step / replacements_used when it calls
  _finalize_with_actor (replacement and shortfall silently disabled),
- the pump crediting a rejected step short a second time,
- reserving the spare's lineage with rollout recovery disabled, which
  the pump would then never discard.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Jonas Yang <[email protected]>
…ace test

_finalize_with_actor now requires target_step and replacements_used so that
a forgotten argument raises instead of silently disabling the replacement and
shortfall handling. test_rollout_trace still called it with neither.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: ruit <[email protected]>
@RayenTian
RayenTian force-pushed the joyang/sc-below-threshold-drop branch from c88336b to b9df420 Compare November 13, 2026 02:27
@RayenTian

Copy link
Copy Markdown
Contributor

/ok to test b9df420

@yuki-97

yuki-97 commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

closes since included in #5202

@yuki-97 yuki-97 closed this Nov 15, 2026
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.

4 participants