Skip to content

[Triton/Gluon] [gfx942] Support fp8 KV caches and fp8 dots in sparse_mla_fwd on gfx942 - #6199

Merged
phambinhfin merged 18 commits into
ROCm:mainfrom
jin-amd:gfx942-sparse-mla-fp8
Nov 23, 2026
Merged

phambinhfin merged 18 commits into
ROCm:mainfrom
jin-amd:gfx942-sparse-mla-fp8

Conversation

@jin-amd

@jin-amd jin-amd commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

#5721 enabled sparse_mla_fwd on gfx942 for bf16 caches only. The kernel decoded fp8 as OCP e4m3, while gfx942's native fp8, which is also what vLLM's fp8 KV cache stores there, is e4m3fnuz. This PR adds the fp8 cache on gfx942 under both dot precisions. For GLM-5.3-Flash on MI325X, it turns --kv-cache-dtype fp8 from a crash into a speedup (end-to-end numbers below).

Technical details

Two commits:

  1. Read the fp8_scalar cache as e4m3fnuz on gfx942. An FP8_FNUZ constexpr picks the fp8 type the dequant reads, and the wrapper sets it from the arch. gfx942 now takes the per-tensor fp8_scalar cache under bf16 dots. A typed cache in the other arch's encoding is refused instead of misread.
  2. Run fp8 dots on gfx942.
    • The staging, the in-kernel Q quantization (now to 240, fnuz's max) and P use the arch's fp8 type.
    • The MFMA layouts take version 3 for fnuz operands, because only CDNA3 intrinsics accept them.
    • P is quantized as p * 128, and the epilogue divides that back out along with the V scale.
    • gfx942 publishes a _sparse_mla_fp8 launch config at BLOCK_K 64, since one-byte tiles fit twice the bf16 tile's rows.
    • The LDS budget check models one-byte tiles. It matches the compiled kernels: 34816 B rope-free and 39936 B with 64 rope.

gfx950 keeps its numerics: the OCP type, MFMA version 4, and a P scale of 1.

Results

MI325X, at the GLM-5.3-Flash TP4 shape (16 heads, rope-free 512, top-k 2048). Kernel time per call:

bf16 cache fp8 cache, bf16 dots fp8 cache, fp8 dots
Decode, 2 tokens 33.2 µs 30.7 µs 23.7 µs
Decode, 16 tokens 37.4 µs 32.7 µs 25.4 µs
Prefill, 16K tokens 10.55 ms 9.35 ms 5.78 ms

For fp8 dots, BLOCK_K 32 and 8 warps were both slower.

Accuracy. Relative L2 error against f32 attention over the same fp8 cache is 0.2-0.3% with bf16 dots. With fp8 dots it is 3.4% on N(0,1) inputs and 4.5% on peaky attention, almost all of it from quantizing Q. Without the P scale, a long softmax tail flushes to zero in fnuz. In a test with one key scoring 9 above 2047 others that together carry a fifth of the output (split-K off), the error is 14.5% unscaled and 1.7% scaled.

End to end. vLLM serving GLM-5.3-Flash at TP4, 131K tokens in and 1K out, concurrency 2-16. The attend was routed to this kernel by a vLLM build carrying vllm-project/vllm#57134 and a small Gluon dispatch helper that upstream vLLM does not have.

bf16 KV fp8 KV, bf16 dots fp8 KV, fp8 dots
Output tok/s (geomean) 155.1 157.1 165.7
TPOT 28.1 ms 27.5 ms 26.4 ms
gsm8k, 5-shot strict (±0.005) 0.974 0.970 0.973
Needle in a haystack, 4K-128K 60/60 60/60 60/60
KV cache capacity 12.2M tokens 23.1M 23.1M

Test plan

op_tests/triton_tests/attention/test_sparse_mla.py on gfx942 (MI325X, rocm/pytorch rocm7.2.4 image, triton 3.8.0) at cda1a160: 83 passed, 69 skipped. The fp8-dot cases now run on gfx942, and new tests cover the foreign-encoding rejection and the fp8-tile LDS budget. Of the skips, 68 are #7429's custom fp8 kernel and 1 is the fp8_dsv32_mla cache, both gfx950-only.

I have no gfx950 hardware, so I did not run these changes there myself. gfx950 keeps its fp8 type, MFMA version and a P scale of 1, and CI's six MI35X shards are green on this head.

@jin-amd
jin-amd requested review from a team and a balanced review from Copilot October 7, 2026 07:57
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
multigpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 6199 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The benchmark still skips the new gfx942 path, and kernel trace representations omit its fp8 encoding specialization.

Review effort: Balanced
Findings: 1 Medium severity · 1 Low severity

Open (2)
What changed in this PR

Adds gfx942-native fp8 cache decoding and fp8 dot support to sparse MLA while preserving gfx950 behavior.

Changes:

  • Selects architecture-native fp8 encoding and MFMA layouts.
  • Adds gfx942 fp8 launch configuration and LDS validation.
  • Expands correctness and encoding-rejection tests.
File Description
aiter/​ops/​triton/​attention/​sparse_mla.py Enables and dispatches gfx942 fp8 paths.
aiter/​ops/​triton/​_gluon_kernels/​gfx950/​attention/​sparse_mla.py Implements fnuz decoding, quantization, and scaling.
aiter/​ops/​triton/​configs/​gfx942/​gluon/​attention/​sparse_mla/​DEFAULT.json Adds the gfx942 fp8 launch configuration.
op_tests/​triton_tests/​attention/​test_sparse_mla.py Covers fp8 execution, validation, and LDS limits.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@zufayu
zufayu requested review from a team and Dewei-Wang-sh October 8, 2026 02:08
Copilot AI balanced review requested due to automatic review settings October 8, 2026 08:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Flat-cache validation permits unsupported byte dtypes, and the FP8 probability-scaling invariant lacks focused regression coverage.

1 open finding
2 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Medium severity Add peaky-attention regression coverage for FP8 probability scaling

aiter/​ops/​triton/​_gluon_kernels/​gfx950/​attention/​sparse_mla.py:341

The existing fp8 accuracy matrix uses small random Q/K values, so its per-tile softmax probabilities stay close to one and it does not exercise the long-tail underflow that this new P_SCALE is intended to prevent. A regression to P_SCALE = 1 could therefore pass the suite while substantially changing peaky-attention output. Add the described one-dominant-key/2047-tail case (or an equivalent focused case) so the scaling and epilogue compensation are asserted.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Copilot AI balanced review requested due to automatic review settings October 8, 2026 08:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The architecture-sensitive numerical kernel changes were validated on gfx942 but still lack gfx950 execution coverage.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The architecture-specific kernel changes require final human review and gfx950 CI validation.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The low-level numerical and MFMA changes require human review and gfx950 validation before approval.

0 open findings

🧠 Review effort: Balanced

jin-amd added a commit to jin-amd/vllm that referenced this pull request Oct 13, 2026
…ing FP8 KV

VLLM_ROCM_USE_AITER_TRITON_SPARSE_MLA now also takes effect on gfx942 for the
ROCM_AITER_MLA_SPARSE backend's rope-free layout (GLM-5.3-Flash), when the
installed aiter's sparse_mla lists gfx942 (ROCm/aiter#5721). An fp8 KV cache
also needs an aiter that reads it on gfx942 (ROCm/aiter#6199). That kernel
takes no fp8 q, so q stays in the model dtype and the kernel quantizes it
under fp8 dots. gfx950 and DeepSeek V4/V4.1 are unchanged.

Signed-off-by: Jin Tao <[email protected]>
jin-amd added a commit to jin-amd/vllm that referenced this pull request Oct 13, 2026
…ing FP8 KV

VLLM_ROCM_USE_AITER_TRITON_SPARSE_MLA now also takes effect on gfx942 for the
ROCM_AITER_MLA_SPARSE backend's rope-free layout (GLM-5.3-Flash), when the
installed aiter's sparse_mla lists gfx942 (ROCm/aiter#5721). An fp8 KV cache
also needs an aiter that reads it on gfx942 (ROCm/aiter#6199). That kernel
takes no fp8 q, so q stays in the model dtype and the kernel quantizes it
under fp8 dots. gfx950 and DeepSeek V4/V4.1 are unchanged.

Signed-off-by: Jin Tao <[email protected]>
@phambinhfin
phambinhfin force-pushed the gfx942-sparse-mla-fp8 branch from f5d031a to cda1a16 Compare November 11, 2026 21:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@zufayu
zufayu requested review from a team and removed request for a team November 13, 2026 01:48
Copilot AI balanced review requested due to automatic review settings November 13, 2026 20:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

New test docstrings and benchmark commentary violate the short-sentence documentation rule and need to be split into shorter sentences.

2 open issues

Review effort: Balanced

@phambinhfin

Copy link
Copy Markdown
Contributor

@azaidy Could you check again, since you request the change so this can not merge.

Keep ROCm#7510's gfx942 fp8_dsv32_mla path with this branch's fp8_scalar
cache and fp8 dots. Scaled-cache dequant already follows FP8_FNUZ.
Copilot AI balanced review requested due to automatic review settings November 17, 2026 17:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The docstrings at lines 259 and 611 of test_sparse_mla.py need shorter sentences to comply with the required short-comment and ASD-STE100 style rules.

2 open issues

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The sparse MLA test and benchmark contain overly long comments and docstrings that violate the repository’s short-sentence guidance.

2 open issues

Review effort: Balanced

The parameterized FP8_TY decodes whatever the wrapper passes, where the
target predicate it replaced could not be wrong.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Comments and docstrings in test_sparse_mla.py violate the repository’s brevity rules and need to be shortened.

2 open issues

Review effort: Balanced

@phambinhfin

Copy link
Copy Markdown
Contributor

Added the static_assert in ab1fc215. It sits right after the Cfg construction, which is where FP8_TY is derived and ahead of every consumer (_fp8_to_f32, _fp8_to_bf16, the P quantization, FP8_MAX), so one assert covers the parameterization rather than each decode site:

gl.static_assert(
    not is_hip_cdna3() or cfg.FP8_TY == gl.float8e4b8,
    "CDNA3 reads fp8 as e4m3fnuz; FP8_FNUZ must be set",
)

On the four deciders: FNUZ_ARCHS is the removable one. Both its uses take the running arch (_classify_flat and the launch site both call arch_info.get_arch()), which is what get_fp8_e4m3_dtype() already reports. FNUZ_DSV32_ARCHS cannot collapse into it: it is the capability probe a caller reads, and _check_fp8_arch evaluates it for an arbitrary arch argument, which the running-arch helper cannot answer. Thanks for the note on #6955 — I'll retarget it at FNUZ_ARCHS rather than _classify_flat:281 alone.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

An overlong comment and docstring in the sparse MLA tests still violate the repository’s short, simple comment guidelines.

3 open issues

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Active findings identify overlong test docstrings that violate repository guidelines and obscure test conditions and dispatch setup.

2 open issues
1 resolved since last review

Review effort: Balanced

…nt rule

Review follow-up. The bench module note is two short sentences, and the softmax-tail test docstring is two short sentences. No behavior change.
@phambinhfin

Copy link
Copy Markdown
Contributor

@azaidy @ahmed-bsod please re-review. Head is cefcb53.

The two long docstrings Copilot flagged are shortened in that commit. The CDNA3 fnuz static_assert is already on the branch. get_fp8_e4m3_dtype() stays in #6955, as requested on sparse_mla.py:289.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The cache-shape explanation in test_sparse_mla.py:259 violates the documented short-sentence rule and should be shortened to explain why valid 3-D pools isolate the architecture gate.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The FP8 encoding, MFMA layout, probability scaling, and LDS changes require head-matched gfx942/gfx950 validation, as source-only reviews could not independently confirm numerical correctness or performance.

No open issues 🎉

Review effort: Balanced

@azaidy azaidy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

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.

8 participants