Skip to content

[Fix] MHAv4 to reject a missing sparse row before quantizing - #7984

Merged
zufayu merged 2 commits into
mainfrom
nsakkine/fix-gfx942-test-error
Nov 16, 2026
Merged

zufayu merged 2 commits into
mainfrom
nsakkine/fix-gfx942-test-error

Conversation

@nsakkine

@nsakkine nsakkine commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

On gfx942, test_mha_v4_sparse.py aborted the whole process. mha_v4_sol() checked only that the formats named a Sol-Attn recipe, then quantized, and the mode-2 manifest lookup ran later inside mha_v4_packed(). On an arch with no row for the recipe, the MX quantizers reach an AITER_CHECK and abort instead of raising, because the pybind path never sets g_aiter_can_throw. gfx942 ships no mode-2 rows, so an allowlisted MXFP4 recipe there crashed and never raised NotImplementedError.

mha_v4(block_mask=...) had the same gap. It checked its default geometry before quantizing, but skipped the check when the caller passed block_tile. That path just isn't exercised on gfx942 today.

Introduced with the Sol-Attn kernels in #7794.

Changes

  • aiter/ops/mha_v4.py:
    • The row and geometry check from mha_v4_packed() moves into a helper, _check_block_tile(). It raises NotImplementedError when the arch has no row for the recipe in that mode, and ValueError when it has one at a different block_tile.
    • mha_v4(block_mask=...) and mha_v4_sol() call it before any quantizer, whether block_tile is the default or passed in. mha_v4_packed() calls the same helper where it checked before, for callers that come to it directly.
    • A valid geometry only triggers the guarded scalar manifest lookup mha_v4_packed() already used under torch.compile(fullgraph=True). The untraceable lookup runs only when building an error message.
    • mha_v4's missing-row error now says "sorted-sparse MHA v4 has no ... row", matching mha_v4_packed(), instead of "block-sparse".
  • op_tests/test_mha_v4_sparse.py:
    • test_mha_v4_block_mask_without_a_sparse_row_names_the_recipe also calls MXFP4 with block_tile=(256, 128) and a mask shaped for it, wherever the manifest has no MXFP4 sparse row.
    • test_mha_v4_sol_rejects_recipes_without_a_manifest_row keeps its unknown-recipe case (MXFP4 Q/K with FP8 V). It also calls MXFP4/MXFP4/MXFP4 with the default and an explicit tile, wherever the manifest has no MXFP4 mode-2 row.
    • test_sol_prepare_k_shift_needs_a_packed_k_of_its_shape runs its MXFP6 K check on gfx950 only. That quantizer aborts on gfx942 the same way.

The new MXFP4 cases skip on gfx950, which has those rows, and run on gfx942.

Not in scope

Dense mha_v4() (no block_mask) still aborts on gfx942 for every MX recipe: MXFP4, MXFP6, f8f6, f6f4 and f6f8. It has no row check before quantizing, so it reaches the gfx950-only MX quantizers in csrc/kernels/mha_v4_quant.cu (lines 850 and 1082). Their AITER_CHECK aborts because the pybind path never sets g_aiter_can_throw. No dense MX check runs on gfx942, so the op_tests don't hit it.

The fix that covers every entry point at once is for those bindings to raise instead of abort, for example by wrapping them in AiterThrowGuard. That would also cover direct quantizer and sol_prepare callers. It's left for a follow-up.

Testing

Each file run as CI runs it (python3 <file>), on both architectures.

On gfx950:

File Ran Skipped Failed
op_tests/test_mha_v4_sparse.py 609 5 0
op_tests/test_mha_v4.py 327 0 0

On gfx942:

File Ran Skipped Failed
op_tests/test_mha_v4_sparse.py 160 454 0
op_tests/test_mha_v4.py 66 261 0

The gfx942 skips are the gfx950-only checks. The sparse file now runs to completion there instead of aborting. The three changed checks also ran on their own on gfx942, all passing. The manifest there has no MXFP4 sparse row and no MXFP4 mode-2 row, so the new MXFP4 cases run rather than skip. Each of these raises NotImplementedError before reaching a quantizer:

  • mha_v4(block_mask=...) with block_tile=(256, 128)
  • mha_v4_sol() with the default tile
  • mha_v4_sol() with block_tile=(256, 128)

