Skip to content

[spec] Fix index_share_for_mtp_iteration being a no-op in EAGLE MTP draft - #29654

Merged
Fridge003 merged 3 commits into
sgl-project:mainfrom
JustinTong0323:xinyuan/mtp-index-share-cudagraph
Jun 29, 2026
Merged

Fridge003 merged 3 commits into
sgl-project:mainfrom
JustinTong0323:xinyuan/mtp-index-share-cudagraph

Conversation

@JustinTong0323

@JustinTong0323 JustinTong0323 commented Jun 29, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

index_share_for_mtp_iteration (#28192) is meant to run the DSA indexer once on the first MTP draft step and reuse its top-k for the remaining steps. It's a silent no-op — the reuse never engages, so every draft step recomputes the indexer.

Cause

Each draft step forwards on a copied ForwardBatch (load_batch → extract_buffer/replace). The write-back in deepseek_nextn

forward_batch.topk_indices = topk_indices

lands on that per-step copy, while the ForwardBatch the draft loop carries across steps keeps topk_indices = None. So prev_topk_indices is always None and step 0's selection is never reused.

It went unnoticed because at short context the indexer selects all tokens (ctx < index_topk), so reuse and recompute are bit-identical; the paths only diverge once the selection actually prunes.

Fix

Carry the top-k on spec_info (EagleDraftInput.mtp_topk_indices), which is shared by reference across the per-step forwards the same way hidden_states already is, so the write-back survives. Removes the now-dead ForwardBatch.topk_indices field.

Models that don't set the flag are unaffected — the flag (and topk == 1) gates the whole path.

Test

GLM-5.2-FP8 on 4×B300 (EAGLE topk=1, num_steps=5, num_draft_tokens=6). Verified the reuse now engages — step 0 computes the indexer, steps 1–3 reuse it — matching the deterministic-top-k design. On an OpenHands-style long-context agentic workload (~89k ISL, 13-turn) the accept length is neutral with vs without the fix (4.64 vs 4.65), i.e. the change is behavior-preserving for draft quality while removing the redundant per-step indexer recompute and restoring the intended path. Spec decode is lossless regardless — only the draft proposal changes, not target verify.

Performance

At long context (ISL ≈ 500k) the redundant per-step indexer recompute dominates a draft step. Profiling one draft step:

reuse draft step time
ON (this PR) 2.215 ms
OFF (main) 4.167 ms

1.88× faster per draft step (4.167 → 2.215 ms, ~47% less time) — the indexer now runs once (step 0) and is reused by steps 1–3 instead of recomputed each step. The gain scales with context (indexer cost ∝ sequence length): large at ~500k, smaller at the ~80k agentic regime.

Draft-step profile (reuse ON):

image

Draft-step profile (reuse OFF, main):

image

CI States

Latest PR Test (Base): ⏳ Run #28386073348
Latest PR Test (Extra): 🚫 Run #28397012447

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request moves the storage of NSA/DSA indexer-topk indices from ForwardBatch to spec_info (EagleDraftInput.mtp_index_topk) to prevent writebacks from being lost when ForwardBatch is copied during execution. The feedback suggests adding defensive checks when accessing and writing to spec_info.mtp_index_topk to avoid potential AttributeErrors if spec_info is None or lacks the attribute.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

…raft

index_share_for_mtp_iteration (sgl-project#28192) is meant to run the DSA indexer once
on the first MTP draft step and reuse its top-k for the remaining steps. It
never engaged.

Each draft step forwards on a copied ForwardBatch (load_batch ->
extract_buffer/replace), so the write-back in deepseek_nextn

    forward_batch.topk_indices = topk_indices

lands on the per-step copy, while the ForwardBatch the draft loop carries
across steps keeps topk_indices=None. prev_topk_indices is then always None
and every step recomputes the indexer instead of reusing step 0's selection.

Carry the top-k on spec_info (EagleDraftInput.mtp_topk_indices) instead, which
is shared by reference across the per-step forwards the same way
hidden_states already is, so the write-back survives. Drop the now-dead
ForwardBatch.topk_indices field.

It went unnoticed because at short context the indexer selects all tokens
(ctx < index_topk), so reuse and recompute are bit-identical; the paths only
diverge once the selection actually prunes.
@JustinTong0323
JustinTong0323 force-pushed the xinyuan/mtp-index-share-cudagraph branch from ecc70f1 to b2a1c27 Compare June 29, 2026 13:19
@JustinTong0323

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Jun 29, 2026
@JustinTong0323

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

@kpham-sgl kpham-sgl self-assigned this Jun 29, 2026
@JustinTong0323 JustinTong0323 added the run-ci-extra CI: also run the extra suite (requires run-ci) label Jun 29, 2026
@JustinTong0323

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

@Fridge003
Fridge003 merged commit 45314a9 into sgl-project:main Jun 29, 2026
227 of 296 checks passed
vstone-w pushed a commit to ClownBin/sglang that referenced this pull request Jul 2, 2026
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants