Repository navigation
feat: SGLang prefill/decode disaggregation for GRPO rollouts - #5086
shikicloud wants to merge 27 commits into
Conversation
Signed-off-by: Shiki Wu <[email protected]>
shikicloud
left a comment
There was a problem hiding this comment.
This review covers only the SGLang commit 0dc56ac. The vLLM part of the stack is #4920 and was reviewed there.
Merge state. The branch conflicts with main, but every conflict is in #4920's files (vllm_worker.py, trtllm_disagg_server.py, and tests/unit/L0_Unit_Tests_Vllm_{1,2,3}.sh). Please rebase #4920 first. After the rebase, re-run the nightly GPU-hour test for C5, since main's nightly list may have moved.
Merge order with #5085. #5085 moves SingleController sizing into _inference_gpus_per_instance(), which still reads gpus_per_server. Whichever PR lands second must carry sglang_replica_width into it.
The shape of this commit is good: plan_sglang_engines reuses plan_engines and a small SGLangEngineSpec value object; validation in the SGLangGeneration constructor reaches every entrypoint; the setup-time refusals of retract and power_of_two match what upstream enforces; using the sglang router's PD mode keeps /generate unchanged; prefill engines pause first and resume last; the invalidate_kv_cache result is checked before refit. All 89 new CPU tests pass.
- (C1) Forced
abortpause mode is unsafe on the SingleController entrypoint, which refits with rollouts in flight; addSGLangGeneration.validate_settingsand fix the comment. - (C2)
plan_sglang_engineslets an engine straddle two nodes; refuse it at planning time and add tests. - (C3) Role override
num_continuous_decode_stepsis never passed to SGLang; forward it and replace the identity test. - (C4)
transfer_backend: fakekills every prefill engine at startup; drop it. - (C5) The new nightly entry breaks the GPU-hour cap test; raise the cap to 5221.
- (C6) The PD recipe is not minimized, so Lint fails.
- (C7) pyrefly
bad-returninresolve_sglang_role_overrides; wrap incast. - (C8) pyrefly
bad-assignmentondist_init_addr; annotate it. - (C9) With fault tolerance on,
ReplicaDispatcher.acquiresends most prompts to a router whose engine is dead. - (C10)
SGLangRoleEngineArgsis a new TypedDict config; make it a pydanticBaseModel. - (C11) The
cache_awareprefix-affinity comment is wrong, because NeMo RL sends token ids only. - (C12) The
pp_sizeerror message gives the wrong reason. - (C13) The design doc intro still describes two backends.
- (C14) Dead
nodes_per_engineandgetattrfallbacks kept only for tests. - (C15) The new
grpo.setupbranches have no tests. - (C16) Long in-function comment blocks, one with a wrong claim about the NeMo-Gym gate.
- (C17) No performance or convergence numbers, and the nightly gates would pass with PD off.
Generated by Claude Code
Brings NVIDIA-NeMo#4920's review rounds 2 and 3 and origin/main 4f39fd8 (merged there) under the SGLang disaggregation commit. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Shiki Wu <[email protected]>
Picks up the import cleanup that followed the main merge on NVIDIA-NeMo#4920. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Shiki Wu <[email protected]>
Brings in the two fixes found while running the vLLM disaggregation nightly recipe end to end: the trainer adopting the disaggregated engines' NCCL transport for the refit collective, and the Qwen3 tool-call parser in the vLLM nightly recipe. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Shiki Wu <[email protected]>
With sglang_cfg.disagg.transfer_backend=nixl the engines run with NCCL_NET_PLUGIN=none and the training workers did not, so the refit process group spanned two NCCL transports and the first weight broadcast never completed: a 4-node GRPO run sat in update_weights_from_distributed for two hours. The training workers now adopt the engines' value, as on the vLLM path (sglang_refit_peer_env). disagg_transport_env moves from sglang_generation.py to sglang/config.py so the trainer can import it without the generation module, and the list of NCCL variables both sides must share moves to disagg_layout.REFIT_PEER_ENV_KEYS for the two backends. With the broadcast working, the same run lost its engines at the end of the first refit: under nixl the memory saver (sglang_server_config.needs_offload) cannot re-acquire the KV cache it released (CUDA out of memory in resume_memory_occupation). validate_sglang_disaggregation now refuses that combination at setup. With needs_offload=false the nixl run trains (3 steps, token_mult_prob_error 1.003-1.004, gen_kl_error 1.1e-4). The default mooncake transport is affected by neither. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Shiki Wu <[email protected]>
Brings in the vLLM PD branch after its merge with main (c33a104). Conflicts: - nemo_rl/models/megatron/setup.py: keep both new imports (sampler_replay_enabled from main, sglang_refit_peer_env from this branch). - tests/unit/test_recipes_and_test_suites.py: take main's nightly limit of 5310 GPU hours; with the SGLang PD nightly the suite totals 5222. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Shiki Wu <[email protected]>
Brings in main (e6449ae) through the vLLM PD branch (47fdef5). - docs: pd-disaggregation-rollout.md keeps the SGLang text, unwrapped to main's one-line paragraphs. - tests: the nightly budget goes from 5516 to 5524 GPU hours. main and the vLLM PD nightly now add up to exactly 5516, and the SGLang PD nightly (2 nodes x 8 GPUs x 30 minutes) adds 8. Signed-off-by: Shiki Wu <[email protected]>
Signed-off-by: Shiki Wu <[email protected]>
Signed-off-by: Shiki Wu <[email protected]>
Signed-off-by: Shiki Wu <[email protected]>
Signed-off-by: Shiki Wu <[email protected]> # Conflicts: # pyrefly.toml
Signed-off-by: Shiki Wu <[email protected]> # Conflicts: # nemo_rl/models/automodel/setup.py
main checks every file with pyrefly 1.4.0 against a baseline, so sglang_generation.py is type-checked for the first time and reported four errors in the disaggregation path: the role block assigned to the typed `sglang_cfg` key, the engine specs passed as a Sequence to a helper that asked for a list, and the init kwargs dict inferred too narrowly to take the disaggregation kwargs and the role literal. Signed-off-by: Shiki Wu <[email protected]>
Signed-off-by: Shiki Wu <[email protected]>
…/ decode_router Signed-off-by: Shiki Wu <[email protected]>
shikicloud
left a comment
There was a problem hiding this comment.
Self-review of a855eac (round 2).
Round-1 threads: all 17 (C1–C17) re-checked at head. Every fix holds, and the commits since eb40bf3 regressed none of them.
The design holds up: the engine-spec layout in layout.py, which fault tolerance and the weight-sync world size read; ReplicaDispatcher; REFIT_PEER_ENV_KEYS moved to the shared module; role keys derived from the model, with test_every_role_override_key_reaches_the_server_args checking that every one reaches ServerArgs; and validate_settings refusing the SingleController entrypoint. The upstream calls match sglang 3003d70f and sglang-router 0.3.2 (release commit 3f44268f): server args, the router's PD args, /workers registration, what abort does, and weight update under PD. The perf evidence covers what C17 asked, and the 14% / 1.7x numbers check out.
Inline comments:
- (C18) With
router_scope: replica, a request in flight on a replica whose engine dies cannot reach a live engine, so the sync GRPO step raises. Retry on another usable router ingenerate_one_sample; patch and three tests included. - (C19)
test_pause_is_prefill_then_decode_and_resume_is_the_reversepasses for a one-batch pause too; add a two-replica test that records eachray.getbatch. - (C20) The design doc and the
disagg_layout.pydocstring still say "both backends".
PR description fixes (not inline, since the description is not in the diff):
- "Three 90-step runs of 8cad6ab (this branch with main e6449ae merged) on GB200, 4 nodes x 4 GPUs (8 training + 8 inference GPUs)" and "the nightly recipe (2 replicas of 1 TP2 prefill + 1 TP2 decode, one router per replica)": the committed recipe is 2 nodes x 8 GPUs (
gpus_per_node: 8). List the overrides used for these runs, and say that the committed file as-is, including the < 25 s step-time gate, has not run; its first nightly is that check. - "Training does not see the split: reward and the mismatch metrics match within noise.": add that the validation accuracy spread at step 90 (0.480 / 0.430 / 0.398) comes from a single seed and is not attributed to PD.
- The "Unit tests" section: add that
test_generation_disaggregated_sglang_shares_the_nccl_transporthas not run anywhere (no venv in the test image importsnemo_automodel; CI's automodel lane is its first run), and that the megatron refit-env selection withtest_refit_environment_follows_disaggregated_sglang_enginesran (7 passed).
Not blocking (low; for a follow-up or the author's call):
- The nvidia-peermem probe (
disagg_transport_env) runs in the driver, not on the engine node. Only "the driver has the module, the engine node does not" breaks Mooncake. Probe inSGLangGenerationWorkerbefore the server launch. - A fixed
sglang_router_config.sglang_router_port(read here) withrouter_scope: replicamakes N routers bind one port. It fails loudly at startup; refuse it when more than one router starts. - Pre-existing:
sglang_router.pysetsrouter_args.router_policy, but theRouterArgsfield ispolicy, so a user who sets it gets a TypeError at router start. The router tests fakeRouterArgswithSimpleNamespace, which hides it. - The nixl +
needs_offloadrefusal could cite that SGLang'sNixlKVManagerhas noderegister_buffer_to_engine(nixl/conn.py), so it can be lifted once upstream adds it. - Follow-ups: SGLang has no branch in
configure_generation_config(vLLM and TRT-LLM do); a consistency test for the four values copied from sglang / sglang-router; one refit-env helper for the megatron and automodel setup; move the aggregated path onto the spec-driven port allocator (_allocate_disagg_engine_addr_and_ports); the replica-widthifchain exists three times (grpo.py, single_controller_utils/setup.py, ppo.py), and ppo.py still readsgpus_per_server, which is unreachable under PD.
Tests run: unit + lint at this head on GB200 (job 3827839: ruff clean, pyrefly 0 errors, test_sglang_disagg.py 50 passed, sglang config/FT 68, grpo 512, recipes 463); GPU smoke at this head on one GB200 node (job 3828051, mooncake: aggregated 11/11, r2/g2/tp2/p1d3 12/12); suggested-test and mutation runs on GB200 (jobs 3830616, 3830692); lint of the C18 patch (job 3830744).
nemo-rl-review: kind=self harness=claude-code/2.1.331 model=claude-opus-5-5 effort=medium review-pr-team=v3 reviewed=a855eac
- generate_one_sample retries a failed request on another usable router; with router_scope: replica a request in flight on a replica that lost an engine could not reach a live engine at any retry layer. One-router setups raise the original error as before. - test that decode engines are paused only after every prefill engine has returned, on two replicas with a ray.get that records each batch. - the design doc and the disagg_layout docstring name every backend, not two. Signed-off-by: Shiki Wu <[email protected]>
…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]>
Brings the fix for the two names the merge of main left undefined in the TRT-LLM backend. Signed-off-by: Shiki Wu <[email protected]>
…elds validate_settings now runs the SingleController checks of NVIDIA-NeMo#5282 before it refuses disaggregation. Signed-off-by: Shiki Wu <[email protected]>
Brings the test-stub fixes for the weight-sync and real-quant tests. Signed-off-by: Shiki Wu <[email protected]>
SGLangGeneration pauses, flushes and resumes through the engine specs since the disaggregation layout; an instance built without __init__ has none. Signed-off-by: Shiki Wu <[email protected]>
main alone now uses 5524; the SGLang prefill/decode nightly adds 8. Signed-off-by: Shiki Wu <[email protected]>
|
/ok to test bcdbbd2 |
Signed-off-by: Shiki Wu <[email protected]>
|
/ok to test a3bdf08 |
Signed-off-by: Shiki Wu <[email protected]>
|
/ok to test 7e8afd8 |
Conflict in tests/unit/test_recipes_and_test_suites.py: main raised the nightly budget to 5722 GPU hours; this branch's SGLang nightly adds 8, so the cap is 5730 (tools/launch dry run reports 5730). Signed-off-by: Shiki Wu <[email protected]>
|
/ok to test 574450f |
Signed-off-by: Shiki Wu <[email protected]>
|
/ok to test b27fd41 |
What and why
Adds prefill/decode (PD) disaggregation to the SGLang generation backend for synchronous GRPO rollouts, on the shared
generation.disaggregationlayout of #4095 (TRT-LLM) and #4920 (vLLM).Stacked on #4920 (
disagg_layout.py/DisaggConfigcome from there): the base branch isshikiw/vllm-pd-disagg, a copy of #4920's head, so this diff shows the SGLang changes only. The base goes back tomainonce #4920 merges.SGLang needs no frontend of NeMo RL's: the sglang router's PD mode pairs every
/generaterequest with one prefill and one decode engine, stamps the KV handshake on it and relays the decode output. The rollout keeps posting token ids to/generateas without disaggregation, so this path needs no NeMo-Gym and is refused with it.What changes:
sglang_cfg.prefill_engine/sglang_cfg.decode_engine: per-role engine overrides (SGLangRoleEngineArgs), type-checked at setup.sglang_cfg.disagg(SGLangDisaggConfig):router_scope(replicadefault,global),transfer_backend(mooncake default, nixl, mooncake_tcp),ib_device,prefill_router/decode_router(the sglang router's per-role policy, under the key names of the vLLM frontend block),decode_enable_radix_cache.sglang/utils/layout.py): role, width, node slots, replica and router group per engine; prefill and decode widths may differ; no engine may straddle a node boundary. Fault tolerance and the weight-sync world size read the specs.worker_typeandbootstrap_port. Withrouter_scope: replica,disagg_dispatch.pykeeps the samples of one prompt on one router, sends new prompts to the least-loaded usable router, and skips a router whose replica lost an engine until the refit restarts it._allocate_disagg_engine_addr_and_ports) for server/NCCL/dist-init/bootstrap ports from the reserved generation band.pause_generation_mode: abort; refits run between steps on idle engines, soabortdrops nothing.validate_sglang_disaggregation): non-colocated only, no NeMo-Gym, no external router,pp_size: 1,abort, nopower_of_two.SGLangGeneration.validate_settingsrefuses disaggregation on the SingleController entrypoint (it refits with rollouts in flight, andabortwould return cut-off requests as finished samples).grpo-qwen2.5-math-1.5b-instruct-2n8g-megatrontp1-sglang-pd-disagg.yaml+ nightly driver, exemplar keys ingrpo_math_1B_sglang.yaml, SGLang section indocs/design-docs/pd-disaggregation-rollout.md. Nightly GPU-hour cap 5524 -> 5532 (main alone uses 5524; this nightly adds 8).Behavior note for the aggregated path: SGLang inference-topology sizing read an undefined
gpus_per_serverkey (always 1); it now usessglang_server_config.num_gpus_per_engine, which only changes placement for engines wider than a node.Usage
Issues
Follow-up to #4095 and #4920. Async GRPO with SGLang is out of scope (#3127 adds the backend; under PD it would also need sglang's retract-in-PD or a keep-KV pause).
Convergence / perf / functionality proof
Three 90-step runs of 8cad6ab (this branch with main e6449ae merged) on GB200, 4 nodes x 4 GPUs (8 training + 8 inference GPUs), Qwen2.5-Math-1.5B-Instruct on OpenMathInstruct-2, 512 samples per step, same seed:
...-sglang-noncolocated(4 TP2 engines on the same 8 GPUs).router_scope=global.Overrides against the nightly driver: the 4-GPU-node layout (
cluster.num_nodes=4 cluster.gpus_per_node=4, inference on 2 x 4 GPUs), checkpointing and W&B off. The committed recipe as-is (2 nodes x 8 GPUs), including its < 25 s step-time gate, has not run; its first nightly is that check.Nightly checks of
grpo-qwen2.5-math-1.5b-instruct-2n8g-megatrontp1-sglang-pd-disagg.shon the PD run, all pass: mediantoken_mult_prob_error1.0040 (< 1.1), last step 1.0044, meangen_kl_error1.28e-4 (< 0.001), mean step time 11.0 s (< 25), prefill and decode engines logged.Convergence and throughput
Warm-up steps 1-3 excluded from the timing means.
token_mult_prob_error, median / lastgen_kl_error, mean / maxTraining does not see the split: reward and the mismatch metrics match within noise. The validation accuracy spread at step 90 (0.480 / 0.430 / 0.398) comes from a single seed and is not attributed to PD. On this decode-heavy workload PD gives half its GPUs to prefill and generates 14% fewer tokens/s, while each decode GPU produces 1.7x the tokens.
router_scope: globalis within noise ofreplica.GPU smoke
GPU smoke on one GB200 node (Qwen3-0.6B, sglang 0.5.17.dev30, sglang-router 0.3.2): aggregated baseline 11/11; PD layouts
r2(2 replicas of 1P+1D TP1),tp2(1P+1D TP2) andp1d3(1P + 3D TP1) 12/12 each with mooncake, nixl and mooncake_tcp (registration, greedy generation, sticky dispatch, logprobs, pause/flush/continue, decode-engine kill + recovery, shutdown). Greedy parity with the aggregated TP1 baseline: 8/8 token-identical forr2andp1d3;tp2differs by TP2-vs-TP1 numerics only.Rerun at a855eac with the renamed router keys (mooncake): aggregated baseline 11/11;
r2,g2(2 replicas behind one global router),tp2andp1d312/12 each.Two environment fixes from the GPU runs: mooncake needs
WITH_NVIDIA_PEERMEM=0(DMA-BUF) where nvidia-peermem is absent, now the engines' default (disagg_transport_env);nixlneeds the training workers to adopt the engines'NCCL_NET_PLUGIN=none(sglang_refit_peer_env) and is refused together withneeds_offload: true(memory saver OOMs on resume). The default mooncake transport is affected by neither.Unit tests
On GB200 at a855eac (this branch with #4920 d72df4b and main 76a3aaa merged): ruff and pyrefly 1.4.0 clean;
test_sglang_disagg.py50 passed;sglang/test_config.pyandsglang/test_fault_tolerance.py68 passed; the GRPO setup tests 512 passed;test_config_validation.pyandtest_recipes_and_test_suites.py463 passed (nightly budget 5524). The failures left in the wider run are the same on a plain-main tree.Self-review round 2 fixes (router failover in
generate_one_sample, C18-C20), c603b0c on GB200: ruff clean;test_sglang_disagg.py54 passed (4 new tests);sglang/test_config.pyandsglang/test_fault_tolerance.py68 passed;test_disagg_layout.py24 passed. The megatron refit-env selection withtest_refit_environment_follows_disaggregated_sglang_enginesran at a855eac (7 passed).test_generation_disaggregated_sglang_shares_the_nccl_transporthas not run anywhere: no venv in the test image importsnemo_automodel, so CI's automodel lane is its first run.After the merge of #4920 04e186f and main d040a22 (bcdbbd2, GB200, CPU only): ruff and pyrefly 1.4.0 clean;
test_sglang_disagg.py54 passed;tests/unit/models/generation1130 passed,test_grpo.py514,tests/unit/weight_sync458,test_single_controller_actor.py247,test_recipes_and_test_suites.py16 (nightly budget 5532). The failures left in the wider run are the same tests on a plain-main tree in the same image.SGLangGeneration.validate_settingsnow runs the SingleController checks of #5282 first and then refuses disaggregation.Not rerun on this head: the GPU smoke layouts, the sglang-marked tests (143 passed),
test_sglang_generation.py37/37 andtest_weight_update_real.py4/4 on Qwen3-0.6B, the nixl and mooncake_tcp smoke layouts, and the three 90-step runs above (8cad6ab).Needs upstream changes
#4920 (this PR is stacked on it; the base goes back to
mainonce it merges).PR commands and CI
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. Addmode=strictfor a stricter review,reset=truefor a fresh full review./resolve-conflict: Autobot mergesmaininto this PR and resolves the conflicts. PRs from forks must allow edits by maintainers./review-pr-team <pr-number>for a team review before you ask for human review.🤖 Generated with Claude Code