Skip to content

[Qwen3.8] Cherry pick qsa mtp optimization - #99

Merged
sammysun0711 merged 3 commits into
qwen4_v0.5.21from
cherry-pick-qsa-mtp
Nov 11, 2026
Merged

sammysun0711 merged 3 commits into
qwen4_v0.5.21from
cherry-pick-qsa-mtp

Conversation

@apinge

@apinge apinge commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Motivation

This PR is to cherry pick #51

Modifications

Accuracy Tests

Speed Tests and Profiling

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

@apinge
apinge force-pushed the cherry-pick-qsa-mtp branch 2 times, most recently from fe9c8cc to cfb1002 Compare November 9, 2026 12:59
apinge and others added 2 commits November 10, 2026 02:07
* use pyhip qsa prefill kerenl for draft extend

* support pyhip indexer for draft_extend_v2

* support cudagraph for draft extend

* perf(qsa): reduce MTP draft replay metadata preparation

Refresh shared-index proposal metadata for all draft steps in one GPU launch and skip unused compressed-key and ring metadata. Fuse draft-extend layout with full metadata preparation and avoid scalar readbacks in eager metadata builders.

Keep the PyHIP decode page-table width within its ABI limit. Add coverage for shared metadata, graph replay, padding, bucket changes, paged attention output, and eager readback removal.

* perf(mtp): optimize draft processing and target verification

Reuse target prompt embeddings for draft prefill and accelerate the MTP
input broadcast add. Use ROCm max selection for topk=1 draft proposals
without computing full-vocabulary softmax.

Use q/k/v views for ROCm GDN target verification when ReplaySSM buffers
are absent. This verification optimization also serves other speculative
models; it is grouped with the MTP execution-path changes.

Split the MTP and speculative execution changes from fe69548 (add c8 opt).

* replace number with qsa graph mode

* update zero mm_input_embeds; update tests

* update condition of extend_seq_lens_cpu

* revert(qsa): restore full MTP replay metadata preparation

(cherry picked from commit d0a5b96)
Keep the current 1M bounds, capability-based GDN routing, and fused topk1 paths. Reuse the per-request Eagle embedding shift once and initialize each tail before the draft repairs it.

Update draft PyHIP dispatch tests for the new contract, migrate the prefill-anchor case to the current QSA test file, and cover embedding alignment and broadcast-add graph replay.
and not use_rejection_sampling
and is_qwen_qsa(self.draft_runner.model_config.hf_config)
):
# ROCm keeps max()'s tie-break (#26358) without the vocab softmax.

@sammysun0711 sammysun0711 Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgl-project#26235 merge but revert by sgl-project#26358, and alternative implementation exist in current base branch: sgl-project#35872, do you think we still need this adjustment?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In commit c84ad87, I've removed
unreachable paths. but here is in _draft_extend_for_prefill which is not covered by sgl-project#35872.

@apinge
apinge force-pushed the cherry-pick-qsa-mtp branch from cfb1002 to c84ad87 Compare November 10, 2026 02:10
@apinge
apinge marked this pull request as ready for review November 10, 2026 03:17
@sammysun0711

sammysun0711 commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

This PR backports Qwen3.8-Flash-Next QSA/MTP optimizations from #40 to qwen4_v0.5.21, optimize draft prefill and draft-extend processing. Qwen3.5 & Qwen3.8 base (w/o) MTP should not impact by this PR.

  • Extends the PyHIP QSA attention/indexer paths to draft workers and DRAFT_EXTEND_V2, including ROCm draft-extend CUDA graph support.
  • Reuses target prompt embeddings for MTP draft prefill, repairs each request's tail embedding, and fuses the embedding broadcast-add into HC streams for large extends.
  • Removes CPU/GPU synchronization from QSA metadata construction and sparse-index capture by using host-side lengths or GPU-side mappings with fixed output capacities.
  • Uses an argmax instead of a vocabulary softmax for Qwen QSA's greedy top-k-1 draft selection on HIP when rejection sampling is disabled, preserving torch.max tie-breaking.
  • Adds regression coverage for embedding reuse, request tails, fused broadcast-add, QSA metadata, and PyHIP speculative paths.

