feat: single controller e2e#2819
Draft
yuki-97 wants to merge 28 commits into
Draft
Conversation
mehraakash
added a commit
to mehraakash/RL
that referenced
this pull request
Jun 16, 2026
Two bugs around the split-API state machine fixed in one pass: 1. **no_sync_func leak (latent assertion on step 2 with PP=1).** `forward_backward_no_pipelining` (the PP=1 path, which is the common one) wraps inner microbatches in `model.config.no_sync_func` but runs the *last* microbatch OUTSIDE of it. Our outer `with self.model.no_sync():` in `train_microbatch` was therefore bypassed for the trailing MB. `register_grad_ready` leaked per-param counts past the explicit DP sync at `finish_train_step`, and the next `begin_train_step` then asserted on the stale counts (typically step 2). Fix: in `begin_train_step` also save and null `no_sync_func` (set to `contextlib.nullcontext`). Restore both hooks at finish/abort via the new `_restore_saved_grad_sync_func` helper. Spotted in yuki-97's PR NVIDIA-NeMo#2819 (`begin_train_step` also nulls `config.no_sync_func`); same fix landed here. 2. **No exception safety around the open step (terrykong, NVIDIA-NeMo#2683:640).** If `train_microbatch` or `finish_train_step` raised mid-body, both `grad_sync_func` and (now also) `no_sync_func` would stay nulled and future steps would run with the PP scheduler bypass disabled silently. Fix: extract `_train_microbatch_body` and `_finish_train_step_body`, wrap each entry method in try/except that calls `_restore_saved_grad_sync_func` before re-raising. Caller is still expected to invoke `abort_train_step` (idempotent on the saved values) to drop `_train_step_state`. 3. **Cleanup (terrykong, NVIDIA-NeMo#2683:582).** Drop dead `no_sync_active` field from `_split_step_state_init` — never read or written; `no_sync` is applied via the `with self.model.no_sync():` context manager. Also: add module-level `log = logging.getLogger(__name__)` so the try/except handlers can `log.exception(...)` if the restore itself fails. Signed-off-by: Akash Mehra <akamehra@nvidia.com>
36c7e50 to
44fc9a4
Compare
29 tasks
Signed-off-by: Yuki Huang <yukih@nvidia.com>
Signed-off-by: Yuki Huang <yukih@nvidia.com>
… reserve/commit slots Signed-off-by: Yuki Huang <yukih@nvidia.com> update unit test Signed-off-by: Yuki Huang <yukih@nvidia.com>
Signed-off-by: Yuki Huang <yukih@nvidia.com>
Signed-off-by: Yuki Huang <yukih@nvidia.com>
Signed-off-by: Yuki Huang <yukih@nvidia.com>
Signed-off-by: Yuki Huang <yukih@nvidia.com>
Signed-off-by: Yuki Huang <yukih@nvidia.com>
Signed-off-by: Yuki Huang <yukih@nvidia.com>
Signed-off-by: Yuki Huang <yukih@nvidia.com>
Signed-off-by: Yuki Huang <yukih@nvidia.com>
Signed-off-by: Yuki Huang <yukih@nvidia.com>
Signed-off-by: Yuki Huang <yukih@nvidia.com>
Signed-off-by: Yuki Huang <yukih@nvidia.com>
Signed-off-by: Yuki Huang <yukih@nvidia.com>
Signed-off-by: Yuki Huang <yukih@nvidia.com>
deb3b4b to
e0513e5
Compare
…um_prompts_per_step Signed-off-by: Yuki Huang <yukih@nvidia.com>
…unctional test buffer sizing Signed-off-by: Yuki Huang <yukih@nvidia.com>
Signed-off-by: Yuki Huang <yukih@nvidia.com>
e0513e5 to
1e0107e
Compare
Signed-off-by: Yuki Huang <yukih@nvidia.com>
…troller and grpo_async_gym_single_controller into it Signed-off-by: Yuki Huang <yukih@nvidia.com>
Signed-off-by: Yuki Huang <yukih@nvidia.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the SC (Single Controller) entrypoint for async GRPO on the TransferQueue data plane.
SingleControllerActor(nemo_rl/algorithms/single_controller.py): CPU-only Ray actor with three asyncio pumps._rollout_pump: iterates the dataloader →RolloutManager.generate_and_push→TQReplayBuffer.addwrites N training rows per group. Gated by_buffer_capacity/max_inflight_prompts/_rollout_permitted. Supports per-weight-version dispatch quota (over_sampling=false, reserve/commit slot accounting) and exact target-step matching (force_in_order=true)._train_pump:sampler.evict→sampler.select→_advantage_pump→TQPolicysplit API (begin/train_microbatch/finish_train_step) →dp_client.clear_samples. One RL step = one optimizer step ontrain_global_batch_size; enforced by an init-time assertionnum_prompts_per_step * num_generations_per_prompt == train_global_batch_size._sync_weights: drain gate +WeightSynchronizer.sync_weights, wired throughsetup_single_controller.single_controller_utils/(config.py/setup.py/utils.py):MasterConfig+AsyncRLConfig;setup_single_controller()builds the fullSingleControllerBundle(clusters / generation / trainer / weight synchronizer).async_utils/:TQReplayBuffer(group-granular, producer-side tensorization, reserve/commit slot accounting) +StalenessSampler(filter-only;strict_on_policy/staleness_window, optionalforce_in_order).examples/run_grpo_single_controller.py,examples/configs/grpo_math_1B_single_controller.yaml.tests/functional/grpo_dp_single_controller.sh(Qwen3-0.6B, 2 GPU, 2 steps).grpo-llama3.1-8b-instruct-2n8g-async-1off-single-controller(matches legacy async-1off) andgrpo-qwen2.5-math-1.5b-instruct-1n8g-megatron-single-controller.test_rollout_pump,test_single_controller_setup,test_staleness_sampler,test_tq_replay_buffer,test_megatron_split_state.begin_train_stepalso nullsconfig.no_sync_funcso the outermodel.no_sync()covers the last MB — otherwiseregister_grad_readyleaks counts past the explicit sync and asserts on step 2.Known limits (TODOs in code)
compute_prev_logprobs/compute_reference_logprobsgating is provisional.Current state
grpo_dp_single_controller.sh(Qwen3-0.6B, 2 GPU, 2 steps).Compared
grpo-llama3.1-8b-instruct-2n8g-async-1off-single-controllerwith legacy code with same setting (grpo-llama3.1-8b-instruct-2n8g-async-1off), didn't use mini batch for now.rewardis a bit lower, maybe caused bygrad_norm.grad_normis mismatch, investigating.