Skip to content

feat(qsa): backport PyHIP QSA and 1M context support to qwen4_v0.5.21 - #90

Merged
sammysun0711 merged 5 commits into
qwen4_v0.5.21from
cherry-pick-qsa
Nov 9, 2026
Merged

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

Conversation

@apinge

@apinge apinge commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

Motivation

This PR is for cherry-picking #81 and #43.

Modifications

Accuracy Tests

Speed Tests and Profiling

Compared with the baseline CI run(https://github.com/apinge/sglang/actions/runs/42149584665), Qwen3.8 Flash TP2 output throughput increases by 35.5% without MTP and 23.3% with MTP, with lower TTFT and TPOT in both configurations.

Configuration Output throughput (tokens/s) TTFT (ms) TPOT (ms)
Qwen3.8 Flash TP2, without MTP 64.464 → 87.327 (+35.5%) 965.853 → 779.086 (−19.3%) 12.787 → 9.250 (−27.7%)
Qwen3.8 Flash TP2, with MTP 87.294 → 107.608 (+23.3%) 1043.977 → 836.026 (−19.9%) 8.495 → 6.922 (−18.5%)

Average MTP accept length remains close to baseline (3.503 → 3.515).

The four Qwen3.5 cases remain broadly comparable in performance: output-throughput changes range from −2.3% to +2.4%.

All 6/6 CI cases pass, including the 200-example GSM8K accuracy gates. Qwen3.8 TP2 GSM8K changes from 99.0% to 98.0% without MTP (−1.0 percentage point, or two examples) and remains 99.0% with MTP. Qwen3.5 GSM8K changes range from −0.5 to +0.5 percentage points.

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 changed the title Cherry pick qsa feat(qsa): backport PyHIP QSA and 1M context support to qwen4_v0.5.21 Nov 7, 2026
apinge and others added 2 commits November 7, 2026 11:41
…or prefill (#43)

* add pyhip qsa support

* enable pyhip for mtp verify

* fix error overwriting for ring buffer

* align new indexer interface

* remove potential sync in qsa

* cache packed QSA KV slots per forward

* update scripts

* update mtp method

* update pyhip version

* clean qsa attn conditions

* rename condition function

* rename indexer support

* support qsa indexer in decode eager mode

* rename ring to ring_slots

* fix ring slots

* Apply suggestion from @yicyang

Co-authored-by: Ethan Yang <[email protected]>

---------

Co-authored-by: Luo Cheng <[email protected]>
Co-authored-by: Ethan Yang <[email protected]>
(cherry picked from commit d14f81d)
* feat(qsa): read K/V in place and allow 1M-context decode in PyHIP QSA

- Prefixed chunk prefill: PyHIP attention reads the layer's K/V pool in
  place through the packed slot table (kv_slots) instead of gathering the
  full-context K/V with index_select; pools PyHIP cannot read in place keep
  the gather path.
- Graph/eager decode: the PyHIP indexer accepts compressed page tables up to
  the runtime's MAX_COMPRESSED_KEYS (262144 keys, a 1M-token context)
  instead of 65536, bounded by the 32-bit offsets of its FP32 logits.
- Tests: in-place reads match the gather fallback, and graph decode with a
  1M-context page table still runs PyHIP.

Co-authored-by: Copilot <[email protected]>
(cherry picked from commit 0a10105)

* fix(qsa): accept YaRN MRoPE in the PyHIP QSA indexer

The 1M-context launch overrides RoPE to YaRN, which get_rope builds as
YaRNScalingMRotaryEmbedding. PyHIPIndexer.create matched MRotaryEmbedding by
exact type, so it returned None and the native indexer silently ran
(TP2, ~1M-token prompt: TTFT 229 s vs 87 s with PyHIP). YaRN only rescales
the cos/sin cache that the PyHIP prep reads; its lookup and MRoPE axis
composition are MRotaryEmbedding's. The new test builds the RoPE through
get_rope with the launch-style YaRN parameters and checks that PyHIP is
selected and matches native bit for bit in prefill, graph decode and verify.

Co-authored-by: Copilot <[email protected]>
(cherry picked from commit 010b0e2)

* feat(qsa): split long PyHIP QSA prefill indexer rows across attention-TP ranks

The PyHIP prefill indexer is replicated on every TP rank; at 1M context its
last chunk costs 45.3 ms per layer. With SGLANG_OPT_PYHIP_QSA_SPLIT_INDEXER=1
(off by default), a chunk of at least 2048 rows averaging at least 32768
compressed keys per row is cut into equal contiguous shares: each
attention-TP rank selects its share with prefill_indexer(row_range, out)
into a shared [tp * share, 2051] frame, and an in-place
all_gather_into_tensor completes it. The thresholds come from MI308X
measurements (indexer ~1.06e-5 us per row and key, TP2 all-gather ~0.087 us
per row) with about a 2x margin.

Validated on TP2 with YaRN at --context-length 1000000: SGLANG_TEST_PYHIP_QSA=1
passes with the split on (including a 999648-token request), and TTFT changes
by +0.1% / -1.3% / -5.0% / -11.5% at 131k / 262k / 524k / 1M inputs (1M:
86.1 s -> 76.2 s); the decode path is unchanged. Needs pyhip with
prefill_indexer(row_range, out).

Co-authored-by: Copilot <[email protected]>
(cherry picked from commit b1abbb0)

* add 1m script

* fix(qsa): bound Torch decode fallback key workspace

Gather and score compressed keys in page-aligned chunks with a 256 MiB
FP32 K budget. Preserve FP32 scoring, full logits, masking and
capture-static shapes without materializing all per-query keys at once.

Handle empty batches/capacity and truncated or padded output lengths.

* feat(qsa): log actual indexer backend dispatch

Add the opt-in SGLANG_LOG_QSA_INDEXER_BACKEND diagnostic flag. Log the
selected PyHIP, Torch or TileLang path after the indexer returns, with
layer, forward mode and query row count.

Deduplicate by layer instance, mode and backend. Keep logging disabled
by default and avoid import hooks or GPU synchronization.

* update scripts

* update test

* Update default model path in argument parser

Co-authored-by: Copilot Autofix powered by AI <[email protected]>

* test(qsa): cover chunked decode reference workspace

Lower the FP32 key budget to force multiple page chunks and compare
against a dense reference. Cover reordered pages, different context
lengths, partial-page truncation, padded output and empty inputs.

Add a 1M-capacity CUDA Graph workspace bound and replay checks with
changed query, cache, page-table and length inputs.

* Change TestQsaDecodeWorkspace base class

Refactor TestQsaDecodeWorkspace to inherit from CustomTestCase.

Co-authored-by: Copilot Autofix powered by AI <[email protected]>

* revert(qsa): drop chunked Torch decode fallback and workspace tests

Revert the chunked reference implementation and its dedicated workspace
regressions. Keep the PyHIP 1M/YaRN/TP-split integration and actual backend
dispatch logging unchanged.

Reverts 14c5729,
7edc822, and
e255acb.

* update script

* test(qsa): validate graph selection beyond 65536 compressed keys

Compare real compressed lengths of 66049 and 250001 against an independent Torch reference, with reordered pages, masked tail keys, and changing lengths during CUDA graph replay.

* chore(scripts): remove redundant long-context request helpers

Use the built-in serving benchmark with token-ID prompts, zero client warmups, and an explicit cache flush for long-context reproduction. Validated a cold 1000000-token input and 350-token output on TP2 with YaRN.

* build(rocm): pin PyHIP to merged QSA API revision

---------

Co-authored-by: Luo Cheng <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
(cherry picked from commit 286cd46)
@apinge
apinge marked this pull request as ready for review November 7, 2026 12:41
@apinge
apinge requested a review from sammysun0711 November 7, 2026 12:43
Comment on lines +216 to +228
```bash
python3 -m sglang.benchmark.serving \
--backend sglang \
--model /models/Qwen3.8-Flash-Next-PTPC-FP8-PLE-BF16 \
--host 127.0.0.1 --port 7080 \
--dataset-name random --tokenize-prompt \
--random-input-len 1000000 \
--random-output-len 350 \
--random-range-ratio 1.0 \
--num-prompts 1 --max-concurrency 1 \
--warmup-requests 0 --flush-cache \
--cache-report
```

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.

Can you add a new benchmark script for this case? e.g. evaluation/run_qwen38_pure_text_bench_1m.sh?

@apinge apinge Nov 9, 2026 •

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.

will add later. tracked issue in #95

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.

I will follow up with #47 to update CI test, TP1 and 1M case with smoke test in daily pressure test.

@sammysun0711
sammysun0711 merged commit 1ceea27 into qwen4_v0.5.21 Nov 9, 2026
8 of 9 checks passed
@apinge
apinge deleted the cherry-pick-qsa branch November 19, 2026 02:56
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