Repository navigation
[Fix] glm-5.2: Record side-stream work right before its join to keep CUDA-graph replay on one stream - #45349
Conversation
This comment has been minimized.
This comment has been minimized.
…e graphs At CUDA-graph replay a join node continues on the stream of its first-recorded parent, so a side-stream block captured before the concurrent main-stream kernels pulls the main chain onto a side lane. GLM-5.2 decode graphs replayed across 123 distinct streams in a 10-step window (45 in a 30 ms slice), with each layer's indexer chain on its own stream. Keep both forks where they are and capture the side block right before its join: - dsa_indexer: _fused_q_prepare_and_store stage 1, alt wq_b after main wk_weights_proj. - forward_mla: decode-graph q_b_proj on alt_stream after the DSA indexer; k_nope.unsqueeze(1) (a view) runs on main. With this change the same window shows 81 streams (3 in the 30 ms slice) and the same kernel count. Median TPOT at concurrency 1/8/16 on dummy-weight GLM-5.2-NVFP4 TP4 moves from 10.51/11.88/13.33 ms to 10.43/11.78/13.28 ms (one run per arm, within noise). Same approach as sgl-project#39420 for DSV4.1. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
c5fd067 to
b7bf407
Compare
This comment has been minimized.
This comment has been minimized.
|
/rerun-test test/registered/e2e/models/test_dsa_glm52_nvfp4_tp_mtp.py test/registered/e2e/models/test_dsa_glm52_nvfp4_dp_mtp.py test/registered/e2e/models_large/test_deepseek_v32_indexcache.py test/registered/rl/test_return_indexer_topk.py test/registered/e2e/models_large/test_glm52_fp8.py test/registered/e2e/models/test_dsa_glm52_tp_mtp.py test/registered/e2e/models/test_dsa_glm52_dp_mtp.py test/registered/gb300/test_glm52_nvfp4.py test/registered/dcp/test_glm53_dcp2.py test/registered/cp/test_dsa_prefill_cp.py test/registered/ep/test_deepep_large.py test/registered/e2e/models/test_dsa_glm52_hisparse.py test/registered/e2e/models/test_dsa_glm52_pd_mtp_cp_layersplit.py test/registered/radix_cache/unified_radix_tree/linker/test_unified_cache_linker_kl_glm52.py test/registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_glm52.py test/registered/cp/test_glm53_flash_cp.py test/registered/e2e/models/test_glm53_flash_h200_low_latency.py test/registered/e2e/models/test_glm53_flash_h200_high_throughput.py test/registered/e2e/models/test_glm53_flash_b200.py |
|
🚀 🚀 🚀 🚀 🚀 |
|
@YAMY1234 could you review this tiny change? Thanks! |
|
Merging this since this is a tiny change and glm tests have passed. |
Motivation
On GLM-5.2 (
GlmMoeDsaForCausalLM), a CUDA-graph decode replay spreads across many CUDA streams, so a profiler trace ishard to read: each layer's indexer chain lands on a different stream row.
This is the same issue as DeepSeek-V4.1 in #39420. That PR found that at graph replay a join node continues on the stream
of its first-recorded parent. A side-stream block captured before the concurrent main-stream kernels therefore pulls the
main chain onto a side lane at the join. Its fix keeps the fork where it is and captures the side-stream work right before
the join.
Inspired by and following the approach of #39420 ("[DSV4.1] Record side-stream work right before its join").
Modifications
Two side-stream blocks on the GLM-5.2 decode path were captured before the main-stream kernels they run alongside. In
both, the fork (
alt_stream.wait_stream(current_stream)) stays where it was, and only the capture order of the side blockchanges.
python/sglang/srt/layers/attention/dsa/dsa_indexer.py,_fused_q_prepare_and_store, stage 1: thewq_bGEMM onalt_streamis now captured after the main-streamwk_weights_proj, right before the join.python/sglang/srt/models/deepseek_common/attention_forward_methods/forward_mla.py(decode graphs, DSA path): theq_b_projblock onalt_streamis now captured after the indexer, right beforecurrent_stream.wait_stream(self.alt_stream).k_nope.unsqueeze(1), a view with no kernel, now runs on the main stream.I checked the rest of the GLM-5.2 path and found no other active violation under TP4 / NVFP4 /
flashmla_kv. Inparticular,
DeepseekV2MoE.forward_normal_dual_streamalready issues the routed experts before the shared-expert sideblock, and stage 2 of the fused indexer is already ordered correctly.
Test:
test/registered/unit/layers/attention/test_dsa_indexer_stream_order.pypins the issue order of the stage-1 block(fork, main GEMM, alt
wq_b, join). It fails without the change and passes with it.Results
GLM-5.2-NVFP4, aggregated serving, TP=4, CUDA graphs on, dummy weights, GB200 x4. One run per arm, rank TP1, same load for
both.
Distinct CUDA streams seen in the profiler trace:
In the baseline, 99 of the 123 streams are tiny, each carrying a few kernels of the indexer chain
(
fused_q_indexer_rope_hadamard_quant,sm100_paged_mqa_logits,topk_small_batch_cluster_kerneland a TgvGemm kernel).With this PR those streams disappear: two main lanes carry about 13.3k and 9.8k kernels. The kernel count is identical
(23,324 vs 23,319), so the same work runs.
Median TPOT (
sglang.bench_serving, random 512 in / 256 out):No regression. The 0.4% to 0.8% gain is within single-run noise and is not claimed as a speedup.
Reproduce
Model files only, no weights (config and tokenizer from
nvidia/GLM-5.2-NVFP4; weights are random via--load-format dummy):Server (run once on
mainand once on this branch):TPOT at concurrency 1, 8 and 16:
Trace of a steady-state decode window (start profiling about 6 s into the run, while it is decoding):
Count distinct streams per rank: read the trace JSON, take events with
ph == "X"andcat == "kernel", and count thedistinct
args.streamvalues. The full traces are 330 to 460 MB each. For Perfetto, cut a 30 ms window from one rank soit loads.
Notes and limits
generated outputs.
2.14.1+cu130, driver 580.x).
forward_mla.pyedit movesq_b_projafter the indexer. A reviewer raised a theoretical allocator-reuse hazard:tensors the indexer allocates on
alt_streamare freed at return, and the trailingq_b_projcould reuse a block while amain-stream kernel still reads it. I did not reproduce a failure, and the A/B shows no change in throughput. I have not
proven it safe either, so please look at this one closely.
separate stream hop that this PR does not touch.
is_decode_or_idle). The target-verify and draft-extend graphs do not take theforward_mla.pyoverlap branch.Checklist
The diff is still uncommitted on glm52-graph-stream-fork, and nothing is pushed. Two things to decide before you post it:
limits". I'd leave it in; the alternative is dropping that edit or adding a keep-alive fix.
Perfetto screenshots (30 ms slice, rank TP1):
before PR:


after PR:
CI States
Latest PR Test (Base): ❌ Run #39392800055
Latest PR Test (Extra): ❌ Run #39392800085
Latest PR Test (AMD ROCm 10): ❌ Run #39392800119
cc. @nvpohanh @BBuf