Repository navigation
Conversation
There was a problem hiding this comment.
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.
ecc70f1 to
b2a1c27
Compare
|
/tag-and-rerun-ci |
|
/rerun-failed-ci |
|
/rerun-failed-ci |
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 indeepseek_nextnlands on that per-step copy, while the ForwardBatch the draft loop carries across steps keeps
topk_indices = None. Soprev_topk_indicesis 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 wayhidden_statesalready is, so the write-back survives. Removes the now-deadForwardBatch.topk_indicesfield.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:
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):
Draft-step profile (reuse OFF, main):
CI States
Latest PR Test (Base): ⏳ Run #28386073348
Latest PR Test (Extra): 🚫 Run #28397012447