Repository navigation
[Fix] MHAv4 to reject a missing sparse row before quantizing - #7984
Conversation
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]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
…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]>
NOT READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
Problem
On gfx942,
test_mha_v4_sparse.pyaborted 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 insidemha_v4_packed(). On an arch with no row for the recipe, the MX quantizers reach anAITER_CHECKand abort instead of raising, because the pybind path never setsg_aiter_can_throw. gfx942 ships no mode-2 rows, so an allowlisted MXFP4 recipe there crashed and never raisedNotImplementedError.mha_v4(block_mask=...)had the same gap. It checked its default geometry before quantizing, but skipped the check when the caller passedblock_tile. That path just isn't exercised on gfx942 today.Introduced with the Sol-Attn kernels in #7794.
Changes
aiter/ops/mha_v4.py:mha_v4_packed()moves into a helper,_check_block_tile(). It raisesNotImplementedErrorwhen the arch has no row for the recipe in that mode, andValueErrorwhen it has one at a differentblock_tile.mha_v4(block_mask=...)andmha_v4_sol()call it before any quantizer, whetherblock_tileis the default or passed in.mha_v4_packed()calls the same helper where it checked before, for callers that come to it directly.mha_v4_packed()already used undertorch.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", matchingmha_v4_packed(), instead of "block-sparse".op_tests/test_mha_v4_sparse.py:test_mha_v4_block_mask_without_a_sparse_row_names_the_recipealso calls MXFP4 withblock_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_rowkeeps 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_shaperuns 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()(noblock_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 incsrc/kernels/mha_v4_quant.cu(lines 850 and 1082). TheirAITER_CHECKaborts because the pybind path never setsg_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 andsol_preparecallers. It's left for a follow-up.Testing
Each file run as CI runs it (
python3 <file>), on both architectures.On gfx950:
op_tests/test_mha_v4_sparse.pyop_tests/test_mha_v4.pyOn gfx942:
op_tests/test_mha_v4_sparse.pyop_tests/test_mha_v4.pyThe 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
NotImplementedErrorbefore reaching a quantizer:mha_v4(block_mask=...)withblock_tile=(256, 128)mha_v4_sol()with the default tilemha_v4_sol()withblock_tile=(256, 128)PR Self-Review
Reviewed revision
12284f2
Behavior and intent
mha_v4(block_mask=...)andmha_v4_sol()now check that the arch has a manifest row for the recipe at the requestedblock_tilebefore 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 whenblock_tilewas passed. The row lookup ran later, insidemha_v4_packed().That ordering doesn't work on an arch without the row. The MX quantizers run first, and their
AITER_CHECKcallsstd::abort()instead of raising, because the pybind path never setsg_aiter_can_throw. On gfx942, which has no MX rows, an MXFP4 call killed the process instead of raisingNotImplementedError. That tooktest_mha_v4_sparse.pydown 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 undertorch.compile(fullgraph=True).Validation and unverified scope
Each test file run as CI runs it,
python3 op_tests/<file>:op_tests/test_mha_v4_sparse.pyop_tests/test_mha_v4.pyop_tests/test_mha_v4_sparse.pyop_tests/test_mha_v4.pyThe gfx942 skips are gfx950-only checks. At base (95d2112),
test_mha_v4_sparse.pyaborts on gfx942 with SIGABRT (exit 134) atcsrc/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 throughmha_v4(block_mask=...)andmha_v4_sol()at the default tile and at 256x128, 256x64 and 64x64. Everyblock_maskand Sol-Attn call returned or raised a Python error.Unverified or out of scope:
mha_v4()withoutblock_maskstill 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 viaAiterThrowGuard, which would also cover direct quantizer andsol_preparecallers. That's left for a follow-up.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 andblock_tile=(256, 128): before this PR, aborts with SIGABRT atmha_v4_quant.cu:850. An explicitblock_tileskipped the pre-quantization check.mha_v4_sol()with MXFP4/MXFP4/MXFP4, default tile andblock_tile=(256, 128): before this PR, both abort the same way. MXFP4 passes the Sol-Attn recipe allowlist, and nothing checked the manifest beforequantize_mxfp4_q.test_sol_prepare_k_shift_needs_a_packed_k_of_its_shape: before this PR, it aborts at the same line insidequantize_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_rowused 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_recipeused the other arch's FP8 at the default tile, which hits the default-tile check. No test passed an explicitblock_tileto a recipe without a row.Changed op tests
op_tests/test_mha_v4_sparse.py: the only op test file changed.block_tile.test_sol_prepare_k_shift_needs_a_packed_k_of_its_shapechange only gates an existing check to gfx950, so the file no longer aborts on gfx942.