Skip to content

[bug-fix] Stabilize GLM-5.2 MTP IndexShare across PD and CUDA graph replay - #30839

Merged
Fridge003 merged 15 commits into
sgl-project:mainfrom
zRzRzRzRzRzRzR:glm5
Jul 14, 2026
Merged

Fridge003 merged 15 commits into
sgl-project:mainfrom
zRzRzRzRzRzRzR:glm5

Conversation

@zRzRzRzRzRzRzR

@zRzRzRzRzRzRzR zRzRzRzRzRzRzR commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

This PR makes GLM-5.2 MTP IndexShare reliable across PD disaggregation, context parallelism, overlap scheduling, batch splitting, and CUDA graph replay. It preserves the correct draft-extend DSA seed across draft steps, avoiding redundant indexer computation without reusing stale or misaligned indices. This improves proposal consistency, acceptance length stability, and inference performance.

This is a follow-up to #29787. The optimization remains gated to EAGLE with speculative_eagle_topk == 1, index_share_for_mtp_iteration=true, and a valid index_topk.

Modifications

  • Transfer per-request DSA top-k seeds from prefill nodes to decode nodes in PD disaggregation, with explicit invalid sentinels and retry-state cleanup.
  • Unify eager and CUDA-graph seed capture through LogitsProcessorOutput, including correct last-token extraction after CP gather/reordering.
  • Preserve seed alignment across context parallelism and Two-Batch Overlap splitting.
  • Keep reusable seed state across copied forward batches and graph capture/replay.
  • Track seed validity in FutureMap to prevent stale overlap/PD state, and fall back to eager recomputation when no valid seed is available.
  • Refresh paged-MQA schedules, top-k-v2 plans, and per-step metadata during multi-step DSA graph replay.
  • Resolve DSA context-parallel aliases from the effective attention backend.

CI States

Latest PR Test (Base): ❌ Run #29295157846
Latest PR Test (Extra): ⏳ Run #29295157815

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@zRzRzRzRzRzRzR

Copy link
Copy Markdown
Contributor Author

/tag-and-rerun-ci

@zRzRzRzRzRzRzR

Copy link
Copy Markdown
Contributor Author

/tag-and-rerun-ci

@kpham-sgl kpham-sgl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for catching these issues! Can we split this PR into multiple parts to speedup review and merging for post1 image? I recommend splitting into the following parts

  1. PD Transfer and any necessary spec v2, cudagraph, forward batch changes along with it
  2. MTP with CP enabled changes
  3. MQA metadata refresh

Comment thread python/sglang/srt/managers/scheduler.py Resolved
Comment on lines +520 to +526
if (
can_cuda_graph
and not forward_batch.forward_mode.is_idle()
and self.index_share_for_mtp_iteration
and draft_input.dsa_topk_indices is None
):
can_cuda_graph = False

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does draft cudagraph need to be turned off here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fallback triggered when the runtime batch lacks the draft-extend DSA seed.

The draft graph is captured assuming a seed exists (dsa_topk_indices is bound to a static buffer). With a None seed, replay zero-fills the buffer — and since 0 is a valid DSA index, the graph silently reuses wrong indices. The eager path correctly recomputes the indexer at step 0, with later MTP steps reusing the result.

Normal PD batches with a seed still use CUDA Graph. Capturing a separate no-seed graph variant per batch size isn't worth it for this rare path, so it falls back to eager.

@kpham-sgl kpham-sgl self-assigned this Jul 12, 2026
@zRzRzRzRzRzRzR

Copy link
Copy Markdown
Contributor Author

Thank you for catching these issues! Can we split this PR into multiple parts to speedup review and merging for post1 image? I recommend splitting into the following parts

1. PD Transfer and any necessary spec v2, cudagraph, forward batch changes along with it

2. MTP with CP enabled changes

3. MQA metadata refresh

I have narrowed this PR to Part 1: PD transfer of the
GLM-5.2 DSA top-k seed, together with the required request/batch, overlap, and
CUDA Graph lifecycle changes.

The MTP + context-parallel changes and the MQA metadata refresh have been
removed from this PR and will be submitted separately.

@kpham-sgl kpham-sgl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One concern here is during PD Disagg, some recipes don't turn on speculative decoding for P workers but only D. In this settings, seems like no-one will do draft_extend_for_prefill (important for GLM 5.2 MTP)

