Skip to content

[AMD][DSV4] fp8 unified_kv decode/verify via aiter FlyDSL v4 nm decode - #41383

Closed
AMD-yanfeiwang wants to merge 2 commits into
sgl-project:mainfrom
AMD-yanfeiwang:perf/dsv4-fp8-flydsl-fused-decode
Closed

AMD-yanfeiwang wants to merge 2 commits into
sgl-project:mainfrom
AMD-yanfeiwang:perf/dsv4-fp8-flydsl-fused-decode

Conversation

@AMD-yanfeiwang

@AMD-yanfeiwang AMD-yanfeiwang commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

On gfx950, DSv4 fp8 unified_kv decode and target verify run the asm mla_a8w8_qh64_qseqlen1_gqaratio64_nm kernel, then a stage-2 split merge, then a separate inverse-RoPE + wo_a mxfp8 quant. This PR moves all three into one launch of aiter's FlyDSL v4 nm decode (ROCm/aiter#5882). On the current image it cuts the 8K/1K step time by 1.1–3.9%.

Modifications

  • decode_fp8_2buff calls aiter.ops.flydsl.flydsl_mla_decode_fwd_v4_nm when the installed aiter has it. The kernel picks its own split plan from the stream kind (CSA / HCA / SWA-only).
  • fp8 wo_a: the same launch also does the inverse RoPE and the wo_a mxfp8 quant, so MQALayer runs only the a8w8 GEMM.
  • DSpark target verify: HCA and SWA-only layers read one stream per request (per-draft q_kv_bounds) where aiter's flydsl_mla_v4_grouped_pays says it pays. CSA stays per-token. The output matches per-token verify.
  • On by default; SGLANG_DSV4_FLYDSL_DECODE=0 keeps the asm path.
  • Without [FlyDSL] [MLA] DeepSeek-V4 fp8 MLA decode (v4 nm) in one FlyDSL launch on gfx950 ROCm/aiter#5882 (e.g. current aiter main): aiter.ops.flydsl has no flydsl_mla_v4_decode_supported, so _flydsl_v4_decode() catches the AttributeError (or ImportError if FlyDSL is missing) and returns None. Then decode/verify call the asm mla_decode_fwd_v4_nm with the same split policy as today, wo_a keeps its current path, and no grouped-verify metadata is built. Behaviour is the same as main; there is just no speedup. The FlyDSL cases in the test skip.
  • Test: test/registered/e2e/dsv4/test_dsv4_unified_fp8_decode.py checks decode, fused wo_a (incl. H128) and grouped verify against asm and a reference.

Accuracy Tests

gsm8k (1319 q), DSv4-Pro TP8 + DSpark 6, one run per boot, same setup as the E2E below:

boot 1 boot 2 accept length
stock asm 0.942 0.944 5.30
this PR 0.944 0.942 5.30

Speed Tests and Profiling

DSv4-Pro, 8x MI355X, lmsysorg/sglang-rocm:v0.5.20-rocm724-mi35x-20260927, 8K in / 1K out, TP8, fp8 KV (SGLANG_DSV4_UNIFIED_KV_FP8=1 SGLANG_OPT_FP8_WO_A_FUSED_INVROPE=1), CUDA graphs.

Config stock asm (ms) this PR (ms) Δ step, paired [min, max] decode tok/s
TP8, c8 13.28 12.75 -3.9% [-0.55, -0.49 ms] +4.1%
TP8, c32 17.13 16.61 -3.1% [-0.56, -0.48 ms] +3.2%
TP8 + DSpark 6, c16 27.45 26.95 -1.8% [-0.62, -0.38 ms] +2.7%
TP8 + DSpark 6, c64 46.91 46.03 -1.9% [-1.06, -0.61 ms] +2.5%
DP8 attention, c64 21.24 21.01 -1.1% [-0.26, -0.20 ms] +1.1%

