Skip to content

[QSA] Enable breakable prefill CUDA graphs for text-only Qwen3.8 Flash-Next (capture-safe metadata, MTP side-channel padding) - #41729

Merged
YAMY1234 merged 16 commits into
sgl-project:mainfrom
YAMY1234:hecate-q38fn-qsa-prefill-cg-clean-20260929
Oct 3, 2026
Merged

YAMY1234 merged 16 commits into
sgl-project:mainfrom
YAMY1234:hecate-q38fn-qsa-prefill-cg-clean-20260929

Conversation

@YAMY1234

@YAMY1234 YAMY1234 commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Qwen4Exp breakable prefill is blocked by the multimodal compatibility rules, including for text-only batches. Once the indexer runs in an eager break, live lengths and the prepared slot table avoid one D2H synchronization per QSA layer on replay. MTP replay also needs current HC state and matching target/draft token buckets. PLE request layouts must follow the live batch rather than the capture batch.

Modifications

  • Run QSA indexing in an eager break with live lengths and the prepared slot table.
  • Include contains_mm_inputs in dp_attn's unified vote and share eligibility between scheduling and execution, rejecting multimodal target and draft batches.
  • Move PLE metadata, prefetch, convolution and history updates into eager breaks, correcting capture 1×8 → replay 2×4 request mapping.
  • Add Qwen4Exp to multimodal_breakable_cuda_graph_supported_model_archs and remove the special-case hook.
  • Evaluate is_qwen4_exp once in runner initialization and read cached target/draft policy during forward.
  • Preserve HC replay state, align present draft embeddings to token buckets, and retain the text-only None fallback.
  • Share QSA bridge storage: for buckets 128…16K, topk 512 and 12 layers, Σbucket_tokens × 512 × 4B × 12 drops from 765 MiB to 384 MiB (381 MiB saved; the buckets × max_tokens upper bound is 3 GiB).
  • Keep DP voting, live-length bridge, HC padding and PLE layout regressions in existing suites; host the manual comparison tool with the accuracy evidence.

Accuracy Tests

Bit-identical outputs between graph replay and eager are not expected: breakable capture pads prefill to token buckets, which changes kernel shapes and reduction order.

GSM8K task accuracy is unchanged: 200 questions, 5-shot, strict scoring gives 197/200 with prefill graphs enabled, the same as disabled and base (measured on the pre-rebase branch).

Configuration em_strict
Base, prefill graph disabled 197/200
Patched branch, prefill graph disabled 197/200
Patched breakable vs base, MTP off 198/200 vs 198/200
Patched breakable, MTP on 197/200

For greedy, MTP-off generation over 16 prompts × 64 tokens (measured before this rebase), shared-prefix absolute logprob differences for the same reference-eager token are:

Comparison (positions) p50 p90 p99
Graph C1 vs eager C1 (443) 0.000107 0.065216 0.445882
Eager C8 vs eager C1 (640) 0.00000650 0.041485 0.437805
Graph C8 vs eager C8 (941) 0 0.007811 0.234025

Serial graph/eager has a higher p90 but a similar p99 to the batching baseline; on the 337 positions shared by all comparisons, their p90 values are 0.094516 and 0.093125, while concurrent graph/eager has smaller tails.
Only 2/12, 0/8 and 0/3 flips respectively have a top-1/top-2 gap below 0.05 on either side (none on both), so the flips are not uniformly near-ties; distribution details and CDF retain the measured tails and limits of this comparison.

Speed Tests and Profiling

These results are pre-rebase measurements, not performance validation of the current revision. Static benchmark, same patched branch, disabled → breakable, MTP on, 300 s admission:

ISL/OSL, concurrency Output tok/s/GPU TTFT
8k/1k, C64 4002 → 3929 (−1.8%) p50: 3255 → 3370 ms
8k/1k, C100 5121 → 5600 (+9.4%) p50: 2191 → 1500 ms
32k/1k, C64 1509 → 1522 (+0.9%) p50: 16748 → 16126 ms
32k/1k, C100 3685 → 3770 (+2.3%) p90: −11%

AgentX AGG TP1 C64, 900 s, Golden AL 2.32: base disabled → patched breakable improved 1000/ITL p90 from 35.6 to 38.8 (+8.9%) and total tok/s/GPU from 201.5k to 205.2k (+1.8%), with zero profile request errors. Target capture cost was 33 s / 10.5 GB.

Checklist


CI States

Latest PR Test (Base): ❌ Run #37051030206
Latest PR Test (Extra): ❌ Run #37051029314
Latest PR Test (AMD ROCm 10): ❌ Run #37051029739

@YAMY1234
YAMY1234 force-pushed the hecate-q38fn-qsa-prefill-cg-clean-20260929 branch 3 times, most recently from ba70bd6 to 051c6c6 Compare September 30, 2026 00:30
@github-actions github-actions Bot added the Multi-modal multi-modal language model label Sep 30, 2026
@YAMY1234
YAMY1234 marked this pull request as ready for review September 30, 2026 02:24
@YAMY1234
YAMY1234 force-pushed the hecate-q38fn-qsa-prefill-cg-clean-20260929 branch from e64ae0c to a4c9d22 Compare September 30, 2026 05:41
@Qiaolin-Yu Qiaolin-Yu self-assigned this Sep 30, 2026
Comment thread python/sglang/srt/models/qwen4_exp.py Resolved
Comment thread python/sglang/srt/models/qwen4_exp.py Resolved
Run the prefill indexer in an eager break using the current batch metadata.
Use scheduler CPU lengths and the prepared slot table to avoid capture-time D2H.
Share top-k storage across token buckets; leave eager and decode paths unchanged.
Capture HC state as an explicit output and restore it before the logits tail.
Pad present draft embeddings to the token bucket while preserving text-only None.
Cover live metadata, bucket boundaries, and the draft embedding fallback in three tests.
Allow the text-only Qwen4Exp configuration through the multimodal compatibility gate.
Keep the runtime multimodal replay guard and other backend restrictions.
Do not change decode graphs or enable full prefill graphs.
Include multimodal admission in the shared DP prefill graph vote.