Maybe cc @Fridge003 for more context on previous PD Disagg deployments

if self.output_dsa_topk_indices is not None:
ptrs.insert(-1, self.output_dsa_topk_indices.data_ptr())
data_lens.insert(-1, self.output_dsa_topk_indices.nbytes)
item_lens.insert(-1, self.output_dsa_topk_indices[0].nbytes)

@kpham-sgl kpham-sgl Jul 12, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this break when speculative decoding is enabled only on the decode node? Prefill would send 10 buffers while decode expects 11, and inserting DSA before bootstrap_room means the two sides interpret the same position differently.

kpham-sgl and others added 2 commits July 13, 2026 14:51
…nput defaults

Declare dsa_topk_indices / future_dsa_topk_indices_available /
dsa_seed_topk_capture as class-level defaults on SpecInput (same
pattern as ragged_verify_layout), so the scheduler, FutureMap relay,
PD transfer, and MHA indexer read them uniformly on any SpecInput
without hasattr/getattr fallbacks. Req.output_dsa_topk_indices is
always initialized in Req.__init__, so those getattrs go too.

Co-Authored-By: Claude Fable 5 <[email protected]>
@kpham-sgl

Copy link
Copy Markdown
Collaborator

/rerun-test test/registered/models_e2e/test_dsa_glm52_dp_mtp.py test/registered/8-gpu-models/test_deepseek_v32_indexcache.py

@github-actions

github-actions Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/models_e2e/test_dsa_glm52_dp_mtp.py test/registered/8-gpu-models/test_deepseek_v32_indexcache.py:

🚀 8-gpu-h200 (2 tests): ✅ View workflow run

cd test/ && python3 registered/models_e2e/test_dsa_glm52_dp_mtp.py
cd test/ && python3 registered/8-gpu-models/test_deepseek_v32_indexcache.py

Resolve conflict in disaggregation/utils.py: keep both the PR's
output_dsa_topk_indices metadata buffer (inserted before bootstrap_room)
and main's sampling-mask buffers in the refactored get_buf_infos.

Co-Authored-By: Claude Fable 5 <[email protected]>
Main's sgl-project#27408 added an unconditional req.return_sampling_mask read in
MetadataBuffers.set_buf; the SimpleNamespace req stub predates it.

Co-Authored-By: Claude Fable 5 <[email protected]>
kpham-sgl added a commit that referenced this pull request Jul 14, 2026
…eplay

Backport of #30839 to release/v0.5.15 (squashed).

Co-Authored-By: Claude Fable 5 <[email protected]>
@kpham-sgl

kpham-sgl commented Jul 14, 2026 •

Copy link
Copy Markdown
Collaborator

Internal nightly run #0e8ae04b has passed GSM8K. Accept length of PD Disagg also looks healthy > 5

@Fridge003

Copy link
Copy Markdown
Collaborator

@junliu-mde The padding issue should be fixed in cbc7fd5

@kpham-sgl

Copy link
Copy Markdown
Collaborator

#31083 (comment)

@kpham-sgl

Copy link
Copy Markdown
Collaborator

Accept-length A/B (main vs this PR) — no regression

Ran a same-config A/B to check acceptance length isn't hurt by this PR. nvidia/GLM-5.2-NVFP4, TP4 (GB300), EAGLE steps=5 / topk=1 / draft=6, temp=0, kv-cache-dtype=fp8_e4m3, reasoning_effort=high. Metric = server-side generation_tokens_total / spec_verify_calls_total from /metrics, cache flushed per run. main @ 50ed4c01 vs PR head @ 96226f36.

dataset reps main this PR Δ
mtbench 6 4.037 3.987 −0.049
humaneval 3 4.898 4.897 −0.001
gsm8k 3 4.892 5.043 +0.151
math500 3 4.827 4.808 −0.018
aime25 3 4.992 4.922 −0.070

Accept length is flat within run-to-run noise on 4/5 datasets and slightly higher on gsm8k — no degradation from the PR. (mtbench was −0.205 at 3 reps but regresses to −0.049 at 6 reps, i.e. noise.)