All 30 paired differences are negative. The DSpark rows are the total gain vs the production asm path. In the earlier 20260922-image numbers, about 0.18 ms/step of the DSpark gain came from that asm baseline (ROCm/aiter#5195 .co + ROCm/aiter#5776 merge) building split_indptr in every layer; the stock asm wrapper here caches it, so none of the gain above comes from that.

Attention per step, in-graph kineto (µs), stock asm read + merge + inv-RoPE quant → one FlyDSL launch:

TP8 c8 TP8 c32 DSpark c16 DSpark c64
stock asm 1199 1275 1633 3231
this PR 584 673 1111 2247
graph nodes -122 -122 -122 -59

The rest of the step is unchanged within 1–2%.

Kernel microbench (details in ROCm/aiter#5882), FlyDSL / best asm split + merge: 179 decode cells (H 16–128, msq 1–4, B 1–1024, L 128–16K) median 0.86, max 0.997; DSpark verify, 80 cells, median 0.86; 61-layer decode step 0.77–0.93x.

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 #38235907942
Latest PR Test (Extra): ❌ Run #38235907289
Latest PR Test (AMD ROCm 10): ❌ Run #38235907761

Route the fp8 two-pool unified_kv decode and target verify to aiter's FlyDSL
v4 nm decode (aiter.ops.flydsl) on gfx950 when the installed aiter ships it,
instead of the asm mla_a8w8_qh64_qseqlen1_gqaratio64_nm kernel + stage-2 merge:

* decode_fp8_2buff: drop-in kernel swap, one launch with the split merge,
  split plan picked per batch size and stream kind (CSA / HCA / SWA-only),
  H in 16 / 32 / 64 / 128.
* fp8 wo_a: the same launch also does the inverse RoPE and the wo_a mxfp8
  quant; MQALayer only runs the a8w8 mxscale GEMM on its output.
* DSpark target verify: where aiter's measured policy says it pays
  (flydsl_mla_v4_grouped_pays for the layer kind and the model's output
  mode), HCA and SWA-only layers read one stream per request with
  per-draft key ranges (q_kv_bounds), exact w.r.t. the per-token streams.
  CSA stays per token.

SGLANG_DSV4_FLYDSL_DECODE=0 keeps the asm path; an aiter without the FlyDSL
v4 decode falls back the same way.

Signed-off-by: Yanfei Wang <[email protected]>
…flicts with sgl-project#41308

sgl-project#41308 added an `inv_rope` argument next to this PR's `wo_a_quant_freqs`.
Conflict resolution only, no functional change:
- deepseek_v4_backend_hip_radix.py `_forward_attention`: keep both
  `inv_rope` (main) and `wo_a_quant_freqs` (this PR); keep main's docstring
  and this PR's `Union[Tensor, Tuple[Tensor, Tensor]]` return type.
- deepseek_v4.py `MQALayer.forward`: keep main's `inv_rope =
  _hip.attention_inv_rope(...)` followed by this PR's `wo_a_quant_freqs =
  None`; in the unified branch forward both `inv_rope` and
  `wo_a_quant_freqs` through rope_kwargs. `attention_inv_rope` returns None
  whenever `unified` is set, so the two never apply together.
Duyi-Wang added a commit to Duyi-Wang/sglang that referenced this pull request Oct 12, 2026
… until aiter ships it

The official aiter pin (ROCm/aiter main 02575f1c3a) has no FlyDSL v4 nm decode,
so sgl-project#41383's fp8 unified_kv decode/verify fell back to the asm kernel. Carry
ROCm/aiter#5882 at its sgl-project#6377-adapted head 03359c43df in-tree:

- python/sglang/kernels/ops/attention/dsv4/flydsl_v4nm/: mla_v4_decode.py,
  mla_v4_grouped.py, kernels/mla_v4_decode_{common,gfx950}.py copied from the
  PR (license header kept, source PR / commit / file noted); only the import
  paths changed (helpers come from aiter's public FlyDSL utils:
  communication_ops_utils, buffer_ops, kernels_common, tensor_shim) plus
  isort / ruff format. Importing it on an aiter before sgl-project#6377 raises ImportError.
- runtime._flydsl_v4_decode(): aiter.ops.flydsl when the installed aiter has
  the API, else the in-tree copy; logs which one once per process.
  SGLANG_DSV4_FLYDSL_DECODE_SOURCE=auto|aiter|intree (default auto) forces one
  copy; SGLANG_DSV4_FLYDSL_DECODE=0 still turns FlyDSL off (asm).
  SGLANG_DSV4_FLYDSL_DECODE_H128 gating is unchanged.
- test/registered/kernels/ops/attention/dsv4/test_flydsl_v4nm_decode.py: the
  PR's op_test ported to pytest, trimmed to the DSv4 shapes (H16/32/64/128
  msq1, H16 msq4, fused wo_a epilogue, grouped verify at 4/7 drafts), plus the
  source-selection contract.
- Kernel inventory entries for the two entry points; codespell skips the
  vendored directory (helper name `padd`).

Every piece carries TODO(aiter#5882): remove once ROCm/aiter#5882 is in the
aiter pin.
@AMD-yanfeiwang
AMD-yanfeiwang marked this pull request as ready for review October 16, 2026 09:03
@github-actions

Copy link
Copy Markdown
Contributor

Required checks failed on 266d7e8; this PR cannot be merged until they pass.

PR title (run)

PR title must use "[Type] scope: title" or "[Type] [Hardware] scope: title". Type must be one of: Feat, Fix, Refactor, Perf, Doc, Test, CI, Chore. Scope is required and may be any module or model name, with unrestricted letter case (letters, numbers, dots, underscores, slashes, or hyphens). Hardware is optional; use a single tag without spaces. Use uppercase hardware tags (AMD, NVIDIA, NPU, MI300X), except for exactly these four spellings: Intel, Apple, Huawei, Ascend. Reverts must use GitHub's default format: Revert "original title". Use one space between fields and after the colon, with a non-empty title and no leading or trailing whitespace. Examples: "[Fix] attention: Fix KV cache indexing", "[Feat] qwen3: Add model support", "[Perf] [AMD] flash-attn: Optimize decode performance".
Edit the title; the check reruns on its own.

@AMD-yanfeiwang

Copy link
Copy Markdown
Contributor Author

Superseded by #44016 .

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