Skip to content

[Perf] [AMD] dsa: Prefill rope-free bf16 KV pools with aiter's OPUS sparse kernel - #49282

Draft
eppaneamd wants to merge 4 commits into
sgl-project:mainfrom
eppaneamd:eppaneamd/dsa-aiter-sparse-prefill
Draft

eppaneamd wants to merge 4 commits into
sgl-project:mainfrom
eppaneamd:eppaneamd/dsa-aiter-sparse-prefill

Conversation

@eppaneamd

@eppaneamd eppaneamd commented Nov 9, 2026 •

Copy link
Copy Markdown

Motivation

GLM-5.3-Flash on ROCm prefills only with TileLang. Its DSA layers keep a bf16 KV pool with a 512-wide latent and no
RoPE part, and they append tail tokens to the top-k (index_kpool > 1). The kpool tail guard rejects
--dsa-prefill-backend aiter for that. Elsewhere the aiter prefill path runs AITER's decode kernel
(mla_decode_fwd) with each query token as its own sequence.

AITER has a sparse prefill kernel for this layout (OPUS), which SGLang already calls for DeepSeek-V4
(opus_sparse_prefill_hip.py). On MI355X this PR's call (CSR conversion and OPUS) takes 0.27–0.39× TileLang's time
for 2 K–16 K prefill rows at 32 and 16 heads per rank (kernel table below). End to end, GLM-5.3-Flash at TP 2 (one
768×1024 image and 6.5 K–8 K text tokens per request, concurrency 16–64) gains 17–18 % output throughput over TileLang
prefill on the same bf16 KV cache, and 6–7 % over the FP8 KV + TileLang recipe.

Modifications

  • kernels/ops/attention/dsv4/opus_sparse_prefill_hip.py: the sink is optional. Without one, the wrapper calls
    mla_sparse_prefill when AITER has it (≥ 0.1.28), else pa_sparse_prefill_opus with a −1e30 sink, which adds
    nothing to the softmax denominator. Both calls use one KV split: AITER's split-key path can leave a row with no keys
    non-finite, and the DSA padding rows have no keys. Calls with a sink (DeepSeek-V4) are unchanged.
  • layers/attention/dsa_backend.py: with --dsa-prefill-backend aiter, a prefill on gfx950 with a rope-free
    512-wide bf16 pool turns the page-size-1 top-k table into CSR (combined_to_csr, no host sync) and calls OPUS.
    • Requires DCP 1, no index-K sharding, no HiSparse and no logit cap; other configurations keep the current path.
    • Below 4,096 query rows × heads (128 rows at 32 heads per rank, 256 at 16) the prefill runs TileLang: there the
      conversion and the kernel cost a near-fixed 0.15–0.3 ms, more than TileLang.
  • layers/attention/dsa/dsa_backend_kpool.py: the kpool tail guard admits aiter for prefill when this path runs.
    Decode stays rejected.
  • Tests:
    • test/registered/unit/layers/attention/test_dsa_q8kv8_bf16_prefill_routing.py (CPU): the guard admits aiter
      for prefill and rejects it for decode. It fails without this PR.
    • test/registered/attention/unittests/dsv4/test_dsv41_opus_sparse_prefill_hip.py (gfx950): the call as DSA makes
      it, against an fp32 reference: a 2,051-column table with −1 holes and an empty row, 32 and 16 heads, few and many
      rows.

Scope: every DSA model with a rope-free 512-wide bf16 KV pool, on gfx950, with --dsa-prefill-backend aiter.
Measured: GLM-5.3-Flash. DeepSeek-V3.2-style pools (with a RoPE part), fp8 KV caches, gfx942 and CUDA are not
affected.

Accuracy Tests

python3 -m sglang.test.run_eval --api chat against the servers under Speed Tests (max tokens 2,048, temperature 0;
MMMU: the 900 validation items; GSM8K: the 1,319 test questions, 5-shot):

Session Prefill backend KV cache MMMU GSM8K
1 tilelang bf16 0.690 0.973
1 aiter (this PR) bf16 0.700 0.968
2 tilelang fp8_e4m3 0.694 0.974
2 aiter (this PR) bf16 0.701 0.974