PR Self-Review

Reviewed revision

12284f2

Behavior and intent

mha_v4(block_mask=...) and mha_v4_sol() now check that the arch has a manifest row for the recipe at the requested block_tile before quantizing. Before, mha_v4_sol() checked only that the formats named a Sol-Attn recipe. mha_v4(block_mask=...) checked only its default geometry and skipped the check when block_tile was passed. The row lookup ran later, inside mha_v4_packed().

That ordering doesn't work on an arch without the row. The MX quantizers run first, and their AITER_CHECK calls std::abort() instead of raising, because the pybind path never sets g_aiter_can_throw. On gfx942, which has no MX rows, an MXFP4 call killed the process instead of raising NotImplementedError. That took test_mha_v4_sparse.py down with it. The check now lives in one helper, _check_block_tile(), shared by all three entry points. Valid calls behave the same as before, and the accepting path stays traceable under torch.compile(fullgraph=True).

Validation and unverified scope

Each test file run as CI runs it, python3 op_tests/<file>:

Arch File Ran Skipped Failed
gfx950 (MI355X) op_tests/test_mha_v4_sparse.py 609 5 0
gfx950 (MI355X) op_tests/test_mha_v4.py 327 0 0
gfx942 (MI300X) op_tests/test_mha_v4_sparse.py 160 454 0
gfx942 (MI300X) op_tests/test_mha_v4.py 66 261 0

The gfx942 skips are gfx950-only checks. At base (95d2112), test_mha_v4_sparse.py aborts on gfx942 with SIGABRT (exit 134) at csrc/kernels/mha_v4_quant.cu:850, "MHA v4 MX quantization requires gfx950".

A gfx942 sweep ran 81 calls, each in its own subprocess so an abort shows up as a signal. It covered 9 recipes: FP8, i8fp8, bf16, bf16fp8, MXFP4, MXFP6, f8f6, f6f4 and f6f8. Each went through dense mha_v4, and through mha_v4(block_mask=...) and mha_v4_sol() at the default tile and at 256x128, 256x64 and 64x64. Every block_mask and Sol-Attn call returned or raised a Python error.

Unverified or out of scope:

  • Dense mha_v4() without block_mask still aborts on gfx942 for all five MX recipes. It has no row check before quantizing, and no dense MX test runs on gfx942. The general fix is for the quantizer bindings to raise instead of abort, for example via AiterThrowGuard, which would also cover direct quantizer and sol_prepare callers. That's left for a follow-up.
  • The new MXFP4 cases skip on gfx950, which has those rows. There, only the unchanged accepting path is exercised.
  • No MI300 CI run yet.

PR-specific question

Each new case was run against base aiter/ops/mha_v4.py (95d2112) on gfx942 (MI300X), each in its own subprocess:

  • mha_v4(block_mask=...) with MXFP4 and block_tile=(256, 128): before this PR, aborts with SIGABRT at mha_v4_quant.cu:850. An explicit block_tile skipped the pre-quantization check.
  • mha_v4_sol() with MXFP4/MXFP4/MXFP4, default tile and block_tile=(256, 128): before this PR, both abort the same way. MXFP4 passes the Sol-Attn recipe allowlist, and nothing checked the manifest before quantize_mxfp4_q.
  • The MXFP6 K check in test_sol_prepare_k_shift_needs_a_packed_k_of_its_shape: before this PR, it aborts at the same line inside quantize_mxfp6_k. It's now gated to gfx950. This change removes an abort and adds no coverage.

On gfx950 the new cases skip, so they can't fail there before or after.

The existing canonical tests didn't cover this because neither reached an MX quantizer on an arch missing the row. test_mha_v4_sol_rejects_recipes_without_a_manifest_row used only MXFP4 Q/K with FP8 V, which the allowlist rejects before any quantizer even at base. test_mha_v4_block_mask_without_a_sparse_row_names_the_recipe used the other arch's FP8 at the default tile, which hits the default-tile check. No test passed an explicit block_tile to a recipe without a row.

