Skip to content

[AMD] [GLM5] skip redundant -inf pre-fill of HIP indexer MQA-logits - #28757

Merged
HaiShaw merged 3 commits into
sgl-project:mainfrom
Raiden-Makoto:RM/dsa-skip-logits-clean
Jun 25, 2026
Merged

HaiShaw merged 3 commits into
sgl-project:mainfrom
Raiden-Makoto:RM/dsa-skip-logits-clean

Conversation

@Raiden-Makoto

@Raiden-Makoto Raiden-Makoto commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

This affects HIP serving of DSA (DeepSeek Sparse Attention) models; it was found
and validated on GLM-5.1-MXFP4 (which uses the DSA indexer) at long context.

On the HIP DSA indexer path, Indexer._get_topk_ragged calls aiter's
fp8_mqa_logits with the default clean_logits=True, which
torch.full(-inf)-initializes the [tokens x seq_len_kv] logits buffer on every
layer before the kernel writes the valid positions. That pre-fill is O(seq^2)
and grows quadratically with context length, so at long context it becomes a
significant share of prefill time (~11% of prefill GPU time at 16x8192 on
gfx950).

The CUDA deep_gemm.fp8_mqa_logits path in the same function already passes
clean_logits=False and relies on topk_transform to mask invalid positions via
ks/ke/lengths. The HIP path simply did not pass the flag, leaving the
redundant fill in place. This aligns the HIP path with CUDA.

Modifications

  • python/sglang/srt/layers/attention/dsa/dsa_indexer.py: pass
    clean_logits=False to both HIP fp8_mqa_logits calls in
    _get_topk_ragged (the non-chunked and the budget-chunked branches).
    topk_transform already receives the valid per-row range and ignores
    out-of-range positions, so the -inf pre-fill is redundant. gfx950 behavior
    is otherwise unchanged; the CUDA path is untouched.

Accuracy Tests

GSM8K 5-shot, full 1319 questions, GLM-5.1-MXFP4, MI350X (gfx950), tp4,
fp8_e4m3 KV:

accuracy invalid
before (clean_logits=True) 0.936 0.000
after (clean_logits=False) 0.938 0.000

No regression (delta within run-to-run noise).

Speed Benchmarks

E2E sglang.bench_serving (random, input 8192 / output 1024, median latencies),
GLM-5.1-MXFP4 / MI350X / tp4 / fp8_e4m3 KV:

Baseline (main):

concurrency total tok/s TTFT (ms) ITL (ms) E2EL (ms)
2 938 936 17.75 19664
4 1702 1783 18.64 21627
8 2837 2911 20.75 25916
16 4309 5185 24.33 34222
32 6138 9776 28.93 48123
64 8062 18946 35.57 73134

This PR (clean_logits=False):

concurrency total tok/s TTFT (ms) TTFT delta ITL (ms) E2EL (ms)
2 937 916 -2.1% 17.80 19643
4 1703 1751 -1.8% 18.66 21630
8 2820 2858 -1.8% 20.77 26134
16 4298 5084 -1.9% 24.42 34245
32 6223 9512 -2.7% 28.83 47390
64 8174 18440 -2.7% 35.56 72094

Median TTFT improves 1.8-2.7% across the sweep; median ITL is unchanged
(within +/-0.5%) and median E2EL is flat-to-slightly-better, confirming the
change is prefill-side with no decode regression. The benefit scales with how
prefill-heavy the workload is (short outputs / RAG / long context).

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.

CI States

Latest PR Test (Base): ❌ Run #28113605405
Latest PR Test (Extra): ❌ Run #28113605230

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@Raiden-Makoto Raiden-Makoto changed the title [AMD] perf(dsa): skip redundant -inf pre-fill of HIP indexer MQA-logits [AMD] [GLM5] skip redundant -inf pre-fill of HIP indexer MQA-logits Jun 20, 2026

@HaiShaw HaiShaw 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.

Please run pre-commit to avoid lint error.

On the HIP DSA indexer path, fp8_mqa_logits defaulted to clean_logits=True,
which torch.full(-inf)-initializes the [tokens x seq_len_kv] logits buffer
every layer. That pre-fill is O(seq^2) and grows quadratically with context.
The CUDA deep_gemm.fp8_mqa_logits path in the same function already passes
clean_logits=False and relies on topk_transform to mask invalid positions via
ks/ke/lengths. Align the HIP path with CUDA by passing clean_logits=False.

GLM-5.1-MXFP4 / MI355X (gfx950) / TP4 / fp8 KV: -2..3% median TTFT across a
2-64 concurrency sweep, +9.3% isolated prefill throughput, median ITL and
E2EL unchanged, GSM8K 93.6%->93.8% (no regression).
@Raiden-Makoto
Raiden-Makoto force-pushed the RM/dsa-skip-logits-clean branch from c8609c8 to 077c863 Compare June 22, 2026 14:30
@HaiShaw

HaiShaw commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Jun 22, 2026
@Raiden-Makoto

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

1 similar comment
@Raiden-Makoto

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@HaiShaw

HaiShaw commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

@amd-bot ci-status

@amd-bot

amd-bot commented Jun 23, 2026

Copy link
Copy Markdown

@HaiShaw

CI Status for PR #28757

Merge verdict: ⚠️ Do not merge on a green-CI assumption — the changed code is not exercised by any PR-CI test. All vendor pipelines completed (none pending), and none of the executed failures are caused by this PR — they are an NVIDIA CUDA-path NaN, an AMD non-DSA test timeout, an AMD VRAM-cleanup infra error, and an NPU throughput flake, none of which touch the HIP DSA indexer this PR modifies. But the PR's entire value (the HIP clean_logits=False path) sits in DSA-model code that only nightly=True AMD suites run, so PR CI green proves nothing here.

