Skip to content

feat(single-controller): run SGLang generation on the SingleController - #5282

Merged
yuki-97 merged 7 commits into
NVIDIA-NeMo:mainfrom
shikicloud:shikiw/sc-sglang-generation
Nov 25, 2026
Merged

yuki-97 merged 7 commits into
NVIDIA-NeMo:mainfrom
shikicloud:shikiw/sc-sglang-generation

Conversation

@shikicloud

@shikicloud shikicloud commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor
  • I, the PR author, have personally reviewed every line of this PR.

What and why

Problem. SGLang generation had never run under the SingleController (the SGLang item of #5044). SingleControllerActor.remote(...) pickles the generation handle, and SGLangGeneration carries an event-loop thread, a loop-bound httpx.AsyncClient and the health-monitor thread (TypeError: cannot pickle '_contextvars.Context'). Split out of #5085, which keeps only the rollout-only simulator part.

Change.

  • SGLangGeneration.__getstate__ / __setstate__ (the DynamoGeneration precedent): the copy keeps the engine, router and lock actor handles and starts its own AsyncLoopThread. It does not own the engines; its shutdown releases only its loop and HTTP client. HttpClient.__getstate__ drops the loop-bound client; aclose_local closes it without killing the shared POST actors.
  • SGLangGeneration.validate_settings rejects, before any engine starts, what the SC cannot honor with SGLang: fault tolerance (the health monitor would restart engines in the driver while the copy drives stale handles; tracked in SingleController: support SGLang fault tolerance #5354), generation_fleet_health.enabled (vLLM-only) and a non-null generation_fleet_health.refit_timeout_s (SGLang cannot abort a refit; refused through reject_unenforceable_refit_deadline).
  • New exemplar examples/configs/grpo_math_1B_sglang_single_controller.yaml: the Megatron SC recipe with the generation block of grpo_math_1B_sglang.yaml, non-colocated (1 trainer GPU + 1 SGLang engine GPU), refit_timeout_s: null.
  • New smoke tests/functional/grpo_dp_single_controller_sglang.sh in L1_Functional_Tests_SGLang.sh.
  • New nightly grpo-qwen2.5-math-1.5b-instruct-2n4g-megatrontp1-sglang-noncolocated-single-controller (recipe and driver, listed in nightly_gb200.txt and nightly_mcore_gb200.txt): the SC twin of the legacy grpo-qwen2.5-math-1.5b-instruct-2n4g-megatrontp1-sglang-noncolocated nightly, with 4 trainer GPUs on one node and two tp_size 2 engines on the other node's 4, 90 steps. The nightly.txt GPU-hour budget is unchanged.
#5044 validation target Status on SC
grpo_sglang_async.sh Covered by the new smoke. It keeps that test's assertion (train/token_mult_prob_error < 1.05) and adds the SC gates of grpo_dp_single_controller.sh. Non-colocated, because SC colocation is Megatron-generation only.
grpo_sglang_fault_tolerance_chaos.sh Not covered. SGLang fault tolerance is rejected at SC setup: the health monitor restarts engines in the driver, and the SC actor's copy would keep the old handles. Tracked in #5354.
uv run python examples/run_grpo_single_controller.py \
  --config examples/configs/grpo_math_1B_sglang_single_controller.yaml

bash tests/functional/grpo_dp_single_controller_sglang.sh

Issues

Part of #5044 (SGLang generation on SC); does not close it. Follow-ups: SGLang fault tolerance on SC (#5354); the SC NeMo-Gym path still allows vllm/megatron only.

Convergence / perf / functionality proof

Smoke: GB200, one node, grpo_math_1B_sglang_single_controller.yaml with the smoke's overrides (Qwen3-0.6B, 2 prompts x 4 generations, 1 SGLang engine, Megatron TP1 on the second GPU), 20 steps.

SC + SGLang training, 20 steps value smoke gate
train/token_mult_prob_error, range 1.010 to 1.020 < 1.05
train/gen_kl_error, range 0.00040 to 0.00080 < 0.002
train/max_seq_mult_prob_error, max 1.027 < 1000
train/num_masked_seqs_by_logprob_error, max 0 == 0
timing/train/weight_sync s, mean 0.094
timing/train/exposed_generation s, mean of steps 2-20 0.687
timing/train/total_step_time s, mean of steps 2-20 4.66

Legacy path, same branch: grpo-qwen2.5-math-1.5b-instruct-1n4g-megatrontp1-sglang.yaml through run_grpo.py, 3 steps, train/token_mult_prob_error max 1.004.

Nightly: driver tests/test_suites/llm/grpo-qwen2.5-math-1.5b-instruct-2n4g-megatrontp1-sglang-noncolocated-single-controller.sh, 90 steps, on two GB200 nodes of 4 GPUs: 4 trainer GPUs on one, the two tp_size 2 engines on the other. The run was made before the rename, from the then-1n8g recipe with cluster.num_nodes=2 cluster.gpus_per_node=4, which is what the recipe now sets; the renamed files have not been rerun. The step-time bound is the legacy twin's. Non-colocated SGLang with tp_size above 1 on a single node is not covered here and is tracked in #5438.

SC + SGLang nightly, 90 steps value driver check
train/token_mult_prob_error, median 1.004 < 1.1
train/token_mult_prob_error, step 90 1.005 < 1.1
timing/train/total_step_time s, mean of steps 2-90 10.7 < 25
train/gen_kl_error, range 0.00010 to 0.00016
train/reward, mean of the first / last 10 steps 0.288 / 0.388
timing/train/weight_sync s, mean 0.147
timing/train/exposed_generation s, mean of steps 2-90 0.011
wall time with startup 21.8 min 45 min allocation

Testing on GB200 on this branch's tree (with main 5e27117 merged): pre-commit and pyrefly 1.4.0 clean; tests/unit/single_controller 2212 passed; the unmarked tests under tests/unit/models/generation/sglang 72 passed (after 25322c2); the new smoke passes its 8 checks. The nightly passes its 3 checks; it ran before the last edits (a typing cast, the 45 min limit with its budget number, the issue link in the error message; then, in 25322c2, the NotImplementedError for fleet health, the _owns_engines class default, the docs line and the nightly recipe header comment), which do not change the run. The head then merged main a03ffa1 and renamed the nightly to 2n4g (cb838df); on that tree, on GB200: test_recipes_and_test_suites.py 16 passed, config_cli.py minimize-check of the renamed recipe clean, the dry run of the renamed driver reports 6 GPU-hours, the unmarked SGLang tests 72 passed, and tests/unit/single_controller/test_setup.py 369 passed with 19 failures that are the same 19 on plain main a03ffa1 in my image (MOPD/OPD tests). The smoke and the nightly were not rerun on it. Not run locally: the SGLang-marked unit tests (--sglang-only) and the legacy SGLang functional tests, which train with Automodel; my image has neither environment.

Needs upstream changes

None

PR commands and CI
  • CI label, exactly one:
    • CI:Lfast: the default for most PRs. Runs a fast test subset.
    • CI:L1: dependency or container changes (pyproject.toml, uv.lock, Dockerfile) or broad core changes. Builds a new image and runs unit and functional tests.
    • CI:docs: docs-only changes. Runs doc tests only.
  • /ok to test <full-commit-sha>: start CI for that commit. Post again after each push.
  • /review: automated review comments. Add mode=strict for a stricter review, reset=true for a fresh full review.
  • /resolve-conflict: Autobot merges main into this PR and resolves the conflicts. PRs from forks must allow edits by maintainers.
  • Locally: /review-pr-team <pr-number> for a team review before you ask for human review.
  • Contributor guidelines

@copy-pr-bot

copy-pr-bot Bot commented Nov 18, 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.

@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; the PR is 74 commits behind and the "Check if PR branch is up to date" job allows at most 10.

This lands SGLang generation on the SingleController with a clean ownership story: the handle is pickled into the actor with an explicit owner/copy split, so the unpickled copy never tears down the shared engines, and fault tolerance, fleet health and a refit deadline are refused at setup before anything is built.

The 20-step GB200 run and its metrics table in the description make the refit-from-the-copy behaviour easy to check: token_mult_prob_error stays flat across refits.

Scope: the SGLang pickling/ownership change, validate_settings, the new SC SGLang exemplar, the smoke and the unit tests, at 98fe644

Checked:

  • pickled copy — __getstate__ drops only the loop thread and flips _owns_engines (sglang_generation.py:607–626); every method the SingleController actor and the SGLang synchronizer call on the copy reads intact state, and the driver instance keeps teardown (run_grpo_single_controller.py:245–255)
  • setup-time rejections — fault tolerance, fleet health and a refit deadline are refused in validate_settings (sglang_generation.py:82–112) before any cluster or engine is built; the existing SC colocated, Gym and token-capture rejections cover the other unsupported SGLang cells
  • test doubles — _owns_engines is assigned at sglang_generation.py:124 before any __init__ raise, so the object.__new__ double in test_config.py:196–201 still shuts down cleanly
  • smoke and exemplar — grpo_dp_single_controller_sglang.sh mirrors grpo_dp_single_controller.sh plus the legacy token_mult_prob_error gate and runs fast in the SGLang lane on H100 and GB200; the exemplar inherits the SC Megatron exemplar and overrides only the generation block and refit_timeout_s

nit

  • reusing the refit-deadline helper, which is the only place the deadline is enforced for SGLang on SC
  • a tracking issue for the fault-tolerance follow-up
  • a per-backend sub-list for the generation-backend bullet in the SC guide
  • a nightly test for SC + SGLang, matching the legacy non-colocated SGLang nightly

Generated by Claude Code

Comment thread docs/guides/single-controller.md Resolved
@yuki-97 yuki-97 added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Nov 21, 2026

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

Self review of this PR.

The design holds up:

  • The owner/copy split matches MegatronGeneration._owns_policy and is stricter than the vLLM/Dynamo copy: the copy never tears down shared engines.
  • __getstate__ overrides only two keys.
  • The aclose / aclose_local split lets the copy close only its own client.
  • Unsupported settings are refused at setup by each backend's own validate_settings hook, before anything is built.

yuki-97's 4 threads are all fixed as replied, and the rebase blocker is cleared (1 commit behind main).

Validation on GB200 at this commit: pre-commit and pyrefly clean; 2212 SC unit tests pass; 71 unmarked sglang unit tests pass, including the 3 new ones; the smoke passes 8/8 checks; the 90-step nightly passes 3/3. Not run: the --sglang-only unit tests and the legacy SGLang functional tests.

Inline comments:

  1. (C1) The guide names only the fault-tolerance requirement; it misses fleet health and refit_timeout_s: null, so switching the default exemplar to SGLang fails at setup.
  2. (C2) The pickling test's fake has no POST actors, so it cannot tell aclose() from aclose_local(); add one test.
  3. (C3) Raise NotImplementedError for fleet health, like the other backends, and update the test.
  4. (C4) Make _owns_engines a class default so shutdown() is safe on instances that never ran __init__.
  5. (C5) The nightly recipe is not a synchronous "twin": it runs one version ahead.

Follow-up, outside this PR: _check_single_controller_config never calls the backend validate_settings. This already applies to vLLM and Megatron; worth a tracking issue.

Generated by Claude Code

Comment thread docs/guides/single-controller.md Resolved

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

Self-review of 0ce198e.

All 4 threads from yuki-97 and the 5 comments from the previous self-review (C1–C5) were re-checked at 0ce198e and are fixed; none needs another reply. The PR-description wording from C5 stays as is, on purpose.

The pickled copy keeps the engine, router and lock handles but cannot shut them down, as with MegatronGeneration._owns_policy. Setup calls validate_settings once before anything is built, so it refuses fault tolerance, fleet health and a refit deadline up front.

Inline comments: none. No finding from this round reached the posting bar.

PR description fixes (not inline, since the description is not in the diff):

Not blocking, follow-ups outside this PR:

No tests were run for this review (no GPU or test environment on the review host). CI has not run on 0ce198e yet.

nemo-rl-review: kind=self harness=claude-code/2.1.331 model=claude-opus-5-5 effort=medium review-pr-team=v2 reviewed=0ce198e

@shikicloud

Copy link
Copy Markdown
Contributor Author

/ok to test 0ce198e

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

Thanks for resolving the comments from the previous round.

Scope: fix commits 243b72d through 0ce198e, checked against the open threads from the previous review, plus a scan of the changed files for new issues.

Checked:

  • previous comments — the refit-deadline helper, the #5354 citation and the per-backend docs sub-list all hold at the head
  • validate_settings — the only SingleController entry point runs it before anything is built (setup.py:1834), and the legacy entrypoints never call it, so legacy fault-tolerance runs are not rejected
  • changes merged from main since the last pass — the refit actor rejects SGLang at setup, and the other new SingleController options are off by default or gated to backends other than SGLang
  • CI at the head — the SingleController SGLang smoke passed its 8 metric checks, and the new pickling and setup tests ran and passed

nit

  • a run of the new nightly on the one-node shape it declares

nemo-rl-review: kind=expert harness=claude-code/2.1.331 model=claude-fable-5-2 effort=medium review-pr-team=v2 reviewed=0ce198e

…neration

Conflict: tests/unit/test_recipes_and_test_suites.py (nightly GPU-hour
budget). Takes main's 5524; the next commit moves this branch's nightly
out of nightly.txt, so the branch no longer raises the budget.

Signed-off-by: Shiki Wu <[email protected]>
The nightly result in the PR description came from two 4-GPU GB200 nodes
(4 trainer GPUs on one, two tp_size 2 engines on the other); the 1n8g
shape the driver declared has not run. Rename the recipe and driver to
2n4g, set cluster 2 x 4, and list them in nightly_gb200.txt and
nightly_mcore_gb200.txt instead of nightly.txt and nightly_mcore.txt.
The nightly.txt GPU-hour budget is main's again.

Signed-off-by: Shiki Wu <[email protected]>
shikicloud added a commit to shikicloud/RL that referenced this pull request Nov 25, 2026
…y-sglang

Sync with NVIDIA-NeMo#5282 cb838df (main a03ffa1 merged, SC SGLang nightly renamed
to 2n4g). Conflict in single_controller.py: main dropped the forest
completeness check before the empty-step error; keep this branch's
no_op_trainer guard on that error.

Signed-off-by: Shiki Wu <[email protected]>
@yuki-97

yuki-97 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

/ok to test cb838df

@yuki-97
yuki-97 enabled auto-merge (squash) November 25, 2026 13:35
@yuki-97
yuki-97 merged commit d93ba7d into NVIDIA-NeMo:main Nov 25, 2026
100 of 107 checks passed
shikicloud added a commit to shikicloud/RL that referenced this pull request Nov 26, 2026
…o feat/sglang-pd-disagg

Conflicts with NVIDIA-NeMo#5282 (SGLang on the SingleController), now on main:
- sglang_generation.py: validate_settings keeps main's SingleController
  checks and then refuses disaggregation; both sets of class defaults stay.
- grpo.py: both import groups.

Signed-off-by: Shiki Wu <[email protected]>
shikicloud added a commit to shikicloud/RL that referenced this pull request Nov 26, 2026
…elds

validate_settings now runs the SingleController checks of NVIDIA-NeMo#5282 before it
refuses disaggregation.

Signed-off-by: Shiki Wu <[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.

2 participants