Notes: single-node (no PD), but the CUDA-graph-replay + overlap-schedule seed paths are exercised. This is not a reproduction of #29787's table (different reasoning effort → different out_len), and openhands_longctx (the PR's primary long-context target) was not included.

@Fridge003
Fridge003 merged commit 78dc581 into sgl-project:main Jul 14, 2026
202 of 248 checks passed
Fridge003 pushed a commit that referenced this pull request Jul 14, 2026
…oss PD and CUDA graph replay (#30839) (#31083)

Co-authored-by: Claude Fable 5 <[email protected]>
@zRzRzRzRzRzRzR
zRzRzRzRzRzRzR deleted the glm5 branch July 14, 2026 05:01
HanHan009527 added a commit to bytedance-iaas/sglang that referenced this pull request Aug 22, 2026
Backport the rank-consistency half of sgl-project#32209 (follow-up
to sgl-project#30839, issue sgl-project#29144) onto the deployed poc_glm5.2 baseline.

Root cause (PD decode + DP attention + GLM-5.2 EAGLE MTP): on a seedless
DSA IndexShare round, the DP rank holding the real long request runs the
MTP draft eagerly while idle peers replay the draft CUDA graph. The ranks
diverge into different collective phases, DeepEP low_latency dispatch/combine
waits on a device-side handshake that never arrives, the scheduler loop
blocks, the detokenizer heartbeat freezes, and /health_generate 503s -> the
node is SIGTERM'd (crash at dp_attn all_gather_into_tensor / gloo
"Connection closed by peer").

Fix: fold a rank-consistent draft-graph eligibility vote into the EXISTING
MLP-sync all-gather (no new collective). A seedless draft rank sets
force_disable_draft_cuda_graph; the all-gather min()-reduces the new
can_draft_cuda_graph field so every DP/MoE rank in the cohort takes the same
eager-vs-graph path for the draft phase only. Target verify and draft-extend
keep replaying their own graphs (narrowed per dee050c). The vote is
overlap-aware: when FutureMap will resolve inputs after this scheduler-side
vote, it trusts future_dsa_topk_indices_available instead of the possibly
stale dsa_topk_indices (per 93cc0fa).

Upstream refs (combined form): d619cd9 + 93cc0fa + dee050c.
The eager-output unpad / DP-padding halves (5af5267, 8765784) were
already present in the baseline as a48549b / db92ab8.

Files:
- disaggregation/decode.py: set force_disable_draft_cuda_graph before MLP sync
- speculative/eagle_worker_v2.py: requires_dp_attention_eager_forward (overlap-aware)
- speculative/base_spec_worker.py: default returns False
- managers/schedule_batch.py: can_run_dp_draft_cuda_graph + force_disable_draft_cuda_graph
- managers/scheduler_components/dp_attn.py: 8th all-gather field can_draft_cuda_graph
- model_executor/forward_batch_info.py: propagate can_run_dp_draft_cuda_graph
- speculative/eagle_draft_cuda_graph_runner.py: AND draft-graph gate into can_run

Co-authored-by: TRAE CLI <[email protected]>
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
HanHan009527 added a commit to bytedance-iaas/sglang that referenced this pull request Sep 15, 2026
Backport the rank-consistency half of sgl-project#32209 (follow-up
to sgl-project#30839, issue sgl-project#29144) onto the deployed poc_glm5.2 baseline.

Root cause (PD decode + DP attention + GLM-5.2 EAGLE MTP): on a seedless
DSA IndexShare round, the DP rank holding the real long request runs the
MTP draft eagerly while idle peers replay the draft CUDA graph. The ranks
diverge into different collective phases, DeepEP low_latency dispatch/combine
waits on a device-side handshake that never arrives, the scheduler loop
blocks, the detokenizer heartbeat freezes, and /health_generate 503s -> the
node is SIGTERM'd (crash at dp_attn all_gather_into_tensor / gloo
"Connection closed by peer").

Fix: fold a rank-consistent draft-graph eligibility vote into the EXISTING
MLP-sync all-gather (no new collective). A seedless draft rank sets
force_disable_draft_cuda_graph; the all-gather min()-reduces the new
can_draft_cuda_graph field so every DP/MoE rank in the cohort takes the same
eager-vs-graph path for the draft phase only. Target verify and draft-extend
keep replaying their own graphs (narrowed per dee050c). The vote is
overlap-aware: when FutureMap will resolve inputs after this scheduler-side
vote, it trusts future_dsa_topk_indices_available instead of the possibly
stale dsa_topk_indices (per 93cc0fa).

