Skip to content

feat(sc): enable single-controller dynamic sampling - #4588

Merged
yuki-97 merged 12 commits into
mainfrom
ruit/dapo_dynamic_sampling_sc
Nov 10, 2026
Merged

yuki-97 merged 12 commits into
mainfrom
ruit/dapo_dynamic_sampling_sc

Conversation

@RayenTian

@RayenTian RayenTian commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds DAPO-style dynamic sampling to GRPO on the SingleController async path. Prompt groups with no reward signal under the configured masking policy are filtered and replaced. While data remains available, replacement keeps the target step at grpo.num_prompts_per_step groups; at final dataset exhaustion, the remaining batch is trained or skipped according to the configured minimum batch fraction.

Related issue: #1365.

Behavior

  • Filtering uses the rewards that participate under masked_reward_policy and overlong_filtering. Filtering and reward-metric helpers live in nemo_rl/experience/dynamic_sampling.py.
  • The rollout pump can borrow an eligible finished group from a later admitted step to fill an earlier step's shortfall. Raw replacement prompts come from a separate filtering pool. Its low-water mark is one dataloader batch (num_prompts_per_step), and it refills on demand even while admission or dispatch is blocked. There is no separate dynamic-sampling reserve-size setting.
  • grpo.dynamic_sampling_max_gen_batches bounds generation attempts for each target step, counting the original batch. This is independent of rollout-failure retry budgets and the fault-tolerance spare pool. Filtering works with either on_dropped_prompt: replace or shrink; rollout failure policy does not disable dynamic sampling.
  • At final exhaustion, an already admitted step trains if its remaining groups meet ceil(num_prompts_per_step * min_step_batch_fraction). Otherwise it discards accumulated gradients and skips the optimizer update. Skips advance the scheduling step/version, but not the optimizer or trained-sample count. Dataset iteration handles epoch transitions before declaring final exhaustion.
  • Rollout checkpoints save and restore the filtering pool, replacement/recovery state, shortfalls, and short-batch permissions. Replacement waits stay outside the checkpoint mutation barrier. A first skipped step can save model weights without attempting to save an optimizer that has never run.
  • Filtering, rollout failures, and skipped training steps have distinct metrics. In SC, train/reward remains the trained-rows mean; train/unfiltered_reward is the pre-filter progress signal. For V1 comparisons, align V1 reward with SC unfiltered_reward, and V1 filtered_reward with SC reward (naming alignment is tracked in Align v1's dynamic-sampling reward metrics with the SingleController naming #5039).

Supported configurations

  • GRPO with grpo.adv_estimator.name: grpo and at least two generations per prompt. PPO, Reinforce++, and OPD estimators are rejected for this filtering rule.
  • async_rl.sampler.name: in_order only. Other built-in samplers and custom are rejected; broader sampler support is tracked in feat(single-controller): support dynamic sampling for streaming sampler #4784.
  • token_capture.enabled: false. Token-capture cannot borrow a finished future group and is explicitly unsupported here.
  • Nonzero invalid_tool_call_advantage or malformed_thinking_advantage overrides are rejected; 0 and null remain supported.
  • SC requires grpo.batch_multiplier: 1; it batches prompts directly rather than using V1's batch multiplier.

Replacements consume ordinary dataloader prompts, so a finite epoch can produce fewer training steps than an unfiltered run. Increase max_num_epochs, or use null for unbounded epoch iteration, when a fixed step target requires more prompts.

Usage

grpo:
  use_dynamic_sampling: true
  num_prompts_per_step: 8
  num_generations_per_prompt: 8
  dynamic_sampling_max_gen_batches: 10
  batch_multiplier: 1
  adv_estimator:
    name: grpo

token_capture:
  enabled: false

async_rl:
  sampler:
    name: in_order
    max_lookahead_versions: 1
  rollout_failure:
    # At exhaustion, train only a full batch; otherwise skip the tail step.
    min_step_batch_fraction: 1.0

max_lookahead_versions: 1 permits one version of lookahead; it does not promise strictly on-policy rollouts. max_replacement_attempts and replacement_reserve_prompts remain rollout-failure controls, not dynamic-sampling tuning parameters.

See the dynamic-sampling guide for masking and metric semantics.

Nightly coverage and validation

Adds dapo-nanov3.5-30BA3B-4n8g-megatron-vllm-noncolocated-single-controller.yaml and its matching nightly driver: Nano3.5, DAPOMath17K, Megatron training (TP1/CP1/EP8), vLLM generation (TP4), and non-colocated 16-GPU training / 16-GPU generation. The driver runs 10 steps. Reward scaling (#4878) and reward shaping (#4882) remain disabled pending those PRs; their enablement comments are retained in the recipe.

The four-node validation run xvci4dbb completed all 10 training steps. Its exported metrics passed all 11 updated checks when rerun locally. The original post-run check invocation failed because of an inherited broken virtual-environment interpreter path, so this is not claimed as a successful end-to-end nightly invocation.

Metric Observed Nightly check
Token probability-error median / maximum 1.01593 / 1.01853 < 1.02 / < 1.025
Unfiltered reward median 0.53125 > 0.48
Step time median / maximum 622.9s / 907.0s < 700s / < 1100s
Filtered zero-variance groups per step 7–16 Cumulative FILTERED total >= 50
Skipped steps / dropped prompt groups 0 / 0 0 / 0

The checks also require 10 recorded training losses and finite loss/probability-error metrics. Nightly timeout is 140 minutes; the current-head suite's dry-run budget is 5310 GPU-hours against a 5310-hour cap.

Unit regressions cover filtering and masking, independent budgets, admission/refill wakeups, epoch exhaustion, tail training/skipping, checkpoint cuts and recovery, and reward metrics. GPU checkpoint probes verified nonempty-pool save/restore and tail-step skipping, including a first skipped step with no optimizer update. The CI retry-fixture regression and related generation-failure tests pass locally (89 tests) after the latest rebase. CI has been requested for the latest pushed revision; its result is not claimed here.

V1 / SC comparison

The following plot is retained as the earlier non-token-capture comparison of V1 synchronous and SC asynchronous dynamic sampling. It is not evidence for the current four-node nightly configuration; reward curves need the metric-name alignment described above.

Earlier V1 synchronous versus SC asynchronous dynamic-sampling comparison

Nightly Test Result

image

@copy-pr-bot

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

@cmunley1

Copy link
Copy Markdown
Contributor

Tried this with Lightning 3.5 SingleController, ready_first, token_capture.enabled=true, GBS 4096. The filter never fired. Committed groups were 32.9% zero-variance, same as the run without it (32.7%), and dropped_prompt_groups stayed 0.

With token capture the pump calls generate_for_finalization and hands off to the finalizer actors (single_controller.py, around L1596). It never calls generate_and_push, where the check lives. Should the check move before the finalizer commit?

Also, ready_first stamps no step, so on_dropped_prompt=replace does nothing. Does a filtered group still use up an admission slot with no refund? At ~33% I'd expect the window to starve after a few steps. Has this run past 3 steps? Logging zero_variance_groups as a metric would make a no-op like this visible.

@RayenTian
RayenTian force-pushed the ruit/dapo_dynamic_sampling_sc branch from d7434e7 to 46ce5b8 Compare October 13, 2026 03:18
@smahdavi4

Copy link
Copy Markdown
Contributor

Can we also have a metric to keep track of the reward before dynamic sampling? it would be very useful because in dynamic sampling train/reward might stay flat while the model is still learning.

@RayenTian
RayenTian force-pushed the ruit/dapo_dynamic_sampling_sc branch from 46ce5b8 to 97782d0 Compare October 15, 2026 05:44
@RayenTian RayenTian added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Oct 15, 2026
@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Oct 15, 2026
@RayenTian
RayenTian force-pushed the ruit/dapo_dynamic_sampling_sc branch from 32cc804 to 77b759a Compare October 16, 2026 06:42
@RayenTian

Copy link
Copy Markdown
Contributor Author

/ok to test 8e98c7c

@RayenTian
RayenTian force-pushed the ruit/dapo_dynamic_sampling_sc branch from 8e98c7c to e55ff23 Compare October 19, 2026 04:32
@RayenTian

Copy link
Copy Markdown
Contributor Author

/ok to test e55ff23

@RayenTian

Copy link
Copy Markdown
Contributor Author

/ok to test 0b888b4

@RayenTian
RayenTian marked this pull request as ready for review October 19, 2026 08:47
@RayenTian

Copy link
Copy Markdown
Contributor Author

/ok to test 4a29761

@RayenTian
RayenTian requested a review from yuki-97 October 19, 2026 13:58
@RayenTian RayenTian changed the title feat: enable single-controller dynamic sampling feat(sc): enable single-controller dynamic sampling Oct 19, 2026
@RayenTian

Copy link
Copy Markdown
Contributor Author

Self review with agent is down. @pthombre would you please take a look at the token capture changes? @saumishr would you please also review the reserved prompt group changes? @yuki-97 would you please help review on the single controller part? Thank you all a lot!

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

Merge blockers — please rebase on main and resolve conflicts.

Thanks for bringing dynamic sampling to the single-controller path, and for the clear write-up of its scope and limitations.

Great to see the V1-vs-V2 and token-capture-vs-not runs posted in the description; the effect of the filter can be read straight off them.

Scope: the structure of the single-controller dynamic sampling path, at 4a29761. A detailed review will follow once the two comments below are addressed.

Remaining comments are on:

  • Moving token-capture support to a follow-up PR that borrows from later steps like the non-capture path
  • A dynamic-sampling budget of its own, counted separately from rollout fault tolerance

Comment thread nemo_rl/algorithms/single_controller.py Resolved
RayenTian added a commit that referenced this pull request Oct 29, 2026
Addresses both review comments on #4588.

Scope it to the non-capture path. On the token-capture path a replacement
cannot borrow a finished group from a later step the way the non-capture path
does, so every drop waits out a full fresh rollout with the trainer idle.
Dynamic sampling makes drops routine, so that cost would land on every step.
Setup now rejects use_dynamic_sampling together with token_capture.enabled,
and FinalizedGroup.zero_variance goes away with the capture-side filtering.
Mirroring the borrow on that path is its own change.

Separate the budgets. A zero-variance drop is a data decision about a rollout
that succeeded, not a rollout failure, so sharing the fault-tolerance knobs let
each kind of drop redefine the other. generate_and_push now returns a distinct
RolloutOutcome.FILTERED, counted against the new
grpo.dynamic_sampling_max_replacements_per_slot rather than
max_replacement_attempts. Filtering no longer reads on_dropped_prompt: a
uniform group is never worth training on, so it is replaced under "shrink" too
and the spare pool is filled either way. Exhausting the budget raises, as v1
does past dynamic_sampling_max_gen_batches, instead of crediting a shortfall
against min_step_batch_fraction; an empty pool still shrinks, since that is the
dataloader ending rather than a mis-tuned filter.

The default budget of 32 is sized from the drop rate, not from how many
resamples feel reasonable: a slot exhausts it with probability p**(N+1), and
every slot of every step takes that draw. At 32 a 4096-group step over 1000
steps is quiet below roughly a 78% drop rate, well clear of the ~33% seen in
practice, and raises above it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: ruit <[email protected]>
@RayenTian
RayenTian force-pushed the ruit/dapo_dynamic_sampling_sc branch from 4a29761 to 3bfe02f Compare October 29, 2026 01:36
@RayenTian

Copy link
Copy Markdown
Contributor Author

/ok to test 83f4879

@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team October 29, 2026 09:09
RayenTian added a commit that referenced this pull request Oct 29, 2026
Addresses both review comments on #4588.

Scope it to the non-capture path. On the token-capture path a replacement
cannot borrow a finished group from a later step the way the non-capture path
does, so every drop waits out a full fresh rollout with the trainer idle.
Dynamic sampling makes drops routine, so that cost would land on every step.
Setup now rejects use_dynamic_sampling together with token_capture.enabled,
and FinalizedGroup.zero_variance goes away with the capture-side filtering.
Mirroring the borrow on that path is its own change.

Separate the budgets. A zero-variance drop is a data decision about a rollout
that succeeded, not a rollout failure, so sharing the fault-tolerance knobs let
each kind of drop redefine the other. generate_and_push now returns a distinct
RolloutOutcome.FILTERED, counted against the new
grpo.dynamic_sampling_max_replacements_per_slot rather than
max_replacement_attempts. Filtering no longer reads on_dropped_prompt: a
uniform group is never worth training on, so it is replaced under "shrink" too
and the spare pool is filled either way. Exhausting the budget raises, as v1
does past dynamic_sampling_max_gen_batches, instead of crediting a shortfall
against min_step_batch_fraction; an empty pool still shrinks, since that is the
dataloader ending rather than a mis-tuned filter.

The default budget of 32 is sized from the drop rate, not from how many
resamples feel reasonable: a slot exhausts it with probability p**(N+1), and
every slot of every step takes that draw. At 32 a 4096-group step over 1000
steps is quiet below roughly a 78% drop rate, well clear of the ~33% seen in
practice, and raises above it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: ruit <[email protected]>
@RayenTian
RayenTian force-pushed the ruit/dapo_dynamic_sampling_sc branch from a88bc72 to ede988d Compare October 29, 2026 10:02
@RayenTian

Copy link
Copy Markdown
Contributor Author

/ok to test ede988d

@RayenTian

Copy link
Copy Markdown
Contributor Author

/ok to test af69573

Give dynamic sampling an independent raw-prompt pool with an internal one-PPS low-water mark. Refill while admission or dispatch is blocked, notify consumers on replenishment and EOF, and bound initial plus replacement generation with dynamic_sampling_max_gen_batches.

Signed-off-by: ruit <[email protected]>
Wait for filtered replacements outside checkpoint mutation ownership. Recheck the pool after acquiring the cut and keep prompt consumption and ledger transfer atomic, charging each replacement once. Exercise empty-pool, checkpoint and competing-consumer races.

Signed-off-by: ruit <[email protected]>
At genuine data exhaustion, train only when retained groups meet ceil(PPS * min_step_batch_fraction); otherwise abort accumulated gradients and skip the optimizer update. Release consumed data, advance scheduling, and preserve checkpoint publication without ranking a skipped step by missing metrics.

Signed-off-by: ruit <[email protected]>
Move reward participation, the shared zero-signal predicate, per-step reward state and record/drain implementations into experience/dynamic_sampling.py. Keep RolloutManager methods as thin delegates and route v1 and SC through the same predicate. Include the module in static type checking.

Signed-off-by: ruit <[email protected]>
Add the Nano 3.5 Megatron/vLLM DAPOMath17K H100 two-node single-controller nightly. Set memory requirements in its CONFIG, place outputs under logs/results, and calibrate checks and the 140-minute budget against the completed ten-step run.

Signed-off-by: ruit <[email protected]>
Share rollout masking helpers, align dynamic-sampling documentation and diagnostics, and remove the unpublished reserve-setting migration. Refill filtering pools during restored rollout waits and require actual filtered outcomes in nightly validation.

Signed-off-by: ruit <[email protected]>
@RayenTian
RayenTian force-pushed the ruit/dapo_dynamic_sampling_sc branch from 95a3381 to a23b936 Compare November 10, 2026 10:44
@RayenTian

Copy link
Copy Markdown
Contributor Author

/ok to test a23b936

@RayenTian

RayenTian commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Quote reply to @yuki-97's review:

thanks for resolving these, only nits on dead code and docs, and let's wait the nightly result after changing to maybe_refill before merge.

The full 10-step nightly with maybe_refill completed successfully, and all 11 metric checks passed.

W&B: https://wandb.ai/nvidia/nemo-rl-dapo-v1v2/runs/walvuqel

Tested commit: 95a3381.

Image

@RayenTian
RayenTian requested a review from yuki-97 November 10, 2026 11:10
@yuki-97
yuki-97 merged commit fc009e6 into main Nov 10, 2026
108 of 114 checks passed
@yuki-97
yuki-97 deleted the ruit/dapo_dynamic_sampling_sc branch November 10, 2026 13:41
RayenTian added a commit that referenced this pull request Nov 14, 2026
…recipe

Replace the Megatron-generation 2n8g DAPO capture nightly with one that inherits
the #4588 dynamic-sampling recipe (Lightning-30B, Megatron training, vLLM
generation, 4n8g) and routes the math task through NeMo-Gym (OpenMathReasoning via
math_with_judge) so token capture is exercised on the faster vLLM path. MAX_STEPS=5
and the check_metrics thresholds are calibrated on a completed Gym run (unfiltered
reward ~0.25, token_mult_prob_error median 1.018/max 1.029, ~1040s/step). Nightly
GPU-hour budget stays under 5310 (5283).

Signed-off-by: ruit <[email protected]>
RayenTian added a commit that referenced this pull request Nov 14, 2026
…recipe

Replace the Megatron-generation 2n8g DAPO capture nightly with one that inherits
the #4588 dynamic-sampling recipe (Lightning-30B, Megatron training, vLLM
generation, 4n8g) and routes the math task through NeMo-Gym (OpenMathReasoning via
math_with_judge) so token capture is exercised on the faster vLLM path. MAX_STEPS=5
and the check_metrics thresholds are calibrated on a completed Gym run (unfiltered
reward ~0.25, token_mult_prob_error median 1.018/max 1.029, ~1040s/step). Nightly
GPU-hour budget stays under 5310 (5283).

