Skip to content

feat(turbomind): EAGLE3 and Qwen3.5 MTP speculative decoding - #5006

Open
lzhangzz wants to merge 1 commit into
InternLM:mainfrom
lzhangzz:mtp-2
Open

lzhangzz wants to merge 1 commit into
InternLM:mainfrom
lzhangzz:mtp-2

Conversation

@lzhangzz

Copy link
Copy Markdown
Collaborator

Summary

Adds speculative decoding to the TurboMind backend, built on a new fixed-chain speculator framework with two draft methods:

  • mtp — Qwen3.5 MTP draft layers, weights read directly from the target checkpoint
  • eagle3 — Qwen3 EAGLE3 with a sidecar draft model; added to bootstrap the MTP integration, not optimized for performance (linear chain verification only, no tree verification)

What's included

Draft model framework (src/turbomind/models/speculative/)

  • Fixed-chain speculator base: model/policy/setup split, hidden-state tap, and a method-keyed draft weight registry
  • eagle3/: EAGLE3 draft model, weight mapping, and target hidden-state projection with dedicated kernels — serves as the integration vehicle for the speculative pipeline rather than a performance-optimized path; verification is linear-chain only, no tree verification
  • qwen3_5_mtp/: Qwen3.5 MTP draft model, weights, and target final-hidden extraction

Verification path

  • Block speculative verification (generation/target_verification)
  • Dedicated verification attention kernels (kernels/attention/verification/): SM80 path, SM90 WGMMA pipelines, paged KV, and cross-CTA reduce
  • SM90 GDR verify-and-commit kernel mode with persistent pipelining
  • Op kernels for draft carry, speculative sampling, and speculative sequence bookkeeping, all with python bindings

Engine and scheduler refactor

  • Unified, parameterized batch-op pipeline driven engine-side
  • Executor forward split into target pass and speculative round
  • Model (formerly BatchComponents) owns target, vision, and speculative models
  • Submitted rows carry producer-set effects instead of a kind tag
  • Unified required admission with simplified rollback
  • Normative contract expanded in src/turbomind/engine/README.md

Python surface (lmdeploy/)

  • spec_decode.py method registry plus qwen3_5_mtp / qwen3_eagle3 model and weight builders, wired through speculative_config
  • Metrics and async-engine support for speculative stats

Tests

  • Op-level pytest suites comparing against pure-PyTorch references: verification attention, draft carry, speculative sampling, speculative sequence, target hidden projection (232 collected cases), plus a copy-op suite
  • scripts/test_turbomind_model.py extended for speculative smoke testing

Usage

from lmdeploy import TurbomindEngineConfig
from lmdeploy.messages import SpeculativeConfig

# Qwen3.5 MTP (draft weights come from the target checkpoint)
spec = SpeculativeConfig(method='mtp', num_speculative_tokens=2)

# Qwen3 EAGLE3 (sidecar draft model)
spec = SpeculativeConfig(method='eagle3',
                         model='<path/to/eagle3-draft>',
                         num_speculative_tokens=3)

engine = TurbomindEngineConfig(speculative_config=spec)

- 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
bltcn added a commit to bltcn/lmdeploy that referenced this pull request Oct 3, 2026
…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).

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.

1 participant