Upstream refs (combined form): d619cd9 + 93cc0fa + dee050c.
The eager-output unpad / DP-padding halves (5af5267, 8765784) were
already present in the baseline as a48549b / db92ab8.

Files:
- disaggregation/decode.py: set force_disable_draft_cuda_graph before MLP sync
- speculative/eagle_worker_v2.py: requires_dp_attention_eager_forward (overlap-aware)
- speculative/base_spec_worker.py: default returns False
- managers/schedule_batch.py: can_run_dp_draft_cuda_graph + force_disable_draft_cuda_graph
- managers/scheduler_components/dp_attn.py: 8th all-gather field can_draft_cuda_graph
- model_executor/forward_batch_info.py: propagate can_run_dp_draft_cuda_graph
- speculative/eagle_draft_cuda_graph_runner.py: AND draft-graph gate into can_run

Co-authored-by: TRAE CLI <[email protected]>
HanHan009527 added a commit to bytedance-iaas/sglang that referenced this pull request Sep 16, 2026
Backport the rank-consistency half of sgl-project#32209 (follow-up
to sgl-project#30839, issue sgl-project#29144) onto the deployed poc_glm5.2 baseline.

Root cause (PD decode + DP attention + GLM-5.2 EAGLE MTP): on a seedless
DSA IndexShare round, the DP rank holding the real long request runs the
MTP draft eagerly while idle peers replay the draft CUDA graph. The ranks
diverge into different collective phases, DeepEP low_latency dispatch/combine
waits on a device-side handshake that never arrives, the scheduler loop
blocks, the detokenizer heartbeat freezes, and /health_generate 503s -> the
node is SIGTERM'd (crash at dp_attn all_gather_into_tensor / gloo
"Connection closed by peer").

Fix: fold a rank-consistent draft-graph eligibility vote into the EXISTING
MLP-sync all-gather (no new collective). A seedless draft rank sets
force_disable_draft_cuda_graph; the all-gather min()-reduces the new
can_draft_cuda_graph field so every DP/MoE rank in the cohort takes the same
eager-vs-graph path for the draft phase only. Target verify and draft-extend
keep replaying their own graphs (narrowed per dee050c). The vote is
overlap-aware: when FutureMap will resolve inputs after this scheduler-side
vote, it trusts future_dsa_topk_indices_available instead of the possibly
stale dsa_topk_indices (per 93cc0fa).

Upstream refs (combined form): d619cd9 + 93cc0fa + dee050c.
The eager-output unpad / DP-padding halves (5af5267, 8765784) were
already present in the baseline as a48549b / db92ab8.

Files:
- disaggregation/decode.py: set force_disable_draft_cuda_graph before MLP sync
- speculative/eagle_worker_v2.py: requires_dp_attention_eager_forward (overlap-aware)
- speculative/base_spec_worker.py: default returns False
- managers/schedule_batch.py: can_run_dp_draft_cuda_graph + force_disable_draft_cuda_graph
- managers/scheduler_components/dp_attn.py: 8th all-gather field can_draft_cuda_graph
- model_executor/forward_batch_info.py: propagate can_run_dp_draft_cuda_graph
- speculative/eagle_draft_cuda_graph_runner.py: AND draft-graph gate into can_run

Co-authored-by: TRAE CLI <[email protected]>
Edward-lyz pushed a commit to Edward-lyz/sglang that referenced this pull request Nov 10, 2026
…h 下稳定化

来源提交(1 个):1bee78dc11
原标题:[Cherry-pick to release/v0.5.15] Stabilize GLM-5.2 MTP IndexShare across PD and CUDA graph replay (sgl-project#30839) (sgl-project#31083)
作者:Khoa Pham,日期:2026-07-13
luno:-
开关:SGLANG_DSA_FUSE_TOPK
默认:开
改动规模:27 files changed, 638 insertions(+), 60 deletions(-)
主要目录:python/sglang/srt/speculative, python/sglang/srt/disaggregation, python/sglang/srt/managers, python/sglang/srt/layers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bypass-fastfail deepseek high priority post version patch run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants