You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Triton/Gluon] [gfx942] Support fp8 KV caches and fp8 dots in sparse_mla_fwd on gfx942 - #6199
#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:
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.
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.
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.
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.
…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]>
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(
notis_hip_cdna3() orcfg.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.
…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.
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.
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.
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.
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
#5721 enabled
sparse_mla_fwdon 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 fp8from a crash into a speedup (end-to-end numbers below).Technical details
Two commits:
FP8_FNUZconstexpr picks the fp8 type the dequant reads, and the wrapper sets it from the arch. gfx942 now takes the per-tensorfp8_scalarcache under bf16 dots. A typed cache in the other arch's encoding is refused instead of misread.p * 128, and the epilogue divides that back out along with the V scale._sparse_mla_fp8launch config at BLOCK_K 64, since one-byte tiles fit twice the bf16 tile's rows.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:
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.
Test plan
op_tests/triton_tests/attention/test_sparse_mla.pyon gfx942 (MI325X, rocm/pytorch rocm7.2.4 image, triton 3.8.0) atcda1a160: 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.