Repository navigation
feat(qsa): backport PyHIP QSA and 1M context support to qwen4_v0.5.21 - #90
Merged
Merged
Conversation
…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
force-pushed
the
cherry-pick-qsa
branch
from
November 7, 2026 12:22
0b81760 to
4c496c3
Compare
apinge
force-pushed
the
cherry-pick-qsa
branch
from
November 7, 2026 12:41
4c496c3 to
46c266a
Compare
apinge
marked this pull request as ready for review
November 7, 2026 12:41
sammysun0711
reviewed
Nov 9, 2026
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 | ||
| ``` |
Collaborator
There was a problem hiding this comment.
Can you add a new benchmark script for this case? e.g. evaluation/run_qwen38_pure_text_bench_1m.sh?
Collaborator
There was a problem hiding this comment.
I will follow up with #47 to update CI test, TP1 and 1M case with smoke test in daily pressure test.
sammysun0711
approved these changes
Nov 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
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
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ci