Repository navigation
Conversation
This was referenced Oct 7, 2026
17 of 56 tasks
ormandj
force-pushed
the
mhc-prefill-stats-overlap
branch
from
October 19, 2026 16:46
9486c1c to
a6a64b6
Compare
This comment has been minimized.
This comment has been minimized.
detain
added a commit
to detain/sglang
that referenced
this pull request
Oct 20, 2026
…/deferred/avoid map - 3A [24-35]: NVFP4 MoE boot sgl-project#39807/sgl-project#40173, block-FP8 TP refine sgl-project#42566, k-pool indexer split sgl-project#43619, SM120 skinny GEMM sgl-project#42865/sgl-project#42867, DeepGEMM warmup guards sgl-project#32686/sgl-project#43712, autotune sgl-project#43363/sgl-project#40420, mHC overlap sgl-project#42985, FP8-einsum precompile sgl-project#42821. - 3B [36-43]: PCIe CustomAllreduce VMM sgl-project#44448, EP local expert ids sgl-project#44480, shm TP broadcast sgl-project#44202, PCIe-IPC all-gather sgl-project#42863 + multicast guard sgl-project#41888, TP-sampling consistency sgl-project#41916/sgl-project#38565, draft embed/lm_head VRAM sgl-project#37155. - sgl-project#39807 toolchain commit verified safe against our CUDA_HOME=12.9 pin (cu13 fallback needs CUDA_HOME unset AND glibc>=2.41; we are 2.39). - stack_want.txt: execution-status banner. Branch tip 5dd6ec7.
…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.
ormandj
force-pushed
the
mhc-prefill-stats-overlap
branch
from
October 29, 2026 22:19
a6a64b6 to
bf274a7
Compare
The wide-prefill overlap recorded each residual on the stats stream, so the caching allocator kept every freed residual until the GPU caught up with the CPU. In a prefill forward that is most of the layers: an 8K chunk held about twenty 320 MiB residuals at once, and the allocator hit its OOM-retry path on every chunk. The post already joins the stats stream before it reads the residual, and the residual is released only after the post, so main-stream reuse is ordered after the mix GEMM without the record.
…record The caller keeps the residual alive until the main stream joins the stats stream, and the caching allocator reuses a freed block only on the stream that allocated it until the block returns to the driver.
ormandj
added a commit
to ormandj/sglang-deepseek-v41-flash-sm120
that referenced
this pull request
Oct 30, 2026
…stats stream Patch 13 (sgl-project/sglang#42985 at e60bfae9de) no longer records each residual on the mHC stats stream. The record kept every freed residual until the GPU caught up with the CPU: an 8K prefill chunk held about twenty 320 MiB residuals at once, and every chunk and startup warmup went through the caching allocator's OOM retry. Same stack key.
Contributor
|
Thanks @ormandj. Closing this because you have 25 PRs open and none updated in 7 days, over our soft cap of 5 for idle PRs. Reopen the two or three you most want reviewed - a short active set moves faster than a long idle one. Some directories moved recently, so an older branch may need retargeting: |
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.
Motivation
#39704 ran each DeepSeek-V4.1 hyper-connection's mix statistics (the mix GEMM and Sinkhorn that produce
pre,postandcomb) on the model-wide stats stream beside that sublayer's TP all-reduce in wide target prefill. The stream forked after the sublayer's compute, right before the collective, and the main stream joined it before the post.#42245 unified mHC into one state machine and listed this as "Dropped for now: wide-prefill stats multistream overlap". Since then
deepseek_v4_mhc.use_stats_streamallows the stream only for decode and target verify, so in prefillrun_attn_postandrun_moe_postcompute the triplet on the main stream after the all-reduce returns. That puts the mix GEMM and Sinkhorn on the critical path twice per layer, for every row of every prefill chunk. At 8192 rows each call reads the full[8192, 4 x 5120]BF16 residual.This PR restores the overlap inside the state-machine design, with the gating #39704 used.
Modifications
deepseek_v4_mhc.use_prefill_stats_overlap(cfg, forward_batch, x)is the per-forward gate. It is true only when all of these hold, which are the conditions of [DSV4.1] Reduce mHC, metadata and small-batch router overhead #39704's_get_hc_stats_streamprefill branch:pre_from_prev(V4.1) without prefill CPdeepseek_v4_mhc.issue_prefill_stats(hc, residual, stats_stream)forks the stats stream from the main stream and issues the triplet on it. It records the three coefficients on the main stream. It does not record the residual on the stats stream. The read state keeps the residual alive untilHcUpdate.posthas joined the stats stream, and the boundary releases it only after the post. Until a freed block returns to the driver, which synchronizes the device, the caching allocator reuses it only for allocations on the stream that allocated it (the main stream), so every reuse is ordered after the mix GEMM. Recording the residual would make the caching allocator hold each freed residual until the GPU caught up with the CPU. In a prefill forward that is most of the layers: an 8192-row chunk would hold about twenty[8192, 4, 5120]BF16 residuals (320 MiB each) at once.In
deepseek_v4_boundary,AttentionTransport.prepare_outputandMoeTransport.prepare_outputcall_issue_prefill_statsright before they hand back the output that still owes its TP sum. This is the point just before the all-reduce, which is where [DSV4.1] Reduce mHC, metadata and small-batch router overhead #39704 forked. The call is skipped when:AttnOutput, for example because it reduced its own output_issue_prefill_statsstores the triplet and the stream on theReadState(stats, newstats_join), andHcUpdate.postjoinsstats_joinbefore running the unchanged post with the precomputed triplet.The static half of the gate is two cached properties on
DeepseekV4DecoderLayerBase, matching [DSV4.1] Reduce mHC, metadata and small-batch router overhead #39704's layer conditions:_can_overlap_attn_stats:pre_from_prev, a stats stream, andtp_size == attn_tp_size == 4_can_overlap_ffn_stats:pre_from_prev, a stats stream, MoEtp_size == 4, and no MoE A2A backendDecode and target verify are unchanged: they still fork before each combine through
use_stats_stream. Other prefill widths, batch-invariant mode and the excluded layouts compute the triplet in line, as on main.The kernels, their inputs and the all-reduce are the same as on main. Only the stream and the issue order of the mix kernels change.
Accuracy Tests
New CPU test
test/registered/unit/models/test_deepseek_v4_mhc_prefill_overlap.py. It drives the real transports'prepare_output, the owed sum's completion andHcUpdate.postwith a mocked layer and recorded streams, and it checks:The kernels, their inputs and the collective are unchanged, so prefill outputs are expected to match main. This expectation is not a measured result.
On the hardware below, short-prompt greedy outputs were bitwise identical between builds with and without this change. Long (8K to 32K) prefills are not bitwise reproducible from run to run even within one build on this setup, so they were not compared exactly. Teacher-forced log-probability and loop checks passed with this change.
Speed Tests and Profiling
Setup: 4x RTX PRO 6000 Blackwell (SM120), TP4 over PCIe (PCIe-IPC all-reduce), 250 W power limit, chunked prefill of 8192 tokens.
Regression after #42245, from a TP0 profiler trace of two cold 32K-token prefills (eight 8192-token chunks), comparing builds from before and after #42245:
End-to-end cold prefill throughput of the same two builds changed by -3.1%, -4.0% and -4.0% at 8K, 32K and 128K tokens. These builds also differ by other upstream commits in that range; the profile attributes the per-chunk loss to the mix kernels moving onto the main stream.
With this PR:
A build with this change on top of the same base: a TP0 trace of the same two cold 32K prefills shows the prefill mix kernels back on the stats stream, overlapping the all-reduce wait, and cold prefill throughput recovers to the pre-#42245 level:
(tok/s, median of 3, same thermal state.) Decode is unaffected: the change only applies to extend batches of 4096 to 65536 rows.
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciDeveloped with AI assistance.
CI States
Latest PR Test (Base): ❌ Run #41019187062
Latest PR Test (Extra): ❌ Run #41019186967
Latest PR Test (AMD ROCm 10): ❌ Run #41019186942