Run PLE layout, prefetch, convolution, and state commits in eager breaks.

Cover mixed-rank admission and layer-two 1x8 to 2x4 replay on CPU.
Cache target HC and draft embedding policy with is_qwen4_exp at initialization.

Use the multimodal allowlist and the registered small-GPU test suite.

Clarify D2H and buffer costs, and use keyword arguments for private helpers.
…st sizes

Record the same token prompts with MTP disabled and 64 greedy output tokens.

Compare argmax and logprobs at concurrency one and eight with prefix tracking.

Keep the end-to-end server check manual and retain every differing position.
Move live-length, HC padding, PLE layout and DP voting checks into existing suites.
Keep the manual comparison tool with the external accuracy evidence.
Preserve production behavior and update affected CPU fixtures.
Provide the multimodal predicate in the hidden-state and CP test fixtures.
Use a plain PLE holder with __dict__ for eager-break output replacement.
Keep replay behavior unchanged and remove the new dataclass import.
@YAMY1234
YAMY1234 force-pushed the hecate-q38fn-qsa-prefill-cg-clean-20260929 branch from a4c9d22 to b2292ef Compare October 1, 2026 00:36
…ble graphs

Pad the shared top-k bridge with 0 to keep the zero-padding the eager
path used, and route a materialized idle batch through PLE forward_idle
inside the eager break so replay never calls the PLE layer with no batch.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@YAMY1234
YAMY1234 force-pushed the hecate-q38fn-qsa-prefill-cg-clean-20260929 branch from b2292ef to c5a53d6 Compare October 1, 2026 00:45

@nvpohanh nvpohanh left a comment •

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.

deleted. Too nit-picking

Comment thread python/sglang/srt/models/qwen4_exp.py Resolved
…ble MTP embed padding

Breakable replays run the PLE prefetch inside an eager break with live token
counts while capture mode is still on, so the per-size graph buffer cache grew
without bound; use it only outside breakable graphs. The Qwen MTP embedding
padding was unreachable because replay already rejects multimodal batches.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@Qiaolin-Yu Qiaolin-Yu added run-ci CI: run the baseline test suite on this PR bypass-fail-fast CI: a failing job no longer aborts its siblings (lint still gates) labels Oct 1, 2026
@YAMY1234

YAMY1234 commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator Author

Pushed ed6cbce: after the rebase, main's replay closure (f4c2563) also matches inputs_embeds, which is the position where the Qwen4-Exp MTP draft passes its hyper-connection stream, so the first real prefill failed with a width mismatch when copying it into the input_embeds slot. The Qwen BCG draft now skips that copy (the body reads the stream from the spec hidden-state slot). Verified on Qwen3.8-Flash-Next with MTP on the pre-merge base (431a28b + this fix) and covered by one CPU test.

YAMY1234 and others added 3 commits October 1, 2026 16:36
…ble replay

main's replay closure now matches both input_embeds and inputs_embeds
(f4c2563). Qwen4-Exp's MTP draft passes its hyper-connection stream
(hidden x hc_count) in that position, so the copy into the input_embeds
slot failed with a width mismatch on every real prefill. Skip the fill
for the Qwen BCG draft; the body reads that stream from the spec
hidden-state slot.
# Conflicts:
#	python/sglang/srt/layers/attention/qwen_sparse_attn_backend.py
Breakable prefill reduced MTP accept length by 4-5% without a material
task-accuracy change. The draft passes a hidden_size * hc_count HC stream
as inputs_embeds, but the replay slot was registered at hidden_size, so the
copy was skipped and replay ran on capture-time input.

Declare input_embeds_hidden_size on the MTP draft and keep the live input
copy before replay. GSM8K-200 accept length: TP1 3.31 -> 3.47 (197/200),
TP4 with the CI args 3.44 (197/200).
@YAMY1234

YAMY1234 commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed 9887f73 for the base-c MTP accept-length failure (2.88 < 2.9): with breakable prefill the MTP draft's replay was running on capture-time input — the draft passes its hidden×hc_count HC stream in the inputs_embeds position while the slot was registered at hidden_size, so the copy was skipped. The draft now declares input_embeds_hidden_size = hidden_size * hc_count and the live copy is kept before replay; GSM8K-200 accept length recovers from 3.31 to 3.47 at TP1 and reads 3.44 at TP4 with the CI args (accuracy unchanged). The GLM-5.3 B200 miss (0.928 vs 0.93) matches the margin seen on other PRs the same day, and the two GB300 jobs failed in the install step.

@YAMY1234

YAMY1234 commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator Author

CI status on c5c6ee3: all base-c jobs pass except base-c-test-4-gpu-b200 (0) (GLM-5.3-Flash GSM8K, threshold 0.93). The failing class alternates between attempts (attempt 1: DFlash2 0.926/0.92/0.92; attempt 2: DFlash2 passes at 0.934 and LowLatency fails at 0.928/0.926/0.926), and both failing classes run with the prefill CUDA graph disabled, so this PR's code is not on their path

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

Labels

bypass-fail-fast CI: a failing job no longer aborts its siblings (lint still gates) Multi-modal multi-modal language model run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants