Repository navigation
[1/N] elastic-ep: Add runtime EP scale-up - #30164
Conversation
|
Warning Gemini encountered an error creating the review. You can try again by commenting |
53ea8e1 to
797b9cf
Compare
797b9cf to
44ba05d
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request implements dynamic elastic EP (Expert Parallelism) scale-up, enabling new ranks to join a deployment at runtime. It introduces state management, HTTP endpoints, and updates the distributed state, data parallel controller, and token dispatchers to support the expanded world size. The review highlighted several critical bugs: a potential AttributeError in the scheduler when accessing the model runner, a missing enable_elastic_ep attribute on ModelRunner that disables uneven token count handling, and a bug preventing recovered rank 0 from starting the master TCPStore server. Additionally, the reviewer noted that NIXL mask updates do not use the effective EP size, _LOCAL_ATTN_DP_SIZE is not updated post-scale, torch.arange lacks an explicit dtype, and server arguments overly restrict node ranks to exactly 1.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
/tag-and-rerun-ci |
# Conflicts: # python/sglang/srt/elastic_ep/elastic_ep.py # python/sglang/srt/managers/tp_worker.py # python/sglang/srt/model_executor/model_runner.py
Re-express the elastic-EP fault-tolerance work on top of current main (2499 commits, incl. runtime EP scale-up sgl-project#30164 and the sock_send/sock_recv IPC refactor sgl-project#29012). Key resolution decisions: - Fault detection/recovery stays at the scheduler result boundary (this PR's architecture); the forward-path rebalance re-run and per-forward recovery polling are removed. The scale-up driver (maybe_join_ep_ranks) is kept intact; its recovery arm reduces to the has_scaled -> fail_recovery latch, mirrored by a guard in the scheduler mixin (recovery after append-only scale-up stays unsupported). - ActiveRanksOutput moves to the direct scheduler->controller channel (sock_send/sock_recv msgpack end to end; port_base+6, since +5 is now the load collector). ElasticScaleUpdateReq keeps its tokenizer relay because the TokenizerManager consumes it for fan-out updates. - New ElasticEPState.realign_snapshots_to_active() re-baselines the staging ring after legitimate active_ranks rewrites (scale admission, recovery reset) so the AND-sticky committed mirror cannot re-kill newly admitted ranks or trigger a spurious retract; pending slots are preserved so each submitted forward still commits exactly once. pg masks are applied prefix-based against the max-ep-size capacity. - Fixes folded in while rebasing: draft-worker snapshot double-submit guard (battle-tested downstream); disagg-prefill submit gate (those loops have no result boundary); parked chunked-prefill request release on retract; EPLB active mask sliced to num_gpus; controller send timeout no longer mutates the authoritative worker status (liveness is decided solely by scheduler-published active-rank updates); poller-based controller event loop with bounded fair drain. Co-Authored-By: Claude Fable 5 <[email protected]> Co-Authored-By: codex (gpt-5.6-sol)
[1/N] elastic-ep: Add runtime EP scale-up
Summary
This is the first PR in the runtime Expert Parallel (EP) Scaling series. It
allows a running MoE deployment to grow through one or more append-only scale
operations up to a reserved
--max-ep-size, without restarting the primaryserver. Each operation may add any positive number of ranks that fits within
the reserved capacity.
Motivation
SGLang currently fixes the EP topology when the server starts. Adding GPUs to
an MoE deployment therefore requires stopping the server, rebuilding its
distributed topology, and reloading the model.
SGLang already has most of the lower-level machinery needed to admit ranks at
runtime through Elastic EP rank recovery. Runtime scale-up can reuse that
model when the deployment reserves its maximum size up front: inactive rank
slots and backend buffers are allocated at launch, a joiner loads the same
model independently, and Mooncake admits the new rank range when the operator
requests scale-up.
This PR implements that scale-up slice of the [RFC] Elastic EP Scale](#22788).
What This PR Does
Scale API and state
POST /scale_elastic_epwith an absolutenew_ep_sizetarget.GET /is_scaling_elastic_epfor the effective size, pending target,coarse request state, and last error. Internal model-runner phases are not
reported through this endpoint.
--elastic-ep-join-modeto distinguish new-rank admission (scale)from existing rank recovery (
recover); the latter replaces the deprecated--elastic-ep-rejoinflag.ElasticEPStateManagerandpropagates scale requests through the tokenizer-to-scheduler control path.
max_ep_size.Reserved capacity and size semantics
--max-ep-sizereserves the scale-up ceiling; it does not start the reservedrank processes or add them to the serving topology. For a deployment launched
at EP=4 with capacity reserved through EP=8, launch-time state is:
The
active_rankstensor and NIXL rank/buffer capacity are sized formax_ep_sizeat launch. The inactive tail has no running processes and noestablished peer connections. Other state that depends on the live topology,
including DPC worker slots and expanded EPLB metadata, is activated or rebuilt
during the scale commit.
effective_ep_sizeis the committed size used for serving. For example, aftera 4-to-5 request is accepted, it remains
4whilepending_ep_sizeis5.Only after the joiner is admitted and every rank has installed the expanded
runtime state does the commit produce:
A subsequent operation can grow the same deployment from EP=5 to EP=6.
Rank admission and runtime commit
Scale-up is split into an asynchronous request stage and a synchronized runtime
commit:
POST /scale_elastic_epsends the target to the current schedulers, recordspending_ep_size, and returns after the request is accepted. The HTTPresponse does not wait for rank admission or runtime reconfiguration.
joiners are ready. Once they have joined, it commits the expanded topology
and reports completion to the control plane.
Clients use
GET /is_scaling_elastic_epto observe completion.Data and control planes
max_ep_sizeand lazily connects the newlyadmitted peers on MoE dispatch.
the expert-distribution recorder.
live Mooncake WORLD rather than launch-time groups that cannot grow.
DataParallelControllerand grows tokenizer/control fan-out to include them.Architecture and Flow
flowchart TD P1["Primary ranks 0..S-1<br/>Start at EP=S; reserve max EP=M"] P2["Serve requests at EP=S"] P3["Accept target EP=T<br/>continue routing at EP=S"] P4["At the next forward boundary,<br/>admit ranks and install EP=T state"] P6["Activate joiner schedulers<br/>and grow control fan-out"] P7["First EP=T forward connects NIXL<br/>serve requests at EP=T"] J1["Joiner ranks S..T-1<br/>Launch later and load model"] J2["Wait in scale join mode"] J3["Join Mooncake WORLD and<br/>install EP=T runtime state"] J5["Become active<br/>scheduler ranks"] J6["First EP=T forward connects NIXL<br/>execute as active EP ranks"] M["Mooncake WORLD expanded<br/>runtime state coordinated"] B["Expanded-WORLD readiness barrier<br/>all primary and joiner ranks"] P1 --> P2 --> P3 --> P4 --> M P1 -. "Operator launches joiners after the primary starts" .-> J1 J1 --> J2 --> J3 --> M M --> B B --> P6 --> P7 B --> J5 --> J6How to Use
The following example grows a four-rank wide-EP deployment to eight effective
EP/DP ranks by adding a second four-rank launch cohort. Each cohort remains
local TP4; scale-up does not create a TP8 group. The primary and joiner must use
the same model, distributed initialization address, initial EP size, maximum
EP size, and backend configuration.
Start the primary:
Start the joining group. It may be launched before the scale request and wait
for the primary to admit it:
Request scale-up through the primary:
Poll the asynchronous operation:
A completed operation reports
effective_ep_size: 8,pending_ep_size: null, andis_scaling_elastic_ep: false.For a direct 4-to-6 operation, launch a two-rank joiner with
--tp 2 --dp 2,--elastic-ep-join-rank-offset 4, and requestnew_ep_size: 6. For repeated4-to-5-to-6 scale-up, launch a one-rank joiner at offset 4 and commit EP=5,
then launch a new one-rank joiner at offset 5 and commit EP=6.
Follow-up Work
The following capabilities are planned as follow-up PRs in this Elastic EP
series:
topology changes.
topology without restarting the deployment.
one or more successful scale-up operations while preserving the committed EP
size.
ranks but disables periodic rebalance after scale-up.
The follow-up PR [2/N] elastic-ep: Enable EPLB after scale-up #30553
coordinates EPLB collectives with the expanded WORLD and re-enables
runtime expert reshuffling.
work out of the request-visible commit and first post-scale request paths.
Known Limitations
--enable-dp-attention,--enable-dp-lm-head,--pp-size 1,--attention-context-parallel-size 1,--moe-data-parallel-size 1, and--tp == --dp == --epwithin each launchcohort.
--tokenizer-worker-num 1.backend and NIXL as the MoE all-to-all backend.
Test Plan
Manual six-GPU E2E tests used for this PR:
python -m pytest -v -s test/manual/ep/test_elastic_scale.py -k TestElasticScaleUp4To6 python -m pytest -v -s test/manual/ep/test_elastic_scale.py -k TestElasticScaleUp4To8 python -m pytest -v -s test/manual/ep/test_elastic_scale.py -k TestElasticScaleUp4To5To6 # Multi-scaleTogether the tests cover pre-launched joiners waiting for admission, multi-rank and repeated scale-up, asynchronous
completion polling, generation and input logprobs after each scale, direct
routing to every newly activated rank, and post-scale GSM8K correctness.
Cross-References
CI States
Latest PR Test (Base): ❌ Run #29324601378
Latest PR Test (Extra): ❌ Run #29324601422