Changed op tests

  • op_tests/test_mha_v4_sparse.py: the only op test file changed.
    • The three changed tests cover rejecting a recipe that has no manifest row before quantizing, for both raw sparse entry points, at the default and at an explicit block_tile.
    • They aren't redundant: the existing cases reject before any MX quantizer, so they couldn't catch a missing row check, and the new cases run only where the manifest lacks the row.
    • No new test functions were added. The cases extend the two existing rejection tests, which already own this contract, rather than duplicating their setup.
    • The test_sol_prepare_k_shift_needs_a_packed_k_of_its_shape change only gates an existing check to gfx950, so the file no longer aborts on gfx942.

mha_v4_sol() checked only that the formats named a Sol-Attn recipe, then
quantized, and left the mode-2 manifest lookup to mha_v4_packed(). On an
arch with no row for the recipe, the MX quantizers' AITER_CHECK aborts the
process instead of raising, because the pybind path never sets
g_aiter_can_throw. So on gfx942 MXFP4/MXFP4/MXFP4 crashed rather than
raising NotImplementedError.

- Resolve the row and its geometry before any quantizer runs, with the
  launcher's errors: NotImplementedError when the arch has no row for the
  recipe, ValueError when it has one at a different block_tile.
- test_mha_v4_sol_rejects_recipes_without_a_manifest_row also calls an
  allowlisted MXFP4 recipe wherever the manifest has no mode-2 row for it.
- test_sol_prepare_k_shift_needs_a_packed_k_of_its_shape runs its MXFP6 K
  check on gfx950 only, since that quantizer aborts on gfx942 the same way.

Signed-off-by: Niko Säkkinen <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
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 Radeon R9700 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 7984 --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.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

…ntizing

mha_v4_sol() checked only that the formats named a Sol-Attn recipe, then
quantized, and left the mode-2 manifest lookup to mha_v4_packed().
mha_v4(block_mask=...) checked its default geometry early but not a
block_tile the caller passed. On an arch with no row, the MX quantizers'
AITER_CHECK aborts the process instead of raising, because the pybind path
never sets g_aiter_can_throw. So on gfx942 MXFP4/MXFP4/MXFP4 crashed rather
than raising NotImplementedError.

- Move mha_v4_packed()'s row and geometry check into _check_block_tile()
  and call it from mha_v4(block_mask=...) and mha_v4_sol() before any
  quantizer, for default and explicit block_tile alike: NotImplementedError
  when the arch has no row for the recipe, ValueError when it has one at
  another geometry.
- Tests call MXFP4 through both entry points, with default and explicit
  tiles, wherever the manifest has no row for it.
- test_sol_prepare_k_shift_needs_a_packed_k_of_its_shape runs its MXFP6 K
  check on gfx950 only, since that quantizer aborts on gfx942 the same way.

Signed-off-by: Niko Säkkinen <[email protected]>
@nsakkine nsakkine changed the title [Fix] MHAv4 reject a missing Sol-Attn row before quantizing [Fix] MHAv4 to reject a missing sparse row before quantizing Nov 15, 2026
@nsakkine
nsakkine marked this pull request as ready for review November 15, 2026 13:20
@nsakkine
nsakkine requested a review from a team November 15, 2026 13:20
@aiter-bot

aiter-bot commented Nov 15, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision 12284f2a71d9 · 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

`mha_v4(block_mask=...)` and `mha_v4_sol()` now check that the arch has a manifest row for the recipe at the requested `block_tile` before quantizing. Before, `mha_v4_sol()` checked only that the formats named a Sol-Attn recipe. `mha_v4(block_mask=...)` checked only its default geometry and skipped the check when `block_tile` was passed. The row lookup ran later, inside `mha_v4_packed()`.

That ordering doesn't work on an arch without the row. The MX quantizers run first, and their `AITER_CHECK` calls `std::abort()` instead of raising, because the pybind path never sets `g_aiter_can_throw`. On gfx942, which has no MX rows, an MXFP4 call killed the process instead of raising `NotImplementedError`. That took `test_mha_v4_sparse.py` down with it. The check now lives in one helper, `_check_block_tile()`, shared by all three entry points. Valid calls behave the same as before, and the accepting path stays traceable under `torch.compile(fullgraph=True)`.

Validation and unverified scope

Each test file run as CI runs it, `python3 op_tests/<file>`:

| Arch | File | Ran | Skipped | Failed |
|---|---|---|---|---|
| gfx950 (MI355X) | `op_tests/test_mha_v4_sparse.py` | 609 | 5 | 0 |
| gfx950 (MI355X) | `op_tests/test_mha_v4.py` | 327 | 0 | 0 |
| gfx942 (MI300X) | `op_tests/test_mha_v4_sparse.py` | 160 | 454 | 0 |
| gfx942 (MI300X) | `op_tests/test_mha_v4.py` | 66 | 261 | 0 |

The gfx942 skips are gfx950-only checks. At base (95d211284), `test_mha_v4_sparse.py` aborts on gfx942 with SIGABRT (exit 134) at `csrc/kernels/mha_v4_quant.cu:850`, "MHA v4 MX quantization requires gfx950".

A gfx942 sweep ran 81 calls, each in its own subprocess so an abort shows up as a signal. It covered 9 recipes: FP8, i8fp8, bf16, bf16fp8, MXFP4, MXFP6, f8f6, f6f4 and f6f8. Each went through dense `mha_v4`, and through `mha_v4(block_mask=...)` and `mha_v4_sol()` at the default tile and at 256x128, 256x64 and 64x64. Every `block_mask` and Sol-Attn call returned or raised a Python error.

Unverified or out of scope:
- Dense `mha_v4()` without `block_mask` still aborts on gfx942 for all five MX recipes. It has no row check before quantizing, and no dense MX test runs on gfx942. The general fix is for the quantizer bindings to raise instead of abort, for example via `AiterThrowGuard`, which would also cover direct quantizer and `sol_prepare` callers. That's left for a follow-up.
- The new MXFP4 cases skip on gfx950, which has those rows. There, only the unchanged accepting path is exercised.
- No MI300 CI run yet.

PR-specific question

Each new case was run against base `aiter/ops/mha_v4.py` (95d211284) on gfx942 (MI300X), each in its own subprocess:

- **`mha_v4(block_mask=...)` with MXFP4 and `block_tile=(256, 128)`:** before this PR, aborts with SIGABRT at `mha_v4_quant.cu:850`. An explicit `block_tile` skipped the pre-quantization check.
- **`mha_v4_sol()` with MXFP4/MXFP4/MXFP4, default tile and `block_tile=(256, 128)`:** before this PR, both abort the same way. MXFP4 passes the Sol-Attn recipe allowlist, and nothing checked the manifest before `quantize_mxfp4_q`.
- **The MXFP6 K check in `test_sol_prepare_k_shift_needs_a_packed_k_of_its_shape`:** before this PR, it aborts at the same line inside `quantize_mxfp6_k`. It's now gated to gfx950. This change removes an abort and adds no coverage.

On gfx950 the new cases skip, so they can't fail there before or after.

The existing canonical tests didn't cover this because neither reached an MX quantizer on an arch missing the row. `test_mha_v4_sol_rejects_recipes_without_a_manifest_row` used only MXFP4 Q/K with FP8 V, which the allowlist rejects before any quantizer even at base. `test_mha_v4_block_mask_without_a_sparse_row_names_the_recipe` used the other arch's FP8 at the default tile, which hits the default-tile check. No test passed an explicit `block_tile` to a recipe without a row.

Changed op tests

- `op_tests/test_mha_v4_sparse.py`: the only op test file changed.
  - The three changed tests cover rejecting a recipe that has no manifest row before quantizing, for both raw sparse entry points, at the default and at an explicit `block_tile`.
  - They aren't redundant: the existing cases reject before any MX quantizer, so they couldn't catch a missing row check, and the new cases run only where the manifest lacks the row.
  - No new test functions were added. The cases extend the two existing rejection tests, which already own this contract, rather than duplicating their setup.
  - The `test_sol_prepare_k_shift_needs_a_packed_k_of_its_shape` change only gates an existing check to gfx950, so the file no longer aborts on gfx942.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • FAIL — Aiter Test Gate: failed
  • Required CI failed; fix it before requesting 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.

@zufayu zufayu added the ci:mi300x Run MI300X standard and OPUS CI on PRs label Nov 16, 2026
@zufayu
zufayu requested a review from minmengdie November 16, 2026 01:35
@zufayu
zufayu requested a review from JohnNikolay84 November 16, 2026 09:13
@zufayu zufayu assigned JohnNikolay84 and unassigned minmengdie Nov 16, 2026
@zufayu
zufayu removed the request for review from minmengdie November 16, 2026 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:mi300x Run MI300X standard and OPUS CI on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants