Skip to content

[ROCm][DSA] Enable AITER fused FP8 indexer writer - #40710

Merged
HaiShaw merged 5 commits into
sgl-project:mainfrom
fanxingran:feat/rocm-aiter-fused-fp8-dsa-writer
Sep 24, 2026
Merged

HaiShaw merged 5 commits into
sgl-project:mainfrom
fanxingran:feat/rocm-aiter-fused-fp8-dsa-writer

Conversation

@fanxingran

@fanxingran fanxingran commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

On HIP, the DSA FP8 indexer writer currently issues a chain of small kernels (K LayerNorm, joint Q/K RoPE, optional Hadamard, Q/K FP8 quant, and the paged index-K cache store). That launch overhead shows up on decode ITL, especially the tail.

CUDA already fuses the analogous indexer writer (SGLANG_DISABLE_DSA_INDEXER_FUSION, default on). This PR adds the ROCm counterpart via AITER indexer_qk_rope_quant_and_cache, so HIP can fuse RoPE + K LayerNorm + FP8 quant + cache write into one kernel. Hadamard is omitted, matching the CUDA fused writer (pre-quant logits stay aligned).

The path is default-on when AITER is available and indexer geometry matches (head_dim=128, rope_dim=64, quant_block=128, index-K LayerNorm). Models that do not match (including RMSNorm index-K) keep the legacy split writer. Set SGLANG_AITER_FUSED_FP8_DSA_INDEXER=0 to force the split path.

Validated on GLM-5.2-MXFP4 (gfx950). Any DSA indexer with the same geometry can take this path; it is not hardcoded to a model name.

Modifications

  • python/sglang/kernels/ops/attention/dsa/fp8_fused_writer_hip.py: AITER adapter (geometry checks, RoPE table reshape, fused Q/K write).
  • python/sglang/srt/layers/attention/dsa/dsa_indexer.py: enable fused writer when HIP + AITER + geometry match; LayerNorm in fp32 only on the fused path; warn only if the env is explicitly set and unsupported.
  • python/sglang/srt/environ.py: SGLANG_AITER_FUSED_FP8_DSA_INDEXER = EnvBool(True).
  • Tests:
    • test/registered/unit/layers/attention/test_fp8_fused_writer_hip.py
    • test/registered/amd/test_fp8_fused_dsa_writer_gfx950.py

Accuracy Tests

GSM8K via local sglang.test.run_eval (1314 questions), GLM-5.2-MXFP4, baseline = fused off (SGLANG_AITER_FUSED_FP8_DSA_INDEXER=0).

Baseline Fused
Score 0.935 0.936

No accuracy regression. Server log contains Enabled AITER fused FP8 DSA indexer writer.

Speed Tests and Profiling

Hardware: gfx950. Workload: InferenceX AgentX, 1200s (not the 3600s publication window). Toggle only SGLANG_AITER_FUSED_FP8_DSA_INDEXER. Interactivity = output token throughput per user; TPOT = ITL.

TP4 / EP4 / concurrency 8, HiCache DRAM

Request mix is aligned (510 vs 518 completed; ISL/OSL mean 103925/568 vs 104042/563).

Metric Baseline Fused Delta
P90 interactivity (tok/s/user) 190.02 194.48 +2.4%
P90 E2E-norm interactivity 153.12 157.97 +3.2%
P50 interactivity 135.78 137.08 +1.0%
TTFT p90 1.197 s 1.225 s +2.3%
TPOT p90 13.0 ms 12.5 ms −3.8%
TPOT avg 9.19 ms 8.64 ms −6.0%
TPOT p99 40.5 ms 34.1 ms −15.7%
E2E latency p90 10.85 s 9.80 s −9.6%
Throughput / chip 10832 tok/s 11013 tok/s +1.7%
Output throughput 235.5 tok/s 236.9 tok/s +0.6%
Completed requests 510 518 —

Gain is mainly decode tail latency (p99 ITL), not prefill.

TP8 / EP1 / concurrency 1, no HiCache

Request count 155 vs 157; ISL aligned. OSL mean 646 vs 582, so E2E and output throughput are not causal. Use interactivity / ITL.

Metric Baseline Fused Delta
P90 interactivity (tok/s/user) 244.64 252.77 +3.3%
P90 E2E-norm interactivity 214.62 224.71 +4.7%
P50 interactivity 234.51 241.99 +3.2%
TTFT p90 1.689 s 1.557 s −7.8%
TPOT p90 4.64 ms 4.53 ms −2.3%
TPOT p99 7.20 ms 6.92 ms −4.0%
Completed requests 155 157 —

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 #35808442739
Latest PR Test (Extra): ❌ Run #35808442600
Latest PR Test (AMD ROCm 10): ⏳ Run #35808442791

@fanxingran

Copy link
Copy Markdown
Contributor Author

Hi @kkHuang-amd @HaiShaw @yuan-luo — could you take a look at this ROCm DSA fused FP8 indexer writer (AITER indexer_qk_rope_quant_and_cache, default-on when geometry matches)?

CI failed at pr-gate only (~5s); the actual test jobs did not run. Could you please /tag-and-rerun-ci (and /tag-and-rerun-ci extra if needed) so the AMD pipeline can start?

Thanks!

@1am9trash 1am9trash added the run-ci CI: run the baseline test suite on this PR label Sep 22, 2026
@1am9trash

Copy link
Copy Markdown
Collaborator

Hi, @fanxingran
I added the tag and re-triggered CI, but I found that lint format check failed.
May you take a look when you are free? Thanks.

@fanxingran

Copy link
Copy Markdown
Contributor Author

Hi, @fanxingran I added the tag and re-triggered CI, but I found that lint format check failed. May you take a look when you are free? Thanks.

Hi @1am9trash, thanks for tagging CI and catching the lint.

I ran pre-commit locally (ruff format). It only reformatted wrapping in dsa_indexer.py and test_fp8_fused_dsa_writer_gfx950.py — no logic change. Pushed in 54362bf. Local hooks are green; CI should pick this up.

Thanks!

@fanxingran

Copy link
Copy Markdown
Contributor Author

Hi @1am9trash — we pushed a gfx950 arch gate (a24a22de8d) so MI300 no longer takes the fused writer (the AITER Python symbol can import there, but the GPU kernel is gfx950-only). Also dropped the HIP unit test from NVIDIA base-a CPU.

Our own push is rate-limited: User 'fanxingran' already triggered 'PR Test Base' via 'pull_request' ... wait 120 minutes. Could you please /tag-and-rerun-ci so Base/AMD pick up this commit? Thanks!

return False
if not torch.cuda.is_available():
return False
return "gfx95" in str(torch.cuda.get_device_properties(0).gcnArchName)

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.

Hi, @fanxingran
Can _is_gfx95() reuse sglang.srt.utils.is_gfx95_supported() utility?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reused sglang.srt.utils.is_gfx95_supported() and dropped the local helper.


from aiter.ops.cache import indexer_qk_rope_quant_and_cache

indexer_qk_rope_quant_and_cache(

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.

Hi, @fanxingran
This path calls indexer_qk_rope_quant_and_cache, which sglang indexer did not use before.
Do we need to bump the sglang aiter version?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No sglang AITER pin in this PR. Images clone ROCm/aiter; if indexer_qk_rope_quant_and_cache is missing we fall back via ImportError/AttributeError.

Comment thread python/sglang/srt/environ.py Outdated
SGLANG_DISABLE_DSA_INDEXER_FUSION = EnvBool(False)
# HIP analog of CUDA DSA indexer fusion (default on). Set 0 for the
# legacy split writer. Omits Hadamard; pre-quant logits match.
SGLANG_AITER_FUSED_FP8_DSA_INDEXER = EnvBool(True)

@1am9trash 1am9trash Sep 22, 2026 •

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.

Hi, @fanxingran
CUDA uses SGLANG_DISABLE_DSA_INDEXER_FUSION (default on). Should we use the same disable-style flag?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added SGLANG_DISABLE_AITER_FUSED_FP8_DSA_INDEXER (default False). Kept it separate from SGLANG_DISABLE_DSA_INDEXER_FUSION because that CUDA flag also packs wk/weights_proj.

@1am9trash 1am9trash Sep 22, 2026 •

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.

Hi, @fanxingran
On some fallbacks (_get_q_k_bf16), Hadamard is gated only by _maybe_rotate(), which does not include the HIP fused flag.
May that crash our code path, or are those paths unreachable on HIP?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_maybe_rotate now skips Hadamard when the HIP fused writer is on as well, so fallback K matches the fused cache. It would mismatch, not crash.

Reuse is_gfx95_supported, switch to a disable-style HIP env flag, and skip Hadamard on the HIP fused fallback path.
@fanxingran

Copy link
Copy Markdown
Contributor Author

Hi @1am9trash, thanks for the review.

All four are addressed in b4356e3:

  1. Reused is_gfx95_supported().
  2. No sglang AITER pin; missing indexer_qk_rope_quant_and_cache falls back via ImportError.
  3. HIP uses SGLANG_DISABLE_AITER_FUSED_FP8_DSA_INDEXER (default on). Separate from CUDA SGLANG_DISABLE_DSA_INDEXER_FUSION because that flag also packs wk/weights_proj.
  4. _maybe_rotate now skips Hadamard when the HIP fused writer is on.

Could you please take another look at those replies? If anything still needs a change, I will follow up right away; if it looks good, an approve would be very helpful.

CI on b4356e3 is already running (Lint / Base / AMD).

@1am9trash 1am9trash 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.

Thanks for the update.
All comments are resolved.
LGTM.

@fanxingran

Copy link
Copy Markdown
Contributor Author

Hi @1am9trash, the AMD mi35x failure is in test_triton_mla_kv_cache.py, which is unrelated to this PR — we did not change Triton MLA / KV cache. That test should be fine; this looks like a flake. Could you please /rerun-failed-ci? Thanks!

aiter_fused_fp8_writer_available,
fused_fp8_writer_geometry_supported,
prepare_aiter_rope_caches,
)

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.

@fanxingran let's put this hip specific import under _is_hip, in follow-up PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @HaiShaw,I will move the HIP-only import under _is_hip in a follow-up.

@fanxingran

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@HaiShaw

HaiShaw commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

AITER specific

@HaiShaw

HaiShaw commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Previous base-c-test-8-gpu-b300 (0) was known issue listed in #17050

@HaiShaw
HaiShaw merged commit 0dc8b29 into sgl-project:main Sep 24, 2026
344 of 391 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jit-kernel 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