One standard error is 1.5 pp on MMMU and 0.5 pp on GSM8K. An earlier session of the same bf16 tilelang server scored
0.697 and 0.971.

Speed Tests and Profiling

  • Image lmsysorg/sglang-rocm:v0.5.23-rocm724-mi35x-20261106 (SGLang 62384de1ae, AITER 285579b621) with this PR
    applied.
  • amd/GLM-5.3-Flash-Quark-MXFP4 (revision b5688f25), TP 2 on two MI355X; decode on tilelang throughout.
  • Per session: one server per configuration on the same two GPUs, the baseline first. Each server gets an untimed pass
    at each concurrency, then three repetitions of concurrency 16, 32 and 64 with 10 × concurrency requests. Every server
    uses the same seed per (concurrency, repetition); the output token counts matched in every cell.
  • Tables: mean ± standard error over the three repetitions.
SGLANG_USE_AITER=1 SAFETENSORS_FAST_GPU=1 \
SGLANG_DSA_PREFILL_DENSE_ATTN_KV_LEN_THRESHOLD=0 SGLANG_UNIFIED_RADIX_TREE_CORE_BACKEND=python \
python3 -m sglang.launch_server --model-path amd/GLM-5.3-Flash-Quark-MXFP4 --revision b5688f25 \
  --tp 2 --trust-remote-code --quantization quark --attention-backend dsa \
  --dsa-prefill-backend aiter --dsa-decode-backend tilelang \
  --context-length 131072 --mem-fraction-static 0.90 --enable-multimodal \
  --limit-mm-data-per-request '{"image": 1}' \
  --mm-process-config '{"image": {"min_image_tokens": 16, "max_image_tokens": 8000}}' \
  --mm-enable-dp-encoder --reasoning-parser glm45 --tool-call-parser glm47
# baselines: --dsa-prefill-backend tilelang; in session 2 also --kv-cache-dtype fp8_e4m3

python3 -m sglang.benchmark.serving --backend sglang --model amd/GLM-5.3-Flash-Quark-MXFP4 \
  --dataset-name image --image-count 1 --image-resolution 768x1024 \
  --random-input-len 8192 --random-output-len 64 --random-range-ratio 0.8 \
  --request-rate inf --max-concurrency $C --num-prompts $((10 * C)) --warmup-requests $C \
  --seed $((17 + C + 1000 * (REP - 1))) --flush-cache
  • SGLANG_DSA_PREFILL_DENSE_ATTN_KV_LEN_THRESHOLD=0: prefills of at most 2,048 KV tokens (the eval prompts) otherwise
    run the dense MHA path; the benchmark's prompts take the sparse prefill either way.
  • SGLANG_UNIFIED_RADIX_TREE_CORE_BACKEND=python: the containers had no network access, and the default core builds
    from crates.io at startup.

Session 1, bf16 KV cache in both servers:

Concurrency Output tok/s, tilelang aiter Ratio Mean TTFT ms, tilelang aiter Ratio
16 139.9 ± 1.4 163.1 ± 1.7 1.166 1,728 ± 33 1,404 ± 40 0.813
32 146.1 ± 1.1 171.5 ± 1.4 1.174 2,691 ± 71 2,229 ± 47 0.828
64 150.4 ± 0.6 177.2 ± 0.8 1.178 4,426 ± 32 3,774 ± 90 0.853