MI308X CI: PR #94 baseline → PR #99

Both runs passed 6/6 serving cases. Each case completed 128 performance requests at concurrency 1 and scored 200 GSM8K examples. Performance thresholds are advisory; the recorded GSM8K gate allows a 3% relative drop from each case's reference. The after summary reports coverage of 6/7 defined cases because the daily-only R-Fork startup case is excluded from standard PR runs.

  • Before: PR #94, SGLang 598ebb63de3ddc8c51cab59bd43ea3ab56deae12, run 42624481704, attempt 1, November 9, 2026 UTC.
  • After: PR #99, SGLang eeb5f260ee09445a3da54968c998711aaf6e1c1c, run 42772431983, attempt 4, November 10, 2026 UTC.
  • Shared sources: AITER 514c166e9abad59acde74309923c2d923a89eee0, pyhip 8027faad29415747707670db7776528c6b72db81, and benchmark client fc6ddbbf7aac80167ea04cc00bf200af8adf2b85.
  • Performance inputs: random dataset, configured input/output lengths of 12,000/350 tokens for Qwen3.8 and 8,000/500 for Qwen3.5.

Changes are (after / before - 1) × 100%, calculated from unrounded artifact values and rounded to one decimal place. Negative TTFT/TPOT changes mean lower latency; positive throughput/QPS changes mean higher throughput.

Case GSM8K (before → after) TTFT ms (before → after; Δ %) TPOT ms (before → after; Δ %)
Qwen3.8-Flash-TP2-Base 98.00% → 98.00% 730.911 → 724.959 (-0.8%) 7.270 → 7.225 (-0.6%)
Qwen3.8-Flash-TP2-MTP 98.50% → 99.00% 779.860 → 746.748 (-4.2%) 6.264 → 3.896 (-37.8%)
Qwen3.5-35B-TP4-Base 96.50% → 98.50% 166.622 → 176.518 (+5.9%) 4.071 → 4.233 (+4.0%)
Qwen3.5-35B-TP1-DFlash 97.00% → 97.00% 304.783 → 309.212 (+1.5%) 2.866 → 2.898 (+1.1%)
Qwen3.5-397B-TP8-Base 98.00% → 99.50% 339.071 → 339.221 (0.0%) 6.165 → 6.126 (-0.6%)
Qwen3.5-397B-TP8-DFlash 99.50% → 98.00% 361.708 → 361.399 (-0.1%) 3.059 → 2.996 (-2.1%)

Additional CI summary metrics:

Case Output tokens/s (before → after; Δ %) QPS (before → after; Δ %) Accept length (before → after; Δ %)
Qwen3.8-Flash-TP2-Base 107.065 → 107.787 (+0.7%) 0.306 → 0.308 (+0.7%) —
Qwen3.8-Flash-TP2-MTP 117.972 → 166.098 (+40.8%) 0.337 → 0.475 (+40.8%) 3.521 → 3.505 (-0.4%)
Qwen3.5-35B-TP4-Base 227.406 → 218.366 (-4.0%) 0.455 → 0.437 (-4.0%) —
Qwen3.5-35B-TP1-DFlash 288.091 → 284.759 (-1.2%) 0.576 → 0.570 (-1.2%) 5.911 → 5.984 (+1.2%)
Qwen3.5-397B-TP8-Base 146.371 → 147.185 (+0.6%) 0.293 → 0.294 (+0.6%) —
Qwen3.5-397B-TP8-DFlash 264.697 → 269.216 (+1.7%) 0.529 → 0.538 (+1.7%) 7.769 → 7.920 (+2.0%)

The targeted Qwen3.8-Flash-TP2-MTP case records TTFT -4.2%, TPOT -37.8%, and output throughput +40.8%. Its acceptance length changes by only -0.4%, while GSM8K increases from 98.50% to 99.00%.

Qwen3.8 Base (w/o MTP) and Qwen3.5 model performance is keep flat within run-to-run variance.

@sammysun0711
sammysun0711 merged commit 04341c2 into qwen4_v0.5.21 Nov 11, 2026
23 of 33 checks passed
@apinge
apinge deleted the cherry-pick-qsa-mtp branch November 19, 2026 02:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants