Repository navigation
[Refactor] deepseek-v4: Use explicit stage boundaries and row transport - #43607
Merged
Merged
Conversation
ch-wan
force-pushed
the
cheng/refactor/layer-boundary-connections
branch
from
October 14, 2026 19:27
307cbc6 to
b7a8f57
Compare
ch-wan
force-pushed
the
cheng/refactor/layer-boundary-stack
branch
from
October 14, 2026 19:27
5c0f683 to
b3d7a1c
Compare
ch-wan
marked this pull request as ready for review
October 14, 2026 19:47
ch-wan
requested review from
BBuf,
Edwardf0t1,
Fridge003,
HaiShaw,
Ying1123,
fzyzcjy,
hnyls2002,
ispobock and
merrymercy
October 14, 2026 19:47
ch-wan
force-pushed
the
cheng/refactor/layer-boundary-connections
branch
from
October 14, 2026 21:37
b7a8f57 to
b8e60fb
Compare
ch-wan
force-pushed
the
cheng/refactor/layer-boundary-stack
branch
from
October 14, 2026 21:38
b3d7a1c to
50adca4
Compare
ch-wan
force-pushed
the
cheng/refactor/layer-boundary-connections
branch
from
October 14, 2026 21:55
b8e60fb to
b202b82
Compare
ch-wan
force-pushed
the
cheng/refactor/layer-boundary-stack
branch
from
October 14, 2026 21:55
50adca4 to
bb1c72b
Compare
ch-wan
force-pushed
the
cheng/refactor/layer-boundary-connections
branch
from
October 14, 2026 22:08
b202b82 to
f2fae0c
Compare
ch-wan
force-pushed
the
cheng/refactor/layer-boundary-stack
branch
from
October 14, 2026 22:09
bb1c72b to
8c8357b
Compare
Collaborator
Author
|
/run-full-ci |
ch-wan
force-pushed
the
cheng/refactor/layer-boundary-connections
branch
from
October 15, 2026 09:04
f2fae0c to
630a645
Compare
Base automatically changed from
cheng/refactor/layer-boundary-connections
to
main
October 15, 2026 09:04
Route CUDA attention and MoE outputs through explicit hyper-connection reads, updates and compute-row transport. Preserve source residual rows while moving MoE operands, and materialize outstanding work at PP, capture and draft exits. Select CUDA and non-CUDA decoder subclasses at import time. Non-CUDA mHC and TBO execution live in one platform module; DeepSeek-specific gather/combine logic lives beside the model. Preserve late-layer DP metadata changes and breakable-graph tail entry/exit. Declare uneven token rows for overlapped expert dispatch. DSpark attention completion uses the attention-TP group when it is smaller than the full TP group. Keep transport binders out of neighbour facts. Cover receiving PP stages, MoEOutput completion, weight refresh, transport lifetimes and Hopper/dual-stream GPU kernels. Non-CUDA execution is checked by CPU orchestration tests; hardware validation remains separate.
ch-wan
force-pushed
the
cheng/refactor/layer-boundary-stack
branch
from
October 15, 2026 09:05
8c8357b to
b9e67e6
Compare
4 of 5 tasks
This was referenced Oct 15, 2026
4 of 5 tasks
3 of 5 tasks
detain
pushed a commit
to detain/sglang
that referenced
this pull request
Oct 20, 2026
…P all-reduce sgl-project#42245 dropped the wide-prefill multistream overlap that sgl-project#39704 added: in target prefill of 4096 to 65536 rows each sublayer's mix stats ran on the stats stream beside that sublayer's TP all-reduce. Since then only decode and verify use the stream, so in prefill the mix GEMM and Sinkhorn run after the all-reduce on the critical path, twice per layer. Bring it back on the layer-boundary transports (sgl-project#43607). When a sublayer's TP all-reduce is still owed and not deferred to a fused post, the attention and MoE transports fork the stats stream in prepare_output, issue the triplet on it, and record the stream on the residual state; HcUpdate.post waits on it before reading the triplet. Gating follows sgl-project#39704: lagged V4.1 layers, Blackwell, extend without speculation, 4096 to 65536 rows, attention DP 1, no SP, no prefill CP, not batch-invariant, TP4 and no MoE A2A backend. Decode and verify keep forking before the combine. (cherry picked from commit a6a64b6a945e704251c16a1face9d06a15ca5c18)
4 of 5 tasks
ormandj
added a commit
to ormandj/sglang
that referenced
this pull request
Oct 29, 2026
…P all-reduce sgl-project#42245 dropped the wide-prefill multistream overlap that sgl-project#39704 added: in target prefill of 4096 to 65536 rows each sublayer's mix stats ran on the stats stream beside that sublayer's TP all-reduce. Since then only decode and verify use the stream, so in prefill the mix GEMM and Sinkhorn run after the all-reduce on the critical path, twice per layer. Bring it back on the layer-boundary transports (sgl-project#43607). When a sublayer's TP all-reduce is still owed and not deferred to a fused post, the attention and MoE transports fork the stats stream in prepare_output, issue the triplet on it, and record the stream on the residual state; HcUpdate.post waits on it before reading the triplet. Gating follows sgl-project#39704: lagged V4.1 layers, Blackwell, extend without speculation, 4096 to 65536 rows, attention DP 1, no SP, no prefill CP, not batch-invariant, TP4 and no MoE A2A backend. Decode and verify keep forking before the combine.
Contributor
|
I think there’s excessive encapsulation in the current code, which hurts readability. For example, in the snippet below, it’s hard to tell that state = mhc.HcState(hidden_states)
if _is_cuda:
residual_batch.start(forward_batch)
hidden_states = residual_batch.set_written(state, forward_batch) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR was part of the following stack (oldest at bottom; all merged):
Motivation
DeepSeek V4/V4.1 CUDA execution manages mHC reads, residual updates, deferred sums and MoE operand movement in model-specific forward paths. Explicit boundary declarations let the same producer completion reach ordinary consumers, PP transfers, graph exits and draft-model exits while preserving the original residual rows.
Modifications
Use a frozen
msgspec.Structfor layer invocation metadata and explicitly declare the terminal mHC reader stateless.Route CUDA attention and MoE outputs through mHC read/update adapters and compute-row transport. Keep DeepSeek-specific gather, return, shared-expert finalization and TBO events/buffers in
models/deepseek_common/moe_transport.py. The genericlayer_boundary/row_transport.pydefines the source/compute/returned-row contract and completion lifecycle; V4 is currently its only model-family user.Select explicit CUDA/non-CUDA decoder subclasses. Non-CUDA tuple/HcState and fused execution are grouped in
deepseek_v4_platform_stage.py, retaining their existing numerical protocols. Include NextN, DSpark, PP receiving stages, late-layer DP and breakable-graph tail handling. Preserveupdate_contextthrough bothStageBoundary.finishandStageBoundary.exitinto the row-transport update binder; bind it once for deferred and immediately applied updates.TransportExit.finish/complete_owed, or consumer read completion fusionMoeRowTransport.__init__, bound during stage prepareMoeFinalize.completeMoeRowTransport.return_outputTransportExit._write, orFinalReadforward/forward_hc_pre_from_prevDeepseekV4CudaDecoderLayer.forward+HcRead/HcUpdateNonCudaDecoderMixin.forward/forward_hc_pre_from_prev_run_moe_ffn_dp_syncMoeTransport/MoeRowTransport/MoeFinalizeNonCudaDecoderMixin._run_moe_ffn_dp_syncusing shared transportNonCudaDecoderMixinNonCudaDSparkMixinAccuracy Tests
72730d6360matched for V4 TP2 decode graph, V4.1 TP4/DP4 late-layer shared experts, V4.1 DSpark serial decode graph and V4 NextN serial decode graph.Limits and Follow-up
1 < attn_tp < tp; main may use the full TP group. Reachability and complete numerical validation of that non-default configuration remain open, so universal numerical equivalence is not claimed._is_cudalines remain 31 / 7 / 2 respectively. A unified single-layer calling contract and platform naming cleanup remain follow-up work; this PR does not claim the CUDA path's overall complexity is reduced.Speed Tests and Profiling
No speedup or formal no-regression claim. Existing synthetic-model timing samples and host profiles are diagnostic only.
Current Stack Validation
All three updated adapter commits passed pre-commit independently; the two K3 commits are unchanged. The final stack CPU suite passed 481 tests and 7,409 subtests, with 21 hardware-specific skips. Independent common-layer and Inkling boundary suites passed 372 tests / 7,315 subtests and 386 tests / 7,329 subtests, respectively.
Four new regressions fail on the prior implementation and pass with the fixes. They cover terminal export releasing state retained by an old output handle (including a failing final norm), terminal reader binding for written/pending/fused output with two contexts, rejection and cleanup when binding changes read capabilities, and rejection of bindable update results on both immediate and deferred exit paths. Existing tests cover the converted containers, short-convolution positions and stateless V4 terminal reads.
The earlier callback-selection, transformed-reader and row-transport context regressions remain covered. No GPU tests or formal performance benchmarks were rerun for these fixes; prior GPU evidence retains its stated limitations.
Landing
Rebased onto main
3a835cf417for merge. Validation above predates this rebase; no tests or benchmarks were rerun as part of landing.CI States
Latest PR Test (Base): 🚫 Run #38710372685
Latest PR Test (Extra): 🚫 Run #38710372266
Latest PR Test (AMD ROCm 10): 🚫 Run #38710372377