Caution

This PR's changed code is not exercised by any PR-CI test. The diff only affects the HIP fp8_mqa_logits path in dsa_indexer._get_topk_ragged, which is instantiated solely for DSA models (DeepSeek-V3.2, GLM-5.x). Every AMD suite covering it — test_deepseek_v32_eval_*, test_glm51_eval_*, and test_glm51_mxfp4_tp2_gsm8k_mi35x (the GLM-5.1-MXFP4 config the author validated) — is registered nightly=True and does not run on PR CI. Before merging, run the nightly DSA AMD accuracy suites (e.g. nightly-amd-2-gpu-mi35x-glm51-mxfp4, nightly-amd-8-gpu-mi35x-deepseek-v32) on this branch, or attach the author's GSM8K/bench numbers as the verification of record.

Changed files: python/sglang/srt/layers/attention/dsa/dsa_indexer.py (+13/-1)

Executed CI failure attribution: AMD: 2 failures (0 related) · Others: 2 root-cause failures (0 related) + 5 fast-fail cascade jobs (NVIDIA base-c)

AMD Executed Failures

Job Test File Test Function Error Related? Why
stage-c-test-large-8-gpu-amd (3) test/registered/amd/test_deepseek_v3_mtp.py N/A (whole-file timeout) TIMEOUT after 5400s (est 980s) 🟢 Regular DeepSeek-V3 (MTP) does not use the DSA sparse indexer; the changed _get_topk_ragged HIP path is never reached. Hang/infra, not this diff.
stage-c-test-4-gpu-amd (0) N/A (runner) N/A VRAM cleanup unsuccessful after 3 attempts → exit 1 🟢 Runner/environment cleanup failure, no test executed. Infra.

Other Executed Failures

Job Test File Test Function Error Related? Why
base-c-test-4-gpu-b200 (2) test/registered/models_e2e/test_deepseek_v3_fp4.py TestDeepseekV3FP4SymmetricMemory.test_gsm8k Assertion 'NaN detected! sampler: next_token_logits' → exit 255 🟢 NVIDIA B200 / CUDA path; this PR touches only the HIP branch and leaves deep_gemm.fp8_mqa_logits untouched. Also a non-DSA FP4 model.
stage-b-test-1-npu-a2 (0) test/registered/ascend/basic_function/quant/test_npu_w8a8_quantization.py test_* (Qwen2.5-0.5B w8a8) throughput 536–606 tok/s < 700 threshold 🟢 NPU w8a8 throughput perf check on Qwen2.5; unrelated backend and model, no DSA indexer. Perf flake.

Fast-fail cascade (not independent failures): NVIDIA base-c-test-4-gpu-b200 (3), base-c-test-8-gpu-h20 (1), base-c-test-4-gpu-h100 (1), base-c-test-4-gpu-h100 (2), base-c-test-8-gpu-h200 (2) all report Fast-fail: skipping — root cause job(s): base-c-test-4-gpu-b200 (2). The *-finish and call-gate / pr-gate jobs are aggregators reflecting the above.

Details / what to do before merge

  • Coverage (the only real blocker): the changed HIP path is nightly-gated. Run the DSA AMD accuracy suites on this branch before merge — nightly-amd-2-gpu-mi35x-glm51-mxfp4 (GLM-5.1-MXFP4, the validated config) and nightly-amd-8-gpu-mi35x-deepseek-v32 / nightly-amd-accuracy-8-gpu-deepseek-v32 — or record the author's GSM8K (0.936→0.938) and bench numbers as the accepted verification. The PR description already provides strong manual evidence; just don't treat PR CI as having confirmed it.
  • AMD 8-GPU timeout (🟢): worth a quick glance only to confirm it's a pre-existing/infra hang on test_deepseek_v3_mtp.py (regular V3, no sparse indexer) and not a runner capacity issue on the PR's runs; it is not on the changed code path.
  • NVIDIA / NPU / VRAM failures (🟢): unrelated to this diff; no action required for this PR.

Generated by amd-bot using Claude Code CLI

@HaiShaw

HaiShaw commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

@Raiden-Makoto Can you add unit test file for the code change, and upload test results?

…l-project#28757)

Verifies fp8_mqa_logits(clean_logits=False) + masked topk selects identical KV
positions as clean_logits=True, with a sanity check that clean_logits=False
genuinely skips the -inf pre-fill.
@Raiden-Makoto

Raiden-Makoto commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Added a unit test for this change: test/registered/amd/test_dsa_skip_logits_clean.py (registered to stage-b-test-1-gpu-small-amd-mi35x).

It exercises the exact correctness guarantee behind clean_logits=False: the real aiter fp8_mqa_logits is run with clean_logits=True and clean_logits=False, then the production sgl_kernel.fast_topk_v2 masked topk is applied to each, and the selected KV positions must be identical. A sanity assertion confirms clean_logits=False actually leaves non--inf values at the invalid [ke, s_k) tail (otherwise the masking path would not be exercised). Shapes cover decode-like and prefill-like s_q (1 / 16 / 128), s_k=4096, topk=2048. Can test more shapes if needed,

Test results — AMD Instinct MI350X (gfx950), ROCm 7.2.0:

$ python3 -m unittest -v test_dsa_skip_logits_clean
test_skip_logits_clean_topk_equivalence (test_dsa_skip_logits_clean.TestDSASkipLogitsClean) ... ok

Ran 1 test in 0.700s

OK

@HaiShaw
HaiShaw merged commit 9215da2 into sgl-project:main Jun 25, 2026
111 of 125 checks passed
@Raiden-Makoto
Raiden-Makoto deleted the RM/dsa-skip-logits-clean branch July 7, 2026 19:06
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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