Signed-off-by: ruit <[email protected]>
RayenTian added a commit that referenced this pull request Nov 14, 2026
…recipe

Replace the Megatron-generation 2n8g DAPO capture nightly with one that inherits
the #4588 dynamic-sampling recipe (Lightning-30B, Megatron training, vLLM
generation, 4n8g) and routes the math task through NeMo-Gym (OpenMathReasoning via
math_with_judge) so token capture is exercised on the faster vLLM path. MAX_STEPS=5
and the check_metrics thresholds are calibrated on a completed Gym run (unfiltered
reward ~0.25, token_mult_prob_error median 1.018/max 1.029, ~1040s/step). Nightly
GPU-hour budget stays under 5310 (5283).

Signed-off-by: ruit <[email protected]>
yfw added a commit that referenced this pull request Nov 21, 2026
…mpling under exclude_infra

main's SingleController dynamic sampling (#4588, #5202) decides whether
a group carries signal from its voting rewards (voting_rewards). It
treated exclude_infra like include, so an infrastructure-failed row
still voted there although the advantage stage leaves it out. With
rewards [0 (infra), 1, 1] the group was kept as mixed, and every row's
advantage was then 0.

voting_rewards now takes the exclude_infra flags
(rollouts.infra_failure_flags) and drops the flagged rows:
- native path: RolloutManager._voting_rewards computes them from the
  completions with grpo.policy_failure_kinds;
- token-capture path: the finalizer carries them per reward row as
  FinalizedGroup.reward_infra_failure.
Under include and exclude nothing changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
alexandery-nvidia added a commit that referenced this pull request Nov 24, 2026
…ompts

One conflict, in tests/unit/experience/test_rollouts.py. Both sides
changed the end of the file. main rewrote
test_mask_sample_flags_read_either_form_of_the_flag (#4588) and appended
test_restored_turn_is_dispatched_to_its_checkpoint_owner (#4500). This
branch appended _postprocess_rollouts and
test_postprocess_nemo_gym_group_counts_distinct_first_prompts. Both stay:
main's tests first, then this branch's helper and test.

Signed-off-by: alexandery <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
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.

5 participants