Skip to content

fix(turbomind): harden MTP/speculative serving [stacked on #5006] - #5144

Draft
richardclli wants to merge 4 commits into
InternLM:mainfrom
richardclli:pr/mtp-fixes
Draft

richardclli wants to merge 4 commits into
InternLM:mainfrom
richardclli:pr/mtp-fixes

Conversation

@richardclli

@richardclli richardclli commented Nov 17, 2026 •

Copy link
Copy Markdown

Summary

Stacked on #5006 (TurboMind
speculative decoding). This PR adds three correctness fixes that multi-token
speculation exposes: a latent base-upstream MoE-gate out-of-bounds, a
cross-stream logits race, and the speculative KV margin at admission.

Once #5006 is merged, the diff of this PR shrinks to exactly the three fix
commits. SM75 validation additionally ran on
#5019 (GDN half_t + method
alias), but the code here does not depend on it.

Motivation

Multi-token speculation exposes three latent serving bugs. None is introduced by
the MTP framework; they are correctness gaps that the speculative path reproduces
reliably on SM75 (RTX 2080 Ti), and the first also affects any MoE deployment with
degenerate router logits.

Modification

  • MoE gate: initialize routing slots to a skip sentinel and bounds-check the
    expert id, so a valid token that selects fewer than top_k experts no longer
    indexes masks[] out of range. Applies to both the v8 and noaux_tc gate
    kernels.
  • Speculative serving: synchronize the target-pass logits before publishing them;
    the sampler runs on another stream and the first step could hang on stale data.
  • Admission: reserve 2 * (max_proposals + 1) rows below session_len so a
    speculative round cannot write past the allocated KV columns; oversized prompts
    return a clean kTooLong and generation is truncated to the limit.

Dependency note

Kind Required Why
Code #5006 MTP framework
SM75 runtime #5019 GDN half_t and method alias; needed to run, not to build
Validation evidence #5142 SM75 numbers were measured on the NVFP4 checkpoints that PR adds; the code here is format-independent

The MoE-gate fix is format-independent; #5142 is only how the 35B-A3B NVFP4
grouped-expert lane was exercised. FP8/half checkpoints can reproduce the fixes
if #5142 is unavailable.

Validation

  • New MoE-gate regression test for a valid token with fewer than top_k finite
    logits; tests/turbomind/moe_gate 21/21.
  • 35B-A3B MTP: crash repro gone; 120 concurrent speculative requests, 0 crashes.
  • Speculative KV-margin probe: 262015+128 -> 200 (truncated 123); 262130+16 ->
    200 (truncated 8); 262144 and 262200 -> 400, no BatchCopy abort.
  • MTP-2 4K fp16 46.0 -> 75.8 t/s (1.65x); canary 27B MTP-2 10/10 and
    35B-A3B MTP-4 10/10; MTP needle 4K/32K/128K.

The KV-margin figures above (truncated 123 and 8) supersede the earlier
"trunc 113" wording in the commit message; the re-measured numbers are
authoritative.

BC-breaking

None. Behavior changes only in degenerate/oversized cases, where it replaces a
crash with a clean skip, truncation, or kTooLong.

Notes

The MoE-gate fix addresses a latent base-upstream bug that exists independently
of the MTP framework; it is grouped here because multi-token speculation is the
reliable repro. It can be split into a standalone main-targeted PR on request.
SM75 is the validation platform, not the scope of the fixes.

lzhangzz and others added 4 commits September 28, 2026 12:50
- Fixed-chain speculator base with EAGLE3 and Qwen3.5 MTP draft models,
  target-native speculation, and method-keyed draft weight registry
- Block speculative verification: paged CuTe verification attention,
  SM90 GDR verify and commit kernels with persistent pipelining
- Unified parameterized batch-op pipeline; executor forward split into
  target pass and speculative round; host batch ops moved engine-side
- Scheduler: unified required admission, simplified rollback, submitted
  rows carry producer-set effects instead of a kind tag
- Op-level pytest suites: verification attention, draft carry,
  speculative sampling, speculative sequence, target hidden projection,
  copy
ROOT CAUSE: MoeGateKernel_v8 / MoeGateNoAuxTCKernel_V2 (noaux_tc gate). When a
token yields fewer than top_k selectable experts (NaN/-inf router logits collapse
max_i), some of the top_k selection steps clear no slot, leaving holes in
smem.shared_exp_id. The routing write then read such an uninitialized slot as an
expert id and indexed masks[expert_id*token_num_padded+ti2] out of range -> CUDA
illegal memory access (cuda-gdb: 'Warp Out-of-range Address', expert_id=-1132287279).
Timing-dependent (which rows degenerate), so masked by CUDA_LAUNCH_BLOCKING and
memory sanitizers.

Fix (both gate kernels):
  - initialize shared_exp_id/shared_scales to a -1/0 sentinel before the fill,
    so unfilled (degenerate) slots are deterministically skipped.
  - keep the idx<top_k guard and only write masks/scales/accum when
    0 <= expert_id < expert_num.

Validated on full Qwen3.6-35B-A3B NVFP4, TP2: AR canary 10/10; MTP N=2 canary
10/10; 120 concurrent spec requests (k=6 x 20 rounds) zero crashes (was ~2).
A DFlash2/7 round near session_len wrote past the allocated KV columns,
underflowing a BatchCopy size (copy.cc TM_LOG_FATAL) and aborting the
engine. Reserve 2*(max_proposals+1) rows below session_len at add time:
too-large prompts now return a clean kTooLong 400 and generation is
truncated to the limit. Verified: 262015+128 -> 200 (trunc 113),
262130/262144 -> 400, canary 10/10, needle recall True @261K.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants