Skip to content

[Spec] Anchor GLM-5.2 MTP IndexShare topk on the draft-extend step - #29787

Merged
ch-wan merged 10 commits into
mainfrom
kpham/glm52-mtp-indexshare-extend-anchor
Jul 7, 2026
Merged

ch-wan merged 10 commits into
mainfrom
kpham/glm52-mtp-indexshare-extend-anchor

Conversation

@kpham-sgl

@kpham-sgl kpham-sgl commented Jul 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Successor of #29654, move the topk capture to draft extend phase. Discuss with @zRzRzRzRzRzRzR offline and we believe this conceptually aligned with GLM 5.2 behaviour

GLM-5.2's MTP (NextN) draft reuses the DSA indexer top-k across draft-decode steps (index_share_for_mtp_iteration) rather than recomputing it each step. Currently the reused top-k is captured on the first draft-decode step, whose query hidden state is the draft model's own step-0 output. That anchor is one step too late — the IndexShare seed should come from the last verified token's (target-derived) hidden state produced during draft-extend.

This PR captures the indexer top-k during draft-extend (gathering the last position per request) and threads that seed through:

  • the draft-decode loop (eagle_worker_v2.py, deepseek_nextn.py),
  • the draft / draft-extend CUDA-graph capture+replay static buffers,
  • EagleDraftInput.filter_batch / merge_batch,
  • the overlap-schedule FutureMap relay (so the seed survives batching / async overlap).

Gated by seed_topk_from_extend, which is active only when index_share_for_mtp_iteration is on and the model exposes index_topk. Non-DSA / non-MTP paths are untouched (short-context DSA-dense requests are unaffected).

Benchmark — accept length, before vs after

