Skip to content

[None][feat] Add Qwen3-based DSpark drafter (DeepSpec dense checkpoints)#16813

Open
chungen04 wants to merge 1 commit into
NVIDIA:mainfrom
chungen04:dspark-qwen3
Open

[None][feat] Add Qwen3-based DSpark drafter (DeepSpec dense checkpoints)#16813
chungen04 wants to merge 1 commit into
NVIDIA:mainfrom
chungen04:dspark-qwen3

Conversation

@chungen04

@chungen04 chungen04 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Dev Engineer Review

  • Added a pure-Torch Qwen3 DSpark drafter with GQA, RoPE, bidirectional block attention, ring-buffered context K/V, Markov-head refinement, checkpoint loading, and target-model embedding/LM-head sharing.
  • Integrated Qwen3DSparkForCausalLM into DSpark model dispatch and added support for unprefixed DeepSpec configuration keys.
  • Reuses existing DSpark worker, metadata, and CUDA-graph interfaces without schema changes.
  • No config files or test-list files were modified.
  • Review focus should include ring-buffer indexing, batched masking, CUDA-graph safety, checkpoint compatibility, and consistency with existing DSpark APIs.

QA Engineer Review

  • Added:
    • test_worker_protocol_golden
    • test_batched_matches_eager_singletons
    • test_ring_window_wraparound
    • Module-scoped setup fixture
  • Tests cover worker protocol behavior, multi-step decoding, batching parity, and ring-window wraparound against a deterministic reference implementation.
  • No corresponding tests/integration/test_lists/, test-db/, or qa/ coverage entry was found.
  • Verdict: needs follow-up.

Description

