Repository navigation
[rl] generator: DeepEP and HybridEP token dispatchers on SGLang; shared dispatcher checks - #5959
Conversation
a2c654b to
d3a5165
Compare
d3a5165 to
eabccdc
Compare
eabccdc to
55e8dbe
Compare
|
@claude review |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. The shared checks replace SGLang's blanket rejection of DeepEP and HybridEP. They also replace vLLM's lack of any check with build-time ValueErrors, and the RL recipes that use EP still pass. A maintainer still needs to review.
What this PR does. generator/model.py gets two engine-agnostic checks:
validate_ep_token_dispatchersruns at engine build. Under CUDA graphs it rejects dispatchers that read split sizes on the host, and DeepEP in deterministic mode. It also rejects HybridEP when the EP degree is not divisible by 4.validate_ep_token_dispatcher_capacityruns in the model wrappers. It rejects a DeepEP/HybridEPnum_max_tokens_per_rankbelow the per-EP-rank token bound of one engine step.
SGLang's all-to-all-only loop is deleted in favor of the first check, so SGLang now runs DeepEP and HybridEP.
Example. search_r1's generator (vLLM, TP 4 / EP 4, max_num_batched_tokens=2048, DeepEP cuda_graph_compatible=True, num_max_tokens_per_rank=2048 // 4 = 512):
bound = ceil(2048 / 4) * 4 // 4 = 512 -> passes (512 >= 512)
num_max_tokens_per_rank=256 -> before: assert at the first 2048-token step
after: ValueError while the vLLM model wrapper builds
same config on SGLang -> before: ValueError "supports the all-to-all ... only"
after: runs under CUDA graphs
Must fix
- PR description: the "Summary (human-written)" section is empty. The author needs to fill it in.
torchtitan/rl/generator/model.py:313: the DeepEP determinism TODO has no upstream issue link (inline).
Should consider
torchtitan/rl/generator/sglang/README.md"Environment" section: neitherscripts/install_rl_env.shnorscripts/install_sglang.shinstalls DeepEP or HybridEP. The PR body also notes that the SGLang venv's own DeepEP wheel fails an NCCL version assert against torch. One line pointing SGLang users to.github/scripts/install_deepep_v2.sh/.ci/docker/common/install_deepep.shwould save the next user the debugging. Without it, the newly "supported" path can't be reproduced from the docs.
Questions
torchtitan/rl/generator/model.py:323: should the generator ban a HybridEPnon_blocking_capacity_factorbelow 1.0? Below 1.0, tokens are dropped silently (inline).
Details
- Placement: both checks are engine-agnostic and sit next to
build_dist_moe_runtimeinrl/generator/model.py. Core andmodels/common/are untouched, which is the right layer, since only the generator has variable per-step token counts plus CUDA graphs. - Dist-MoE:
DistMoeRoutedExpertsconfigs are notBaseEPTokenDispatcher.Configs, so the traversal skips them, and Dist-MoE under CUDA graphs keeps working on both engines. This is the same traversal SGLang already used. - Capacity bounds: SGLang's bound reuses the padded
chunked_prefill_size + max_running_requeststhat already sizes Dist-MoE. vLLM's paddedmax_num_batched_tokensis an upper bound on every step, because capture sizes are capped at it and filtered to TP multiples (vllm/config.py). With DP > 1, replicas pad to the largest count across replicas, which is still within the bound. - Determinism:
Generator._set_determinismsetstorch.use_deterministic_algorithmsin-process, and the SGLang scheduler runs in-process. SoDebugConfig.deterministicis exactly what makesDeepEPTokenDispatcher.init_bufferbuild a deterministic buffer, and the check matches the runtime condition. Activation remat doesn't run in the generator. - The HybridEP comment talks about "the ranks in its node", but the check uses the EP degree. The two agree when EP sits within one node, or spans nodes whose GPU count is a multiple of 4, which covers every current recipe.
- No new unit test: the checks fail loudly at build, so there's no silent invariant to guard.
Not verified: the DeepEP deterministic_sort capture failure and the HybridEP TMA-alignment rule (both need GPUs and the DeepEP/HybridEP builds).
| # TODO: DeepEP's deterministic dispatch sorts the received tokens with | ||
| # data-dependent shapes (ElasticBuffer's deterministic_sort), which CUDA | ||
| # graphs cannot capture. |
There was a problem hiding this comment.
This TODO waits on an upstream DeepEP gap (the deterministic sort's data-dependent shapes), but it has no issue link. Without one, nobody can tell when the ban can be lifted. Please file or link a DeepEP issue here, e.g. # TODO(<deepep issue URL>): ..., as CLAUDE.md asks for upstream workarounds.
| "the engine's CUDA graphs" | ||
| ) | ||
| elif isinstance(dispatcher, HybridEPTokenDispatcher.Config): | ||
| syncs_host = dispatcher.non_blocking_capacity_factor is None |
There was a problem hiding this comment.
Question: per HybridEPTokenDispatcher.Config's docstring, a non_blocking_capacity_factor below 1.0 drops tokens past the fused-permute capacity silently, and only a GPU overflow_flag records it. In training, forced load balancing keeps this rare. The generator's routing has no aux loss pushing it toward balance, though, and a drop silently changes the sampled tokens and the trainer-vs-generator logprob match. Should the generator require non_blocking_capacity_factor == 1.0 here, or is a lossy generator an intended setting? Not verified on GPU.
55e8dbe to
a7bf976
Compare
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. a7bf976 answers the HybridEP question and the README item from the last review. Both earlier must-fix items are still open, and the new commit adds no new problems. A maintainer still needs to review.
What changed since the last review.
validate_ep_token_dispatchers(torchtitan/rl/generator/model.py:322-335) now raises when HybridEP'snon_blocking_capacity_factoris below 1.0. This matches_num_permuted_tokens_for_non_blockingintorchtitan/distributed/deepep/hybridep.py: 1.0 sizes the permute buffer for the worst case (num_tokens * ep_size * min(num_local_experts, top_k)), and anything smaller can drop tokens without an error.sglang/README.mdnow says that neither install script installs DeepEP or HybridEP, and points to.github/scripts/install_deepep_v2.shand.ci/docker/common/install_deepep.sh. Both scripts exist at HEAD.
Example.
HybridEPTokenDispatcher.Config(non_blocking_capacity_factor=0.5), EP 4, any engine
before a7bf976e4: runs, and skewed routing drops tokens silently (sampled tokens change)
after: ValueError at engine build "... below 1.0 drops tokens in the generator"
non_blocking_capacity_factor=1.0 -> passes (worst-case buffer, no drops)
Resolved since the last review
- Question: HybridEP
non_blocking_capacity_factor < 1.0in the generator. It now raises. - Should consider: the SGLang README now points to the DeepEP/HybridEP install scripts.
Must fix (still open)
- PR description: the "Summary (human-written)" section is still the empty template. The author needs to write it.
torchtitan/rl/generator/model.py:313: the DeepEP deterministic-dispatch TODO still has no upstream issue link (see the earlier inline comment).
Not verified: the HybridEP drop behavior below 1.0 on GPU. The reasoning above comes from the buffer-sizing code only.
a7bf976 to
cbcd584
Compare
|
[From Claude (AI agent), on behalf of @tianyu-l] @claude review again. cbcd584 links the DeepEP deterministic-dispatch TODO to deepseek-ai/DeepEP#820. The human-written summary is still pending from the author. |
|
Claude finished @tianyu-l's task in 42s —— View job Approve: both earlier must-fix items are resolved (the DeepEP TODO now links deepseek-ai/DeepEP#820, and the human-written summary is filled in). See the review. |
34b4bce to
c4de7b4
Compare
d1e0f07 to
9ed452f
Compare
5d7e568 to
3ec8f03
Compare
There was a problem hiding this comment.
Automated review by claude. Do NOT put high weight on this comment.
User server args can get past the new capacity check and the shared validator.
No inline comments. Two gaps that the #5812 comment on engine.py:70-94 covers.
A graph-mode alias = a key in extra_server_args that changes the graph mode, such as cuda_graph_backend_decode.
- Explicit capture sizes can exceed the bound the capacity check uses.
- The new capacity check (model_wrapper.py:333-339) uses the live bound:
chunked_prefill_size + max_running_requests. - SGLang's default capture sizes stay within it (memory_hook.py:235-238, cuda_graph_hook.py:529 at the pinned SGLang commit).
- An explicit
cuda_graph_bs_prefillorcuda_graph_max_bs_prefillis kept as given (memory_hook.py:267). - It can exceed the bound at capture, where DeepEP asserts (deepep.py:536 on main).
- The new capacity check (model_wrapper.py:333-339) uses the live bound:
- A graph-mode alias passes the shared validator.
- The shared validator reads
config.cuda_graph(engine.py:196). - DeepEP's deterministic-mode guard (model.py:316) reads that same value.
- A graph-mode alias in
extra_server_argspasses both.
- The shared validator reads
3ec8f03 to
3ebd73f
Compare
3ebd73f to
bef887c
Compare
|
[From Claude (AI agent), on behalf of @tianyu-l] On the automated review body: both gaps are closed by #5812 (5c1767d), which rejects every |
bef887c to
be8bd7b
Compare
be8bd7b to
19d9f98
Compare
| `.ci/docker/common/install_deepep.sh` (HybridEP) do. SGLang's own DeepEP wheel | ||
| fails its NCCL version check under the PyTorch nightly. Dist-MoE |
There was a problem hiding this comment.
should we raise an issue? not p0 though
There was a problem hiding this comment.
[From Claude (AI agent), on behalf of @tianyu-l] I don't think an upstream issue would lead anywhere. SGLang's DeepEP wheel is built against the PyTorch (and NCCL) SGLang pins, and the check fails only because torchtitan runs the PyTorch nightly, which SGLang doesn't support. Building DeepEP against the environment's PyTorch, as CI does, is the fix on our side.
| max_num_tokens_per_step = ( | ||
| schedule.chunked_prefill_size + schedule.max_running_requests | ||
| num_tokens = schedule.chunked_prefill_size + schedule.max_running_requests | ||
| max_num_tokens_per_step = -(-num_tokens // token_multiple) * token_multiple |
…ed dispatcher checks SGLangEngine accepted only the all-to-all token dispatcher and Dist-MoE. It now also accepts DeepEP and HybridEP, as VLLMEngine does. DeepEP with cuda_graph_compatible and HybridEP with non_blocking_capacity_factor dispatch without a host sync, so they run under CUDA graphs. Both engines now run the same checks (generator/model.py), which VLLMEngine lacked: - validate_ep_token_dispatchers, at engine build: a host-synced dispatcher (all-to-all, DeepEP without cuda_graph_compatible, HybridEP without non_blocking_capacity_factor) under CUDA graphs raises, as does DeepEP's deterministic dispatch (DebugConfig.deterministic), whose receive sort has data-dependent shapes; HybridEP needs an EP degree divisible by 4, since a step can have any token count and HybridEP's TMA loads need a rank's tokens times the ranks in its node, in 4-byte words, to fill 16-byte rows. - validate_ep_token_dispatcher_capacity, in the model wrappers: a DeepEP or HybridEP num_max_tokens_per_rank below a step's tokens per EP rank raises at build, instead of DeepEP asserting at the first large step.
- The shared dispatcher validator notes that Dist-MoE experts have no token dispatcher. - The CUDA-graph server-args comment names the DeepEP / HybridEP capacity check, which assumes SGLang's default capture sizes, as Dist-MoE does.
19d9f98 to
761b7d7
Compare

Stacked on #5918. Addresses the DeepEP / HybridEP question on #5815.
Summary (human-written)
Integrate sglang with deepep and hybrided
Why
SGLangEngineaccepts only the all-to-all token dispatcher and Dist-MoE, so an MoEgenerator configured with DeepEP or HybridEP (as
search_r1's vLLM generator usesDeepEP) cannot run on SGLang.
VLLMEngineaccepts them, but checks nothing: adispatcher config the engine cannot run fails mid-capture or mid-generation with a
low-level error.
Example.
What changed
generator/model.py(engine-agnostic): two checks both engines call.validate_ep_token_dispatchers, at engine build:without
cuda_graph_compatible, HybridEP withoutnon_blocking_capacity_factor)raises under CUDA graphs;
DebugConfig.deterministic) raises under CUDAgraphs: DeepEP sorts the received tokens with data-dependent shapes
(
ElasticBuffer.deterministic_sort);and HybridEP's TMA loads need a rank's tokens times the ranks in its node, in
4-byte words, to fill 16-byte rows (EP 2 with 3 tokens per rank raised
"TMA 16B alignment error" while SGLang captured a decode graph);
non_blocking_capacity_factorbelow 1.0 raises: HybridEP drops thetokens past its capacity without an error, which changes the sampled tokens.
validate_ep_token_dispatcher_capacity, in the model wrappers: a DeepEP/HybridEPnum_max_tokens_per_rankbelow a step's tokens per EP rank raises. SGLang's boundis
chunked_prefill_size + max_running_requests, vLLM'smax_num_batched_tokens,each padded to a multiple of TP and split over TP.
sglang/engine.py: its dispatcher loop is replaced by the shared check, so itaccepts DeepEP and HybridEP.
vllm/engine.py,vllm/model_wrapper.py: call the shared checks.sglang/README.md: the MoE section, including where to get DeepEP and HybridEPbuilds (the install scripts in
.github/scripts/and.ci/docker/common/).cuda_graph_compatible/ HybridEPnon_blocking_capacity_factor, CUDA graphsDebugConfig.deterministic+ CUDA graphsnon_blocking_capacity_factor< 1.0num_max_tokens_per_ranktoo smallEvery existing RL recipe whose generator uses EP passes the new checks (built on CPU
and checked: the
alphabet_sort,dapo_math,search_r1and testalphabet_sortrecipes;
verifiers_terminal_benchalready turns generator CUDA graphs off).no token dispatcher; the CUDA-graph server-args comment names the DeepEP /
HybridEP capacity check, which assumes SGLang's default capture sizes. Explicit
capture sizes and graph-mode keys in
extra_server_argsare rejected since [rl] generator: SGLang generation engine #5812.Numerics
No change for configurations that ran before. DeepEP and HybridEP results on SGLang
match the trainer bitwise when the trainer uses the same dispatcher (below).
Testing
Locally on GB300, Qwen3 MoE debug model (
TestSGLangBitwiseParityMoEEP's config withthe dispatcher swapped). DeepEP v2 at the pin in
.github/scripts/install_deepep_v2.shand HybridEP at the pin in
.ci/docker/common/install_deepep.sh, built againsttorch's NCCL 2.32.3:
cuda_graph="none"cuda_graph="full",DebugConfig.deterministic=Falsecuda_graph="full"cuda_graph="full";num_max_tokens_per_rank=4096; HybridEP with EP 2; HybridEP factor 0.5pytest tests/rl/unit_tests/cpu: 568 passed, 7 skipped.venv's own DeepEP wheel asserts on an NCCL version mismatch with torch.
Known issues / follow-ups
rank that miss the alignment (small test sequences); training microbatches are
packed to aligned sizes.
environments.