Session 2, tilelang on an fp8_e4m3 KV cache (the GLM-5.3-Flash cookbook's MI355X recipe) vs this PR on bf16:

Concurrency Output tok/s, tilelang fp8 aiter Ratio Mean TTFT ms, tilelang fp8 aiter Ratio
16 153.6 ± 1.9 163.5 ± 2.2 1.064 1,582 ± 33 1,421 ± 66 0.898
32 160.8 ± 1.4 171.7 ± 1.4 1.068 2,469 ± 29 2,186 ± 42 0.885
64 165.9 ± 0.6 177.7 ± 0.7 1.071 3,984 ± 85 3,701 ± 86 0.929
  • The fp8 cache held 16.1 M tokens, the bf16 one 8.3 M; neither filled at these loads.
  • The evals (short prompts, up to 2,048 output tokens) ran 3 % longer on the aiter server than on the fp8
    tilelang one: MMMU 300 s vs 291 s, GSM8K 98 s vs 95 s. Its decode reads the bf16 cache, about twice the bytes.

In the session-1 aiter server, 38,544 of the DSA prefill calls on TP rank 0 ran OPUS and 143 (0.4 %), with fewer
than 4,096 rows × heads, ran TileLang (counted by wrapping the two backend methods).

Kernel: this PR's prefill call vs TileLang (same image, one MI355X; bf16, 512-wide, 2,051-column table)
  • Image lmsysorg/sglang-rocm:v0.5.23-rocm724-mi35x-20261106 (SGLang 62384de1ae, AITER 285579b621, which has
    pa_sparse_prefill_opus only).
  • Times: median of 30 interleaved runs, µs. "PR call" includes the CSR conversion. Every output matches an fp32
    reference on sampled rows.
  • T@P: T new rows after a P-token prefix.
Heads Rows TileLang PR call PR / TileLang
32 2,048 1,772 473 0.266
32 8,192 7,267 2,251 0.309
32 16,384 14,737 4,895 0.332
32 8,192@8,192 7,465 2,580 0.345
16 2,048 874 312 0.357
16 8,192 3,326 1,198 0.359
16 16,384 6,814 2,513 0.368
16 8,192@8,192 3,413 1,345 0.390

Small calls (PR / TileLang, the larger of no prefix and an 8,192-token prefix): at 32 heads 1.246 at 32 rows, 0.929 at 64, 0.616 at 128; at 16 heads
1.029 at 128 rows, 0.714 at 256. The 4,096 rows × heads bound keeps every measured call at or below TileLang's time.

Notes

This change was developed with AI assistance (Claude); I reviewed every line and ran the tests listed.

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): ⊘ Skipped -- the PR is a draft; marking it ready starts a new run (AMD: then /rerun-failed-ci).
Latest PR Test (Extra): ⊘ Skipped -- the PR is a draft; marking it ready starts a new run (AMD: then /rerun-failed-ci).
Latest PR Test (AMD ROCm 10): ⚠️ Run #46306851898

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

With index_kpool > 1 (GLM-5.3-Flash) the kpool tail guard rejected the
aiter DSA prefill backend, and elsewhere that backend ran mla_decode_fwd
once per query token. On gfx950, a rope-free 512-wide bf16 pool now turns
the page-size-1 top-k table into CSR (combined_to_csr, no host sync) and
calls aiter's OPUS sparse prefill: mla_sparse_prefill without a sink when
the installed aiter has it (>= 0.1.28), else pa_sparse_prefill_opus with a
-1e30 sink, which adds nothing to the softmax denominator.

- The kpool tail guard admits aiter for prefill when this path is taken;
  decode stays rejected.
- The path needs DCP 1, no index-K sharding, no HiSparse and no logit cap;
  anything else keeps the per-token decode kernel.
- Below 4,096 query rows x heads (64 rows at 64 heads per rank, 128 at
  32, 256 at 16, 512 at 8) the prefill runs TileLang, with q made
  token-major for it: there the CSR conversion and the kernel cost a
  near-fixed 0.15-0.3 ms on MI355X, more than TileLang.
- The sink-less call runs unsplit (num_kv_splits=1): aiter's split-key
  kernel can leave a row with no keys non-finite, and the DSA padding rows
  have none. Calls with a sink (DeepSeek-V4) are unchanged.
- Tests: the guard (CPU), and the backend's prefill call as DSA makes it
  (gfx950: head-major q, a 2,051-column table with -1 holes and an empty
  row, 32 and 16 heads, few rows on TileLang and many on OPUS).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Rony Leppänen <[email protected]>

This branch has not been deployed

No deployments
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.

1 participant