DSpark support today (#15808) covers only the DeepSeek-V4 drafter, whose draft weights live in the target checkpoint and in V4 blocks. DeepSeek's release (https://github.com/deepseek-ai/DeepSpec) also ships standalone dense DSpark drafters for Qwen3 targets, deepseek-ai/dspark_qwen3_{4b,8b,14b}_block7, which this PR enables. This PR also serves as a stepping stone to serve other Qwen3-based DSpark drafter, e.g. novita/kimi-k2.6-dspark

  • modeling_dspark_qwen3.py (new): Qwen3DSparkDraftModel / Qwen3DSparkForCausalLM: a pure-torch dense GQA draft backbone (fc + hidden_norm captured-context projection, Qwen3 decoder layers with per-head q/k RMSNorm and RoPE, bidirectional block attention over a per-layer context-K/V ring cache, Markov-head block refinement). It implements the same worker-facing protocol as the V4 DSparkDraftModel, so DSparkWorker, DSparkSpecMetadata, and the CUDA-graph plumbing are reused unchanged. The worker-owned rolling buffer holds per-layer context K/V as a ring over the last TRTLLM_DSPARK_QWEN3_CTX_WINDOW (default 2048) committed positions.
  • get_draft_model: dispatch on the drafter checkpoint's Qwen3DSparkModel architecture (mirrors the DFlash/Laguna pattern).
  • llm_args DSpark validation: additionally resolve the unprefixed top-level config keys (block_size / target_layer_ids / mask_token_id / markov_rank) used by the DeepSpec drafter checkpoints.

Usage:

speculative_config:
  decoding_type: DSpark
  max_draft_len: 7
  speculative_model: deepseek-ai/dspark_qwen3_8b_block7

Test Coverage

  • tests/unittest/_torch/speculative/hw_agnostic/test_dspark_qwen3.py (new): golden tests against a torch-only port of the DeepSpec reference (deepspec/modeling/dspark/qwen3/modeling.py + eval/dspark/draft_ops.py) — token-exact agreement across multi-step decode driven through the exact DSparkWorker conventions (prefill seeding, interim back-fill, frame offsets), batched-vs-singleton parity, and ring-window wraparound.
  • Existing DSpark unit tests (62) and test_llm_args.py DSpark validation tests (9) pass unchanged.
  • E2E (1xB300, 1.3.0rc22 backport of this diff): results below.
  • Benchmarks: aiperf against trtllm-serve (1xB300, bf16, greedy, chat template with thinking disabled, natural EOS, max_tokens 1024, max_batch_size 64, CUDA graphs on, overlap scheduler off for all configs), GSM8K / MATH-500 / HumanEval in the DeepSpec eval prompt format. Eagle3 baseline swept at draft length 1 and 3.

Per-user decode rate, tok/s (speedup vs vanilla):

Qwen3-8B

dataset conc vanilla eagle3 len1 eagle3 len3 dspark block7
gsm8k 1 200.7 301.7 (1.50x) 367.8 (1.83x) 750.8 (3.74x)
gsm8k 4 182.4 270.5 (1.48x) 306.0 (1.68x) 488.3 (2.68x)
gsm8k 16 151.1 205.4 (1.36x) 216.5 (1.43x) 241.8 (1.60x)
gsm8k 64 88.2 107.7 (1.22x) 108.4 (1.23x) 97.1 (1.10x)
math500 1 203.7 303.0 (1.49x) 362.4 (1.78x) 749.1 (3.68x)
math500 4 188.3 274.3 (1.46x) 321.6 (1.71x) 540.2 (2.87x)
math500 16 158.6 223.1 (1.41x) 254.1 (1.60x) 300.3 (1.89x)
math500 64 106.0 138.8 (1.31x) 136.4 (1.29x) 118.2 (1.11x)
humaneval 1 200.8 302.6 (1.51x) 365.6 (1.82x) 661.4 (3.29x)
humaneval 4 185.7 267.1 (1.44x) 312.4 (1.68x) 470.6 (2.53x)
humaneval 16 157.1 212.8 (1.35x) 251.0 (1.60x) 267.6 (1.70x)
humaneval 64 108.1 137.6 (1.27x) 150.0 (1.39x) 110.3 (1.02x)

Qwen3-4B

dataset conc vanilla eagle3 len1 eagle3 len3 dspark block7
gsm8k 1 264.0 412.9 (1.56x) 512.6 (1.94x) 855.6 (3.24x)
gsm8k 4 233.2 339.2 (1.45x) 416.9 (1.79x) 532.9 (2.28x)
gsm8k 16 175.0 250.0 (1.43x) 264.2 (1.51x) 261.0 (1.49x)
gsm8k 64 97.0 119.6 (1.23x) 124.4 (1.28x) 98.3 (1.01x)
math500 1 267.0 423.9 (1.59x) 492.3 (1.84x) 886.8 (3.32x)
math500 4 243.5 353.9 (1.45x) 442.7 (1.82x) 627.1 (2.58x)
math500 16 198.6 272.1 (1.37x) 332.7 (1.68x) 331.1 (1.67x)
math500 64 126.4 158.3 (1.25x) 166.8 (1.32x) 126.1 (1.00x)
humaneval 1 267.5 397.3 (1.49x) 479.7 (1.79x) 782.4 (2.93x)
humaneval 4 242.5 351.0 (1.45x) 400.1 (1.65x) 529.2 (2.18x)
humaneval 16 194.2 252.2 (1.30x) 310.0 (1.60x) 272.6 (1.40x)
humaneval 64 125.2 175.1 (1.40x) 161.5 (1.29x) 112.1 (0.90x)

Qwen3-14B

dataset conc vanilla eagle3 len1 eagle3 len3 dspark block7
gsm8k 1 142.3 225.4 (1.58x) 291.3 (2.05x) 560.8 (3.94x)
gsm8k 4 131.0 209.0 (1.60x) 270.5 (2.06x) 431.7 (3.29x)
gsm8k 16 110.1 154.5 (1.40x) 183.1 (1.66x) 257.1 (2.34x)
gsm8k 64 72.2 90.6 (1.25x) 113.4 (1.57x) 92.3 (1.28x)
math500 1 143.4 227.7 (1.59x) 299.7 (2.09x) 574.7 (4.01x)
math500 4 137.1 210.7 (1.54x) 274.7 (2.00x) 434.0 (3.16x)
math500 16 118.4 182.6 (1.54x) 224.3 (1.89x) 265.3 (2.24x)
math500 64 84.9 121.1 (1.43x) 129.1 (1.52x) 101.2 (1.19x)
humaneval 1 142.0 218.6 (1.54x) 277.1 (1.95x) 523.0 (3.68x)
humaneval 4 135.8 198.2 (1.46x) 245.4 (1.81x) 378.5 (2.79x)
humaneval 16 118.7 169.6 (1.43x) 200.1 (1.69x) 220.8 (1.86x)
humaneval 64 84.2 113.2 (1.34x) 128.6 (1.53x) 94.8 (1.13x)

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

Support the DeepSpec-released dense DSpark drafters for Qwen3 targets
(e.g. deepseek-ai/dspark_qwen3_8b_block7) alongside the existing
DeepSeek-V4 mtp.*-namespace drafter:

- modeling_dspark_qwen3.py: Qwen3DSparkDraftModel/Qwen3DSparkForCausalLM,
  a pure-torch dense GQA draft backbone (fc+hidden_norm context projection,
  Qwen3 layers with captured-context K/V and bidirectional block attention,
  Markov head refinement) implementing the same worker-facing protocol as
  DSparkDraftModel, so DSparkWorker / DSparkSpecMetadata / CUDA-graph
  plumbing are reused unchanged. The worker rolling buffer holds per-layer
  context K/V as a ring over the last TRTLLM_DSPARK_QWEN3_CTX_WINDOW
  (default 2048) committed positions.
- get_draft_model: dispatch on the drafter checkpoint's Qwen3DSparkModel
  architecture.
- llm_args DSpark validation: also resolve unprefixed top-level config
  keys (block_size / target_layer_ids / mask_token_id / markov_rank) used
  by the DeepSpec drafter checkpoints (no schema change; golden manifest
  unchanged).
- tests: golden tests vs a torch-only port of the DeepSpec reference
  (worker frame conventions across multi-step decode, batched-vs-singleton
  parity, ring wraparound).

Validation: golden unit tests vs a torch-only DeepSpec reference port;
end-to-end + GSM8K/MATH-500/HumanEval benchmarks (aiperf, 1xB300,
conc 1..64) were run on the v1.3.0rc22 backport of this change (branch
dspark-qwen3-rc22, same diff) inside the 1.3.0rc22 release container:
3.3-3.7x per-user speedup over vanilla at concurrency 1
(~750 tok/s/user), 6.17 avg decoded tokens/iter on GSM8K (block=7).

Signed-off-by: chungen04 <cho322@gatech.edu>
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 122ed3fb-183d-4721-9806-dbad2e90430e

📥 Commits

Reviewing files that changed from the base of the PR and between 80b4eb3 and 5476284.

📒 Files selected for processing (4)
  • tensorrt_llm/_torch/models/modeling_dspark_qwen3.py
  • tensorrt_llm/_torch/models/modeling_speculative.py
  • tensorrt_llm/llmapi/llm_args.py
  • tests/unittest/_torch/speculative/hw_agnostic/test_dspark_qwen3.py

Walkthrough

Adds a complete Qwen3 DSpark draft model with projected context K/V ring storage, batched decoding, target-model weight sharing, speculative-decoding dispatch, configuration fallback, and golden tests for protocol, batching, and wraparound behavior.

Changes

Qwen3 DSpark drafter

Layer / File(s) Summary
Model components and initialization
tensorrt_llm/_torch/models/modeling_dspark_qwen3.py
Adds rotary embedding helpers, RMSNorm, GQA attention, gated MLP, decoder layers, confidence-head scaffolding, RoPE caching, and draft-model initialization.
Context ring and draft decoding
tensorrt_llm/_torch/models/modeling_dspark_qwen3.py
Projects target hidden states into context K/V windows, supports single and batched ring writes, executes batched draft attention, and produces proposed tokens and logits.
Wrapper, loading, and dispatch
tensorrt_llm/_torch/models/modeling_dspark_qwen3.py, tensorrt_llm/_torch/models/modeling_speculative.py, tensorrt_llm/llmapi/llm_args.py
Adds the worker-facing wrapper, shared target embeddings and LM head, checkpoint loading, Qwen3DSpark model selection, and top-level DSpark configuration fallback.
Worker protocol validation
tests/unittest/_torch/speculative/hw_agnostic/test_dspark_qwen3.py
Adds reference-based golden tests for worker execution, batched versus singleton decoding, and ring-buffer wraparound.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant TargetModel
  participant Qwen3DSparkForCausalLM
  participant Qwen3DSparkDraftModel
  participant RingBuffer
  TargetModel->>Qwen3DSparkForCausalLM: load shared embeddings and LM head
  TargetModel->>Qwen3DSparkForCausalLM: provide captured hidden states
  Qwen3DSparkForCausalLM->>Qwen3DSparkDraftModel: write context windows
  Qwen3DSparkDraftModel->>RingBuffer: store per-layer context K/V
  Qwen3DSparkForCausalLM->>Qwen3DSparkDraftModel: forward_batched
  Qwen3DSparkDraftModel->>RingBuffer: read committed context
  Qwen3DSparkDraftModel-->>Qwen3DSparkForCausalLM: proposed tokens and logits
Loading

Possibly related PRs

Suggested reviewers: aswinvisva

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title follows the required [None][feat] format and clearly summarizes the main change: adding a Qwen3 DSpark drafter.
Description check ✅ Passed The description includes the required summary, implementation details, test coverage, and checklist sections from the template.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

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