Skip to content

feat(turbomind): native SM75 verification attention [stacked on #5019] - #5145

Draft
richardclli wants to merge 41 commits into
InternLM:mainfrom
richardclli:pr/sm75-verify-attention
Draft

richardclli wants to merge 41 commits into
InternLM:mainfrom
richardclli:pr/sm75-verify-attention

Conversation

@richardclli

@richardclli richardclli commented Nov 17, 2026 •

Copy link
Copy Markdown

Summary

Stacked on #5019, which is
itself stacked on #5006.
#5006 provides the verification-attention framework; #5019 provides the SM75
runtime fixes and the canonical _tm test import this branch inherits.

Once #5006 and #5019 are merged, the diff of this PR shrinks to exactly the two
commits (SM75 kernel + tuning/int4 bench). The branch is built on the current
#5019 head and will be rebased after the base PRs merge.

Motivation

The dedicated verification-attention path is SM90-only, so SM75 MTP routes every
verification row through the prefill path (per-step KV flatten plus full-history
attention). This PR adds a native SM75 kernel and makes the verification path
per-arch, without changing SM90 behavior.

Modification

  • New policy_sm75.cuh + kernel_sm75.cu, compiled 75-real only. Turing has no
    f16 m16n8k16, so a custom cute atom reuses the m16n8k8 emulation; sync KV
    copy (no cp.async), elementwise P store (no stmatrix), Stages=1, CtaM=64.
  • int4/uint4 KV reader and dequant (quant_policy 4).
  • Two per-arch static libraries plus a host-only dispatch_arch.cc; the SM90
    WGMMA path is namespaced and behavior-unchanged. SM80/89/120 remain unsupported.
  • Verification split tuning for SM75 (arch_ == 750) and an int4 attention bench.

Dependency note

Kind Required Why
Code #5006 verification-attention framework
Base #5019 canonical _tm test import and SM75 runtime fixes; this branch bases here
Validation evidence #5142 end-to-end MTP numbers were measured on the NVFP4 checkpoints that PR adds; parity and the int4 bench are synthetic and do not need it

Validated checkpoints

SM75 (RTX 2080 Ti), TP2: Qwen3.8-27B NVFP4 and Qwen3.6-35B-A3B NVFP4.

Check Result
Reference parity 8 passed (1 expected SM75 skip: p > 8); causal/non-causal, fp16 + int4 KV
MTP 4K fp16 46.0 -> 75.8 t/s (1.65x)
MTP 8K fp16 42.75 -> 71.63 t/s (1.68x)
MTP 64K int4 38.27 -> 51.80 t/s (1.35x)
MTP ~254K int4 26.15 -> 25.04 t/s (0.96x, parity)
Canary 27B MTP-2 10/10; 35B-A3B MTP-4 10/10
Needle MTP-2 recall true at 4K / 32K / 128K

MTP remains a short/mid-context lever on this checkpoint/configuration; at
~254K int4 the measured result is parity, not a speedup.

The measured numbers above supersede the earlier figures in the commit
messages (the kernel commit predates the re-measurement). In particular, the
commit message's "2.0-2.6x / 1.3-1.7x" claims are superseded by 1.68x @8k
fp16, 1.35x @64k int4, and parity at ~254K int4.

BC-breaking

None for SM90: the WGMMA path is unchanged. SM75 gains a native path; SM80/89/120
keep the existing fallback. The SM75 kernel is compiled only into the SM75 target.

Notes

The PR also lands the arch-neutral dispatch/int4 plumbing that makes future arch
support possible; the SM75 kernel itself is the only arch-specific behavior. The
upstream CI runs on A100/SM80+, so SM75-only tests are skip-guarded and the SM75
evidence is reported here.

bltcn and others added 30 commits December 7, 2025 00:35
actions-user and others added 11 commits February 4, 2026 06:45
- 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
…d 'mtp'

The CLI exposes qwen3_5_mtp/hy3_mtp/deepseek_mtp, but TurboMind registers the
MTP head under the C++ name "mtp" (TM_REGISTER_SPECULATIVE_MODEL("mtp", ...)).
Without normalization, --speculative-algorithm qwen3_5_mtp hit
build_draft_model's ValueError and the C++ 'unknown speculative method' check.
Add normalize_spec_method() and apply it at both the draft-model builder and the
EngineConfig.spec_method assignment so the registered name reaches C++.
…TP on 2080Ti)

ForwardSpeculativeRound -> CommitAcceptedRecurrentStateKernel dispatches the
recurrent-state dtype through TM_DISPATCH_DTYPES with only (bfloat16_t, float).
On pre-SM80 GPUs (no bf16 tensor core) the engine dtype is float16, so the
GDN recurrent state is f16 and the speculative round aborts with
'unsupported type: f16'. The kernel body computes in float and only touches
StateT via ToFloat/FromFloat, and the input side already dispatches half_t, so
adding half_t is a correctness fix for SM75 MTP. Not caught by CI (A100/bf16
path never hits this branch).
…idth

CI lint's docformatter hook (v1.7.7, --wrap-descriptions 120) rejects the
82-char one-line summary. Shortened to 58 chars; ruff + docformatter clean.
…ixes

Inherited CI blockers from InternLM#5006 (this PR is stacked on it):
- unit_test (exit 2, collection error): 3 top-level 'import _turbomind' fail
  under CI 'pip install -e .' because the bare module name is not on sys.path.
  Switch to 'from lmdeploy.turbomind import _tm' (canonical, matches
  test_linear.py) and function-level imports to the package name.
- lint (ruff): F841 dead var, F401 unused imports, I001 import sorting.

Verified in CI-matched env (0.18.0 + cu12.8 + built _tm.so + torch):
308 tests collected, 0 collection errors (was 213 collected, 2 errors).
Enable direct verification on SM75 so MTP uses a native paged attention instead
of the prefill fallback (per-step KV flatten + full-history attention).

- new policy_sm75.cuh + kernel_sm75.cu, compiled 75-real only; custom cute atom
  TM_16x8x16 reuses TurboMind's m16n8k16 -> two m16n8k8 emulation (Turing has no
  f16 m16n8k16), keeping k16 tiling + ldmatrix
- sync KV copy (no cp.async), elementwise P store (no stmatrix), Stages=1, CtaM=64
- int4/uint4 KV reader + dequant (ConvertKvCache<uint4_t,half>), quant_policy 4
- two per-arch static libs + host dispatch_arch.cc; SM90 WGMMA path namespaced and
  behaviour-unchanged; SM80/89/120 remain unsupported

Result: MTP 2.0-2.6x @4K-64K (fp16) and 1.3-1.7x @64K/256K (int4); canary 10/10;
needle OK to ~247K. Isolated to SM75.

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.

4 participants