Skip to content

feat: SGLang prefill/decode disaggregation for GRPO rollouts - #5086

Open
shikicloud wants to merge 27 commits into
NVIDIA-NeMo:shikiw/vllm-pd-disaggfrom
shikicloud:feat/sglang-pd-disagg
Open

shikicloud wants to merge 27 commits into
NVIDIA-NeMo:shikiw/vllm-pd-disaggfrom
shikicloud:feat/sglang-pd-disagg

Conversation

@shikicloud

@shikicloud shikicloud commented Nov 5, 2026 •

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

What and why

Adds prefill/decode (PD) disaggregation to the SGLang generation backend for synchronous GRPO rollouts, on the shared generation.disaggregation layout of #4095 (TRT-LLM) and #4920 (vLLM).

Stacked on #4920 (disagg_layout.py / DisaggConfig come from there): the base branch is shikiw/vllm-pd-disagg, a copy of #4920's head, so this diff shows the SGLang changes only. The base goes back to main once #4920 merges.

SGLang needs no frontend of NeMo RL's: the sglang router's PD mode pairs every /generate request 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 /generate as 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 (replica default, 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.
  • Engine layout as specs (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.
  • Router started in PD mode with empty pools; engines register with worker_type and bootstrap_port. With router_scope: replica, disagg_dispatch.py keeps 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.
  • Width-aware port allocator (_allocate_disagg_engine_addr_and_ports) for server/NCCL/dist-init/bootstrap ports from the reserved generation band.
  • Refit: prefill engines pause before decode engines and resume after them. PD requires pause_generation_mode: abort; refits run between steps on idle engines, so abort drops nothing.
  • Setup validation (validate_sglang_disaggregation): non-colocated only, no NeMo-Gym, no external router, pp_size: 1, abort, no power_of_two. SGLangGeneration.validate_settings refuses disaggregation on the SingleController entrypoint (it refits with rollouts in flight, and abort would return cut-off requests as finished samples).
  • Recipe grpo-qwen2.5-math-1.5b-instruct-2n8g-megatrontp1-sglang-pd-disagg.yaml + nightly driver, exemplar keys in grpo_math_1B_sglang.yaml, SGLang section in docs/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_server key (always 1); it now uses sglang_server_config.num_gpus_per_engine, which only changes placement for engines wider than a node.

Usage

policy:
  generation:
    backend: sglang
    colocated:
      enabled: false
    disaggregation:
      enabled: true
      num_prefill_engines: 1
      num_decode_engines: 1
    sglang_cfg:
      tp_size: 2
      sglang_server_config:
        pause_generation_mode: abort
      prefill_engine: {}              # per-role overrides, e.g. {tp_size: 4}
      decode_engine: {}
      disagg:                         # all optional; these are the defaults
        router_scope: replica         # replica | global
        transfer_backend: mooncake    # mooncake | nixl (needs needs_offload: false) | mooncake_tcp
        prefill_router: cache_aware
        decode_router: round_robin

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:

  • PD: the nightly recipe (2 replicas of 1 TP2 prefill + 1 TP2 decode, one router per replica).
  • aggregated: sibling recipe ...-sglang-noncolocated (4 TP2 engines on the same 8 GPUs).
  • PD, global router: the nightly recipe with 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.sh on the PD run, all pass: median token_mult_prob_error 1.0040 (< 1.1), last step 1.0044, mean gen_kl_error 1.28e-4 (< 0.001), mean step time 11.0 s (< 25), prefill and decode engines logged.

Convergence and throughput

pr5086_sglang_pd_nightly_and_convergence_m2

Warm-up steps 1-3 excluded from the timing means.

PD, replica router PD, global router aggregated
generation s per step, mean (median) 3.62 (2.86) 3.32 (2.82) 3.06 (2.59)
total step time, mean s 11.0 10.3 10.4
generated tokens/s, 8 inference GPUs 78.3k 81.0k 91.1k
generated tokens/s per decode GPU 19.6k 20.2k 11.4k
reward, mean of last 10 steps 0.396 0.393 0.397
validation accuracy, step 10 → 90 0.305 → 0.480 0.316 → 0.430 0.340 → 0.398
token_mult_prob_error, median / last 1.0040 / 1.0044 1.0039 / 1.0043 1.0039 / 1.0042
gen_kl_error, mean / max 1.28e-4 / 1.54e-4 1.25e-4 / 1.50e-4 1.26e-4 / 1.53e-4

Training 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: global is within noise of replica.

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) and p1d3 (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 for r2 and p1d3; tp2 differs 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), tp2 and p1d3 12/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); nixl needs the training workers to adopt the engines' NCCL_NET_PLUGIN=none (sglang_refit_peer_env) and is refused together with needs_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.py 50 passed; sglang/test_config.py and sglang/test_fault_tolerance.py 68 passed; the GRPO setup tests 512 passed; test_config_validation.py and test_recipes_and_test_suites.py 463 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.py 54 passed (4 new tests); sglang/test_config.py and sglang/test_fault_tolerance.py 68 passed; test_disagg_layout.py 24 passed. The megatron refit-env selection with test_refit_environment_follows_disaggregated_sglang_engines ran at a855eac (7 passed). test_generation_disaggregated_sglang_shares_the_nccl_transport has not run anywhere: no venv in the test image imports nemo_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.py 54 passed; tests/unit/models/generation 1130 passed, test_grpo.py 514, tests/unit/weight_sync 458, test_single_controller_actor.py 247, test_recipes_and_test_suites.py 16 (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_settings now 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.py 37/37 and test_weight_update_real.py 4/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 main once it merges).

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

🤖 Generated with Claude Code

@copy-pr-bot

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

@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Nov 5, 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.

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.

  1. (C1) Forced abort pause mode is unsafe on the SingleController entrypoint, which refits with rollouts in flight; add SGLangGeneration.validate_settings and fix the comment.
  2. (C2) plan_sglang_engines lets an engine straddle two nodes; refuse it at planning time and add tests.
  3. (C3) Role override num_continuous_decode_steps is never passed to SGLang; forward it and replace the identity test.
  4. (C4) transfer_backend: fake kills every prefill engine at startup; drop it.
  5. (C5) The new nightly entry breaks the GPU-hour cap test; raise the cap to 5221.
  6. (C6) The PD recipe is not minimized, so Lint fails.
  7. (C7) pyrefly bad-return in resolve_sglang_role_overrides; wrap in cast.
  8. (C8) pyrefly bad-assignment on dist_init_addr; annotate it.
  9. (C9) With fault tolerance on, ReplicaDispatcher.acquire sends most prompts to a router whose engine is dead.
  10. (C10) SGLangRoleEngineArgs is a new TypedDict config; make it a pydantic BaseModel.
  11. (C11) The cache_aware prefix-affinity comment is wrong, because NeMo RL sends token ids only.
  12. (C12) The pp_size error message gives the wrong reason.
  13. (C13) The design doc intro still describes two backends.
  14. (C14) Dead nodes_per_engine and getattr fallbacks kept only for tests.
  15. (C15) The new grpo.setup branches have no tests.
  16. (C16) Long in-function comment blocks, one with a wrong claim about the NeMo-Gym gate.
  17. (C17) No performance or convergence numbers, and the nightly gates would pass with PD off.

Generated by Claude Code

Comment thread tests/test_suites/nightly.txt Resolved
Comment thread nemo_rl/algorithms/grpo.py Resolved
shikicloud and others added 3 commits November 4, 2026 23:55
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]>
@terrykong terrykong added CI:L1 Run doctests, unit tests, and functional tests CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) and removed CI:L1 Run doctests, unit tests, and functional tests labels Nov 5, 2026
@shikicloud
shikicloud marked this pull request as ready for review November 12, 2026 07:00
shikicloud and others added 5 commits November 12, 2026 01:31
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]>
@shikicloud
shikicloud changed the base branch from main to shikiw/vllm-pd-disagg November 19, 2026 04:32
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]>

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

  1. (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 in generate_one_sample; patch and three tests included.
  2. (C19) test_pause_is_prefill_then_decode_and_resume_is_the_reverse passes for a one-batch pause too; add a two-replica test that records each ray.get batch.
  3. (C20) The design doc and the disagg_layout.py docstring 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_transport has not run anywhere (no venv in the test image imports nemo_automodel; CI's automodel lane is its first run), and that the megatron refit-env selection with test_refit_environment_follows_disaggregated_sglang_engines ran (7 passed).

Not blocking (low; for a follow-up or the author's call):

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

Copy link
Copy Markdown
Contributor Author

/ok to test bcdbbd2

@shikicloud

Copy link
Copy Markdown
Contributor Author

/ok to test a3bdf08

@shikicloud

Copy link
Copy Markdown
Contributor Author

/ok to test 7e8afd8

@terrykong terrykong removed the Documentation Improvements or additions to documentation label Nov 28, 2026
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]>
@shikicloud

Copy link
Copy Markdown
Contributor Author

/ok to test 574450f

@svcnvidia-nemo-ci svcnvidia-nemo-ci added complexity:high Large or cross-cutting change. Set by Autobot PR classify (skills/pr-classify) convergence-risk:high Likely to change training results. Set by Autobot PR classify (skills/pr-classify) proof:functionality Needs proof that it works. Set by Autobot PR classify (skills/pr-classify) proof:convergence Needs convergence proof (W&B runs). Set by Autobot PR classify (skills/pr-classify) proof:perf Needs performance proof. Set by Autobot PR classify (skills/pr-classify) labels Nov 29, 2026
@shikicloud

Copy link
Copy Markdown
Contributor Author

/ok to test b27fd41

This branch has not been deployed

No deployments
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) complexity:high Large or cross-cutting change. Set by Autobot PR classify (skills/pr-classify) convergence-risk:high Likely to change training results. Set by Autobot PR classify (skills/pr-classify) proof:convergence Needs convergence proof (W&B runs). Set by Autobot PR classify (skills/pr-classify) proof:functionality Needs proof that it works. Set by Autobot PR classify (skills/pr-classify) proof:perf Needs performance proof. Set by Autobot PR classify (skills/pr-classify)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants