Skip to content

[Triton/Gluon] [gfx942] Read the fp8_dsv32_mla cache in fnuz on gfx942 - #7510

Merged
azaidy merged 1 commit into
ROCm:mainfrom
xaguilar-amd:gfx942-sparse-mla-fp8-dsv32
Nov 16, 2026
Merged

azaidy merged 1 commit into
ROCm:mainfrom
xaguilar-amd:gfx942-sparse-mla-fp8-dsv32

Conversation

@xaguilar-amd

@xaguilar-amd xaguilar-amd commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

sparse_mla_fwd can now read the fp8_dsv32_mla KV cache (vLLM's fp8_ds_mla) on gfx942. gfx942 decodes it as its native e4m3 fnuz with bf16 q and bf16 dots. Every other fp8 input stays gfx950-only.

Motivation

On gfx942 the wrapper rejects every fp8 cache, because the kernel reads fp8 bytes as OCP e4m3 and gfx942's native fp8 is e4m3 fnuz. Producers on gfx942, vLLM's concat_and_cache_ds_mla included, write the fp8_dsv32_mla cache in fnuz. The layout is 512 fp8 | 4 f32 per-128 scales | 64 bf16 rope. As a result, DeepSeek-V3.2-style models such as Kimi-K3.1 can only use a bf16 cache on MI300X/MI325X, and vLLM refuses to start Kimi-K3.1 there unless the user passes --kv-cache-dtype bfloat16. The fp8 cache holds 1.62x as many tokens.

The fp8_dsv32_mla path already dequantizes each tile in f32 and runs bf16 dots, so only the decode was missing. A fnuz byte read as OCP comes out 2x too large, and as NaN where the quantizer saturated at 240.

Changes

  • aiter/ops/triton/_gluon_kernels/gfx950/attention/sparse_mla.py: _fp8_to_f32, which only the scaled caches use, bitcasts to float8e4b8 (fnuz) on CDNA3 and to float8e4nv (OCP) elsewhere. The branch is resolved at compile time with is_hip_cdna3(), so gfx950 code is unchanged. Of the scaled caches only fp8_dsv32_mla reaches this kernel on gfx942, since fp8_g64 is packed and gfx950-only.
  • aiter/ops/triton/attention/sparse_mla.py: the new FNUZ_DSV32_ARCHS = ("gfx942",) lists the archs that take fp8_dsv32_mla in their native fnuz.
    • _check_fp8_arch lets that cache through on those archs, with bf16 q only.
    • _check_packed_arch's message and the sparse_mla_fwd docstrings now name the formats gfx942 takes.
    • fp8 q, the fp8_scalar cache and dot_precision="fp8" still read OCP e4m3 and are still rejected on gfx942, with the same fnuz errors.
  • op_tests/triton_tests/attention/test_sparse_mla.py: the fp8_dsv32_mla correctness test now runs on gfx942, and the gate tests expect the new behavior (see Changed op tests).

FNUZ_DSV32_ARCHS also lets callers check for the capability. vLLM can allow fp8_ds_mla on gfx942 only when the installed aiter lists the arch, so that change can merge before vLLM bumps aiter.

Performance (if applicable)

Before this change gfx942 rejected fp8_dsv32_mla, so the baseline is the bf16 cache it had to fall back to. Both use bf16 q, top-k 2048, d_qk 576 and a 131,072-token pool. The times are the mean of triton.testing.do_bench on 3 GPUs.

Hardware Workload/configuration Before (bf16 cache) After (fp8_dsv32_mla) Change
MI325X (gfx942) sparse_mla_fwd decode, 8 queries, 12 heads 65.6 us 70.3 us 1.07x time
MI325X (gfx942) sparse_mla_fwd decode, 64 queries, 12 heads 96.9 us 93.8 us 0.97x time
MI325X (gfx942) sparse_mla_fwd decode, 64 queries, 16 heads 98.1 us 96.2 us 0.98x time
MI325X (gfx942) sparse_mla_fwd prefill, 4096 queries, 12 heads 3707 us 3778 us 1.02x time
MI325X (gfx942) KV cache row 1,152 B 656 B 0.57x memory

The kernel takes the same time within 7% on either cache, and the fp8 cache holds 1.62x the tokens in vLLM. gfx950 is not affected: there _fp8_to_f32 compiles to the same OCP convert as before.

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X (MI325X, gfx942)

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None. gfx942 accepts one input it used to reject, and every other input behaves as before on every arch.

PR Self-Review

Reviewed revision

98c734c

Behavior and intent

On gfx942, sparse_mla_fwd used to raise ValueError for the fp8_dsv32_mla cache. It now dequantizes that cache in its native fnuz and runs bf16 dots. fp8 q, fp8_scalar and fp8 dots are still rejected on gfx942, and nothing changes on gfx950. Before, gfx942 users of this layout could only fall back to a bf16 cache at 1.62x the memory, even though the dequant path needed only the arch's fp8 decode.

Validation and unverified scope

On 8x MI325X (gfx942), ROCm 10.0, Triton 3.8.0:

pytest op_tests/triton_tests/attention/test_sparse_mla.py
  • Unit tests: 47 passed, 97 skipped (the gfx950-only fp8 cases), 0 failed. ruff 0.16.0 and black are clean.
  • Negative control: with only the _fp8_to_f32 change reverted, all three test_ds_mla_format cases fail with NaN output.
  • End to end: I tested the same change on the aiter of a Kimi-K3.1 vLLM ROCm image, together with the vLLM gate change: Kimi-K3.1-Pro, TP8, int4 MoE, the fp8_ds_mla cache against bf16. Passkey retrieval inserts one key into filler text and asks for it back, at depths of 10%, 50% and 90%.
KV cache KV tokens GSM8K (250, zero-shot) Passkey 4k / 17k / 70k / 131k
fp8_ds_mla 1,482,843 0.984 3/3 at each length
bfloat16 914,136 0.980 3/3 at each length

Both caches gave the same GSM8K answer on 249 of 250 questions.

With the fp8_ds_mla cache and a production serving config (--max-model-len 135168, full and piecewise CUDA graphs), lm-eval 0.4.13 through the completions API gives:

  • GSM8K, 20-shot, all 1,319 questions: 0.9735 ± 0.0044, the same for strict and flexible extraction.
  • RULER NIAH, all 8 tasks: 1.0 at every length from 4k to 128k tokens (4k, 8k, 16k, 32k, 64k and 128k). That is 100 to 10 samples per task depending on length, 2,000 in total.

Unverified:

  • gfx950 and gfx942 in CI: Triton Tests (MI35X) and Triton Tests (MI300X, ci:triton-300x) ran the selected tests, test_sparse_mla.py included, and passed. On gfx950 that covers the fp8 cases that skip on gfx942.
  • gfx950 machine code: I compiled every _sparse_mla and _sparse_mla_fp8 variant that test_sparse_mla.py, test_pa_decode_sparse.py and test_mla_v4_triton.py build for gfx950 (TRITON_OVERRIDE_ARCH=gfx950), on this PR's base and head. The AMDGCN is identical for all 186 variants compiled in both runs.
  • MI250X (gfx90a) is not in SUPPORTED_ARCHS.
  • The end-to-end runs used the image's aiter, which is an older revision than this PR's base, with the same _fp8_to_f32 decode and _check_fp8_arch gate applied. The unit tests and the benchmark ran this branch's aiter/ops/triton tree.

PR-specific question

Before this PR, gfx942 can fail to read fp8_dsv32_mla in two ways. The wrapper's _check_fp8_arch raises a ValueError that names fnuz. If only that gate is relaxed, the kernel still decodes the bytes as OCP and returns NaN.

  • test_ds_mla_format[topk2048], [h12_lse], [prefill_lse]:
    • On the old code, each case raises the fnuz ValueError.
    • With the gate relaxed but _fp8_to_f32 still reading OCP, all three fail on NaN output (the negative control above).
    • They are the only tests that run the kernel on fp8_dsv32_mla. test_sparse_mla, test_sparse_mla_rope_free, test_return_lse and test_global_load_path parametrize over bf16 and tensor only, and test_sparse_mla_dsv4_train.py uses a bf16 cache.
    • Before this PR, test_ds_mla_format ran a single decode shape and skipped on gfx942. [h12_lse] and [prefill_lse] add checks that no existing test makes for this cache: the LSE output, a 12-head launch (the only non-power-of-two head count in the file) and the prefill launch config.
  • test_fp8_arch_gate: the bf16-q fp8_dsv32_mla case now expects gfx942 to accept the input. It fails on the old code, where _check_fp8_arch("gfx942", "fp8_dsv32_mla", torch.bfloat16) raises. The new fp8-q fp8_dsv32_mla case passes both before and after. It guards against relaxing the gate too far, since gfx942 must still reject fp8 q with this cache.
  • test_native_fp8_cache_rejected[dsmla]: it asserted the old rejection, so on the new code it would fail. It now skips on gfx942. [tensor] still checks that the per-tensor fp8 cache is rejected there.

Changed op tests

op_tests/triton_tests/attention/test_sparse_mla.py:

  • test_ds_mla_format used to skip on gfx942 and now runs there. It is parametrized over decode at top-k 2048, 12 heads with LSE (Kimi-K3.1's 96 heads at TP8, a non-power-of-two head count), and a 2048-query prefill shape with LSE, which runs gfx942's prefill launch config. The cache is packed and decoded in the arch-native fp8 (get_fp8_e4m3_dtype()), as a gfx942 producer writes it. No other test reads fp8_dsv32_mla on gfx942.
  • test_fp8_arch_gate now expects gfx942 to accept bf16 q with fp8_dsv32_mla, and has a new case for fp8 q with fp8_dsv32_mla, which must still be rejected there. The fp8_scalar and fp8-q cases keep the fnuz error.
  • test_native_fp8_cache_rejected[dsmla] skips on gfx942, which now reads that cache. [tensor] still checks the rejection.

sparse_mla_fwd rejected every fp8 cache on gfx942, because the kernel reads
fp8 bytes as OCP e4m3 and gfx942's native fp8 is e4m3 fnuz. Producers on gfx942
write the fp8_dsv32_mla cache (vLLM's fp8_ds_mla: 512 fp8 | 4 f32 per-128
scales | 64 bf16 rope) in fnuz, so DeepSeek-V3.2-style models such as
Kimi-K3.1 could only run there on a bf16 cache.

The fp8_dsv32_mla path already dequantizes each tile in f32 and runs bf16
dots, so the decode was the only gap: a byte read as OCP comes out 2x too
large, and NaN where the fnuz quantizer saturated at 240. _fp8_to_f32, which
only the scaled caches use, now bitcasts to float8e4b8 on CDNA3. fp8 q, the
fp8_scalar cache and fp8 dots keep the OCP reading and stay gfx950-only.

FNUZ_DSV32_ARCHS names the archs that take the cache this way, so a caller
such as vLLM can tell an aiter with this change from one without it.

Tests on MI325X (gfx942): test_sparse_mla.py has 47 passed and 97 skipped
(the gfx950-only fp8 cases). test_ds_mla_format now runs on gfx942 and covers
decode, 12 heads (Kimi-K3.1's 96 at TP8) with LSE, and a prefill shape with
LSE. With the decode change reverted, all three fail on NaN output. The gate
tests now expect gfx942 to take bf16 q with fp8_dsv32_mla and still reject
fp8 q with it.

End to end, with the same change on the aiter of a Kimi-K3.1 vLLM image,
Kimi-K3.1-Pro at TP8 on 8x MI325X with the fp8_ds_mla cache scores 0.984 on
GSM8K (250 questions, zero-shot) against 0.980 on a bf16 cache, retrieves
12/12 passkeys up to 131k tokens on both, and holds 1.62x the KV tokens.

Signed-off-by: Xavier Aguilar <[email protected]>
Co-authored-by: Cursor <[email protected]>
@github-actions

github-actions Bot commented Nov 5, 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
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu 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: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
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 7510 --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.

@aiter-bot

aiter-bot commented Nov 5, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision 98c734c30daa · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

On gfx942, `sparse_mla_fwd` used to raise `ValueError` for the `fp8_dsv32_mla` cache. It now dequantizes that cache in its native fnuz and runs bf16 dots. fp8 q, `fp8_scalar` and fp8 dots are still rejected on gfx942, and nothing changes on gfx950. Before, gfx942 users of this layout could only fall back to a bf16 cache at 1.62x the memory, even though the dequant path needed only the arch's fp8 decode.

Validation and unverified scope

On 8x MI325X (gfx942), ROCm 10.0, Triton 3.8.0:

```bash
pytest op_tests/triton_tests/attention/test_sparse_mla.py
```

- **Unit tests:** 47 passed, 97 skipped (the gfx950-only fp8 cases), 0 failed. `ruff` 0.16.0 and `black` are clean.
- **Negative control:** with only the `_fp8_to_f32` change reverted, all three `test_ds_mla_format` cases fail with NaN output.
- **End to end:** I tested the same change on the aiter of a Kimi-K3.1 vLLM ROCm image, together with the vLLM gate change: Kimi-K3.1-Pro, TP8, int4 MoE, the `fp8_ds_mla` cache against bf16. Passkey retrieval inserts one key into filler text and asks for it back, at depths of 10%, 50% and 90%.

| KV cache   | KV tokens | GSM8K (250, zero-shot) | Passkey 4k / 17k / 70k / 131k |
| ---------- | --------- | ---------------------- | ----------------------------- |
| fp8_ds_mla | 1,482,843 | 0.984                  | 3/3 at each length            |
| bfloat16   | 914,136   | 0.980                  | 3/3 at each length            |

Both caches gave the same GSM8K answer on 249 of 250 questions.

With the `fp8_ds_mla` cache and a production serving config (`--max-model-len 135168`, full and piecewise CUDA graphs), lm-eval 0.4.13 through the completions API gives:
- **GSM8K, 20-shot, all 1,319 questions:** 0.9735 ± 0.0044, the same for strict and flexible extraction.
- **RULER NIAH, all 8 tasks:** 1.0 at every length from 4k to 128k tokens (4k, 8k, 16k, 32k, 64k and 128k). That is 100 to 10 samples per task depending on length, 2,000 in total.

Unverified:
- gfx950 and gfx942 in CI: Triton Tests (MI35X) and Triton Tests (MI300X, `ci:triton-300x`) ran the selected tests, `test_sparse_mla.py` included, and passed. On gfx950 that covers the fp8 cases that skip on gfx942.
- gfx950 machine code: I compiled every `_sparse_mla` and `_sparse_mla_fp8` variant that `test_sparse_mla.py`, `test_pa_decode_sparse.py` and `test_mla_v4_triton.py` build for gfx950 (`TRITON_OVERRIDE_ARCH=gfx950`), on this PR's base and head. The AMDGCN is identical for all 186 variants compiled in both runs.
- MI250X (gfx90a) is not in `SUPPORTED_ARCHS`.
- The end-to-end runs used the image's aiter, which is an older revision than this PR's base, with the same `_fp8_to_f32` decode and `_check_fp8_arch` gate applied. The unit tests and the benchmark ran this branch's `aiter/ops/triton` tree.

PR-specific question

Before this PR, gfx942 can fail to read `fp8_dsv32_mla` in two ways. The wrapper's `_check_fp8_arch` raises a `ValueError` that names `fnuz`. If only that gate is relaxed, the kernel still decodes the bytes as OCP and returns NaN.

- **`test_ds_mla_format[topk2048]`, `[h12_lse]`, `[prefill_lse]`:**
  - On the old code, each case raises the `fnuz` `ValueError`.
  - With the gate relaxed but `_fp8_to_f32` still reading OCP, all three fail on NaN output (the negative control above).
  - They are the only tests that run the kernel on `fp8_dsv32_mla`. `test_sparse_mla`, `test_sparse_mla_rope_free`, `test_return_lse` and `test_global_load_path` parametrize over `bf16` and `tensor` only, and `test_sparse_mla_dsv4_train.py` uses a bf16 cache.
  - Before this PR, `test_ds_mla_format` ran a single decode shape and skipped on gfx942. `[h12_lse]` and `[prefill_lse]` add checks that no existing test makes for this cache: the LSE output, a 12-head launch (the only non-power-of-two head count in the file) and the prefill launch config.
- **`test_fp8_arch_gate`:** the bf16-q `fp8_dsv32_mla` case now expects gfx942 to accept the input. It fails on the old code, where `_check_fp8_arch("gfx942", "fp8_dsv32_mla", torch.bfloat16)` raises. The new fp8-q `fp8_dsv32_mla` case passes both before and after. It guards against relaxing the gate too far, since gfx942 must still reject fp8 q with this cache.
- **`test_native_fp8_cache_rejected[dsmla]`:** it asserted the old rejection, so on the new code it would fail. It now skips on gfx942. `[tensor]` still checks that the per-tensor fp8 cache is rejected there.

Changed op tests

`op_tests/triton_tests/attention/test_sparse_mla.py`:
- `test_ds_mla_format` used to skip on gfx942 and now runs there. It is parametrized over decode at top-k 2048, 12 heads with LSE (Kimi-K3.1's 96 heads at TP8, a non-power-of-two head count), and a 2048-query prefill shape with LSE, which runs gfx942's prefill launch config. The cache is packed and decoded in the arch-native fp8 (`get_fp8_e4m3_dtype()`), as a gfx942 producer writes it. No other test reads `fp8_dsv32_mla` on gfx942.
- `test_fp8_arch_gate` now expects gfx942 to accept bf16 q with `fp8_dsv32_mla`, and has a new case for fp8 q with `fp8_dsv32_mla`, which must still be rejected there. The `fp8_scalar` and fp8-q cases keep the `fnuz` error.
- `test_native_fp8_cache_rejected[dsmla]` skips on gfx942, which now reads that cache. `[tensor]` still checks the rejection.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • WAIT — Black: missing
  • WAIT — Ruff: missing
  • WAIT — Repository dependency: missing
  • PASS — Aiter Test Gate: passed
  • Required CI is incomplete; this PR is not ready for human review.

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

@xaguilar-amd
xaguilar-amd marked this pull request as ready for review November 5, 2026 13:53
@xaguilar-amd
xaguilar-amd requested a review from a team November 5, 2026 13:53
@azaidy
azaidy self-requested a review November 5, 2026 14:04
@azaidy azaidy self-assigned this Nov 5, 2026
@azaidy
azaidy requested a balanced review from Copilot November 5, 2026 14:31

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

Runtime validation is still needed for the new gfx942 FNUZ path and gfx950 regressions, since gfx942 results are author-reported and gfx950 was not rerun.

No open issues 🎉

What changed in this PR

This PR enables sparse_mla_fwd to read fp8_dsv32_mla KV caches on gfx942 using native fnuz decoding, with bf16 queries and dot products. Other fp8 inputs remain gfx950-only.

Changes:

  • Add compile-time fnuz decoding for scaled cache bytes on gfx942.
  • Update architecture checks, capability metadata, error messages, and docstrings.
  • Extend cache correctness tests to cover gfx942, 12-head decoding, prefill, and LSE output.
File Description
op_tests/​triton_tests/​attention/​test_sparse_mla.py Enable gfx942 cache tests and expand correctness and architecture-gate coverage.
aiter/​ops/​triton/​attention/​sparse_mla.py Allow the fnuz cache on gfx942 and document its restrictions.
aiter/​ops/​triton/​_gluon_kernels/​gfx950/​attention/​sparse_mla.py Select native fnuz decoding on CDNA3 while preserving OCP decoding elsewhere.

Review effort: Balanced

@xaguilar-amd

Copy link
Copy Markdown
Contributor Author

CI now covers both points. Triton Tests (MI35X) ran the selected tests on gfx950, and Triton Tests (MI300X) ran them on gfx942 (ci:triton-300x). test_sparse_mla.py was included in both, and every shard passed.

As a further gfx950 check, I compiled every _sparse_mla and _sparse_mla_fp8 variant those tests build for gfx950, on this PR's base and head. The AMDGCN is identical for all 186 variants, because is_hip_cdna3() removes the fnuz branch at compile time on gfx950.

@xaguilar-amd

Copy link
Copy Markdown
Contributor Author

@azaidy we need this to have Kimi-K3.1 enabled on gfx942, so it would be good if we can have it ready by the next Aiter cut.

@maeehart

Copy link
Copy Markdown
Contributor

@azaidy @vgokhale could one of you review this? The internal review on our side is done, the four required checks are green, and there are no open threads. It unblocks the fp8 KV cache for Kimi-K3.1 on gfx942, and we would like it in next week's AITER release.

@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!

@azaidy
azaidy merged commit 8e96f31 into ROCm:main Nov 16, 2026
phambinhfin added a commit to jin-amd/aiter that referenced this pull request Nov 17, 2026
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.
xaguilar-amd added a commit to xaguilar-amd/vllm that referenced this pull request Nov 19, 2026
Accept fp8_ds_mla on gfx942 and gfx950 unconditionally, assuming an AITER
that includes ROCm/aiter#7510. Replace the probe's unit tests with
fp8_ds_mla cases in the ROCm sparse backend correctness test, which run
ROCMAiterMLASparseImpl end to end against an SDPA reference.

Signed-off-by: Xavier Aguilar <[email protected]>
Co-authored-by: Cursor <[email protected]>
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.

5 participants