nvidia/GLM-5.2-NVFP4, TP4, EAGLE steps=5 / topk=1 / draft=6, temp=0 greedy, natural EOS, kv-cache-dtype=fp8_e4m3, hierarchical cache on. Metric = server-side generation_tokens_total / spec_verify_calls_total from /metrics. before = current main (step-0 anchor, post #29654); after = this PR. 3 replicates/arm, cache flushed per dataset.

dataset out_len before after Δ
mtbench 771 3.631 3.663 +0.032
humaneval 688 4.305 4.333 +0.027
gsm8k 717 4.489 4.490 +0.002
math500 1630 4.599 4.610 +0.010
aime 3899 4.635 4.634 −0.000
openhands_longctx 503 5.115 5.177 +0.061

Notes:

  • The short-prompt/short-output DSA-dense sets (mtbench/humaneval/gsm8k) are where this mechanism is inactive; their deltas are within noise. The intended effect is the long-context sparse regime (openhands_longctx +0.061; larger as context grows).
  • For the record: a prior cross-framework "≈0.6 higher accept" observation on OpenHands turned out to be a degenerate-output artifact (target+draft drift into repeated tokens, trivially inflating accept). It is not used as a target here.

Test plan

  • index_share_for_mtp_iteration on, long-context GLM-5.2 run — accept length matches the numbers above; outputs bit-identical to main at temp=0 (only verify-call count moves).
  • CUDA-graph decode + draft-extend graph paths exercised (--cuda-graph-max-bs-decode), incl. batch grow/shrink (filter/merge) and overlap schedule.
  • Non-DSA model / MTP off — no behavior change (seed path gated off).
  • CI _DEBUG_ASSERT (SGLANG_IS_IN_CI) passes with the new pool-indexed dsa_topk_indices buffer.

Draft: seeking review on the approach + the buffer/relay plumbing before finalizing.


CI States

Latest PR Test (Base): ❌ Run #28751939780
Latest PR Test (Extra): ❌ Run #28751939750

GLM-5.2's MTP (NextN) draft reuses the DSA indexer top-k across
draft-decode steps (index_share_for_mtp_iteration) instead of
recomputing it every step. Today the reused top-k is captured on the
first draft-decode step, whose query hidden state is the draft model's
own step-0 output. Anchoring on that speculative hidden state is one
step too late: the intended IndexShare seed is the last verified
token's (target-derived) hidden state produced during draft-extend.

This change captures the indexer top-k during draft-extend (gathering
the last position per request) and threads that seed through the
draft-decode loop, the draft / draft-extend CUDA-graph capture+replay
static buffers, EagleDraftInput filter/merge, and the overlap-schedule
FutureMap relay so it survives batching. Gated by seed_topk_from_extend
(active only when index_share_for_mtp_iteration is on and the model
exposes index_topk); no effect on non-DSA / non-MTP paths.

Accept-length A/B (GLM-5.2-NVFP4, TP4, EAGLE steps=5/topk=1/draft=6,
temp=0, server-side generation_tokens/spec_verify_calls): context-sweep
pooled long-ctx (8k-72k) 5.116 -> 5.232 (+0.117, n_sd +2.9), with the
gain growing as context grows (ctx_8k +0.105, ctx_32k +0.095, ctx_72k
+0.179). Short-context (DSA dense) is within measurement noise.
@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!

@kpham-sgl
kpham-sgl marked this pull request as ready for review July 1, 2026 06:22
@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!

@kpham-sgl kpham-sgl changed the title [spec] Anchor GLM-5.2 MTP IndexShare topk on the draft-extend step [wip][spec] Anchor GLM-5.2 MTP IndexShare topk on the draft-extend step Jul 1, 2026
@kpham-sgl kpham-sgl changed the title [wip][spec] Anchor GLM-5.2 MTP IndexShare topk on the draft-extend step [Spec] Anchor GLM-5.2 MTP IndexShare topk on the draft-extend step Jul 1, 2026
@zRzRzRzRzRzRzR

Copy link
Copy Markdown
Contributor

#29654 fixed the reuse mechanism itself: previously the carried topk could be lost across per-step forwards, so IndexShare could become effectively a no-op. With #29654, draft step 0 can compute the seed and later draft steps reuse it.

#29787 then refines where the seed comes from for GLM-5.2 MTP: capture the indexer topk during draft-extend on the last verified token, then reuse it in the next draft loop, including draft step 0 and later steps. If the draft-extend seed is unavailable, falling back to draft step 0 computation is still valid.

@JustinTong0323

JustinTong0323 commented Jul 1, 2026 •

Copy link
Copy Markdown
Collaborator

Profiled main (step-0 anchor) vs this PR (extend anchor) to confirm the reused indexer top-k recompute is actually eliminated in the draft-decode loop.

Setup: nvidia/GLM-5.2-NVFP4, TP4, B300, EAGLE steps=5 / topk=1 / draft=6, temp=0. Served eager (--disable-cuda-graph --disable-overlap-schedule) so the per-step indexer kernels are individually visible in the torch-profiler trace. Each indexer compute is attributed to its caller by call-tree nesting (draft_forward = draft-decode loop, _draft_extend = extend).

The two captures happened to cover a different number of decode cycles (9 draft-decode loops before, 11 after), so counts are normalized per loop (raw shown as n/loops):

indexer computes, per draft-decode loop before (main) after (this PR)
inside the loop — _get_topk_paged 1.000 (9/9) 0.000 (0/11)
inside the loop — fp8_paged_mqa_logits 1.000 (9/9) 0.000 (0/11)
in _draft_extend (per cycle) 1.000 (9/9) 1.000 (11/11)

The reused top-k is now seeded entirely from draft-extend: the redundant recompute at draft-decode step 0 is gone (1 → 0 per loop), while _draft_extend still computes it once per cycle (rate unchanged). In the trace, step-0's nextn.forward shrinks by ~250 µs — the forward_cuda (407 µs) → _get_topk_paged (110 µs) → fp8_paged_mqa_logits (36 µs) cluster disappears.

Commits profiled: before = 5b76f55d90 (PR parent), after = 8f935f431b (PR head).

@JustinTong0323

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Jul 1, 2026
@JustinTong0323 JustinTong0323 added the run-ci-extra CI: also run the extra suite (requires run-ci) label Jul 1, 2026
buffers.mtp_seed_topk is accessed under an is-not-None guard in execute()/replay(); the white-box mock's SimpleNamespace lacked the attribute, so every test errored with AttributeError. Add None so the guard short-circuits.
@JustinTong0323

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

EagleWorkerV2.draft_forward reads self.seed_topk_from_extend (gated by index_share_for_mtp_iteration and dsa_index_topk). The white-box _EagleDraftWorkerHarness already mocks index_share_for_mtp_iteration but skipped the two new attrs added by the MTP IndexShare-extend PR, so any eagle-draft runner case errored with AttributeError. Mirror the worker's definition so the guard short-circuits.
EAGLEDraftExtendCudaGraphRunner reads self.eagle_worker.seed_topk_from_extend and .dsa_index_topk (eagle_draft_extend_cuda_graph_runner.py). The white-box _EagleDraftExtendV2WorkerHarness skipped both new attrs added by the MTP IndexShare-extend PR, so the runner_fa3_eagle_draft_extend_v2_cuda_graph_runner_fixed_tokens case errored with AttributeError. Mirror EagleWorkerV2's definition (index_share_for_mtp_iteration + dsa_index_topk + seed_topk_from_extend) so the guard short-circuits.
@JustinTong0323

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

1 similar comment
@JustinTong0323

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

…c topk

- mtp_topk_indices -> dsa_topk_indices (EagleDraftInput, RelayPayload, FutureMap buf)
- reuse_mtp_topk_indices -> reuse_dsa_topk_indices (ForwardBatch flag)
- mtp_seed_topk / mtp_seed_topk_capture / mtp_seed_topk_select -> dsa_seed_topk*
- seed_topk_from_extend -> seed_dsa_topk_from_extend
- _extend_topk_buf -> _get_dsa_extend_topk_buf; locals dsa-prefixed

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

@ch-wan ch-wan 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.

LGTM

@ch-wan
ch-wan merged commit 16372b4 into main Jul 7, 2026
144 of 167 checks passed
@ch-wan
ch-wan deleted the kpham/glm52-mtp-indexshare-extend-anchor branch July 7, 2026 03:36
JustinTong0323 added a commit to JustinTong0323/sglang that referenced this pull request Jul 7, 2026
…-extend seed

Upstream sgl-project#29787 renamed the carry (reuse_dsa_topk_indices /
spec_info.dsa_topk_indices) and made begin conditionally keep a
draft-extend-seeded carry. mtp_iteration gains keep_carry_seed to wrap the
new begin semantics; the NextN draft-extend seed publish stays raw (capture
buffer, not the carry lifecycle).
stellaxcpeng added a commit to stellaxcpeng/sglang that referenced this pull request Jul 11, 2026
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
…gl-project#29787)

Co-authored-by: kpham-sgl <[email protected]>
Co-authored-by: Xinyuan Tong <[email protected]>
Co-authored-by: Xinyuan Tong <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deepseek run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci) speculative-decoding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants