Skip to content

[ASM] [HIP] MHA v4: hd256 block-sparse and Sol-Attn on gfx950 - #8684

Open
nsakkine wants to merge 19 commits into
nsakkine/sol-attn-triton-hdim_256from
nsakkine/mha_v4-sparse-hdim_256
Open

nsakkine wants to merge 19 commits into
nsakkine/sol-attn-triton-hdim_256from
nsakkine/mha_v4-sparse-hdim_256

Conversation

@nsakkine

@nsakkine nsakkine commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Stacked on #8683 , which adds the hd256 pooled K/V packing, tilt planes and Jensen cap these kernels consume. Review that PR first; this diff contains only the HIP/ASM side.

Head dimension 256 was dense-only in MHA v4. This adds 256x64 block-sparse and Sol-Attn kernels for hd256 on gfx950, for four recipes: BF16, MXFP8, MXFP6 and MXFP4. Sol-Attn at hd256 supports sorted dispatch, the Jensen variance term and the value tilt (sol_tilt), like the hd128 rows. Models with 256-wide heads, such as Ideogram-4, can now use sparse and Sol attention.

What's added

  • Kernels: 8 new code objects in hsa/gfx950/fmha_v4_fwd/, fwd_hd256_{bf16,mxfp8,mxfp6,mxfp4}_{sparse,sol}_256x64.co, and their rows in fmha_v4_fwd.csv.
  • Geometry: 256x64 only. There is no KV-range support (kv_range = 0). Any other tile at hd256 is refused before anything is quantized.

Changes

  • aiter/ops/mha_v4.py
    • Drops the hd256 dense-only rejection.
    • The block-tile queries (block_tile, block_tiles, kv_tile_for_q_tile, mha_v4_block_tiles_in_any_precision) take a head dim, matched against the manifest's hdim_q. The _check_block_tile error lists only that head dim's tiles.
    • mha_v4_sol quantizes MXFP4 and MXFP6 at hd256 with the hd256 producers and K views. Its default softmax scale follows the head dim, not 128.
    • hd256 MXFP8 K, mean_k and mean_k_var must be record views, because the K is packed with its scales.
    • The docstring covers the hd256 tilt parameters.
  • csrc/py_itfs_cu/asm_mha_v4_fwd.cu
    • The MXFP6 K record and pooled V-scale size checks use head_dim.
    • The MX-V scale-slack check is limited to the 64x64 objects, because the hd256 readers stay inside the image and the hd256 MXFP6 quantizer allocates no slack.

Also included: MXFP8 64x64 Sol-Attn pooled K scale overread (hd128)

fmha_fwd_hd128_mxfp8_sol_64x64_gfx950 reads its pooled E8M0 K scales past their last 128-row tile. sol_prepare pads them only up to that tile, so the read could fault when the allocation ends at an unmapped page. The overread is up to 1 KB for mean_k_scale and 4 bytes for mean_k_var_scale. mha_v4_packed now copies both into block_scale_storage, which adds MHA_V4_KV_SCALE_LOOKAHEAD_ROWS zeroed rows. This is the same padded storage AITER already uses for its own K scales. The copy runs only for E8M0 FP8 K scales on the 64x64 tile and costs a few KB per call.

Testing (MI355X, gfx950)

Suite Result
op_tests/test_mha_v4_sparse.py 630 ran, 5 skipped, 0 failed
op_tests/test_mha_v4.py 354 ran, 0 failed

New hd256 coverage, per recipe:

  • Block-sparse: with every block selected, the output equals dense. A random LUT matches the fp32 masked reference.
  • Sol-Attn, all exact: with every block exact, the output is the dense row, bit for bit over whole blocks and to rounding over a ragged last block.
  • Sol-Attn, routed: the output matches sol_attn_ref on its own mask, beats keep-or-drop, and is the same launch as mha_v4_sol.
  • Jensen term: it lands at its own weight, not at none or double. Sorted dispatch leaves the output unchanged bit for bit.
  • Tilt: on planted low-rank K/V, the tilt moves the output toward exact attention, and moves nothing under an all-exact selection.
  • Overread fix: a test checks that the scales the kernel receives have mapped, zeroed bytes past the last tile plus the lookahead rows. It fails without the copy.
  • Refusal: the hd128 MXFP8 geometry (256x128) is refused at hd256 before quantizing. This replaces the removed dense-only rejection test.

End to end: xDiT Ideogram-4 (hd256), 2048², 48 steps, 4x MI355X

Self-attention s/image Output
dense aiter 26.13 reference
Sol BF16, every block exact (beta 0) 19.50 same layout as dense
Sol BF16, beta 0.5 18.57 title repeated
Sol BF16, beta ramp 0.0 to 0.5 18.62 same layout as dense, clean
Sol MXFP8, ramp + tilt rank 2 21.64 same layout as dense, clean

Most of the speedup over dense comes from the MHA v4 kernel itself; skipping blocks at beta 0.5 adds about 0.9 s. A constant beta of 0.5 can repeat or ghost lettering on Ideogram; a beta ramp or the tilt avoids it.

PR Self-Review

Reviewed revision

dda605ec5315

Behavior and intent

MHA v4 at head dimension 256 was dense-only. Block-sparse and Sol-Attn calls at hd256 were refused: _check_head_dim raised "head dimension 256 is dense-only" in mha_v4(block_mask=...) and in mha_v4_packed, which mha_v4_sol launches through. So models with 256-wide heads could not use sparse attention at all.

This PR adds gfx950 hd256 objects for BF16, MXFP8, MXFP6 and MXFP4, each as a block-sparse row and a Sol-Attn row (eight rows, all 256x64), and routes the Python entry points to them:

  • Manifest lookup keyed by head dim. mha_v4_block_tile, mha_v4_kv_tile_for_q_tile, mha_v4_block_tiles, mha_v4_ragged_kv and _check_block_tile take a head_dim, which defaults to 128 so hd128 callers are unchanged. The lookup has to know the head dim because hd256 runs its own tile: MXFP8 is 256x128 at hd128 and 256x64 at hd256.
  • Producers per head dim. mha_v4(block_mask=...) and mha_v4_sol take the hd256 quantizers and K views (mha_v4_mx_producers, _MXFP6_K_VIEWS), and the softmax scale defaults to head_dim**-0.5 instead of a hard-coded 128**-0.5. The hd256 MXFP8 Sol-Attn row is reached through mha_v4_packed, as hd128 MXFP8 is.
  • Record checks per head dim. check_mxfp6_k_record_storage in asm_mha_v4_fwd.cu checks hd256's 64-token, 13312-byte MXFP6 K records as well as hd128's 128-token, 17408-byte ones. The mean_v_scale size check scales with head dim. _check_mxfp8_hd256_records now covers mean_k and mean_k_var as well as K.
  • V-scale slack check narrowed. The MX V-scale slack check applies only to the 64x64 objects, which gather V scales through a raw pointer. The hd256 256x64 objects bound that gather with a buffer descriptor, like every 256-row object.

hd128 behavior is unchanged.

Validation and unverified scope

On one MI355X (gfx950) with torch 2.13.0 and Triton 3.8.0, at 787e83551cea. The module_mha_v4_quant and module_fmha_v4_fwd JIT modules were rebuilt from this revision's sources. Results:

  • python op_tests/test_mha_v4_sparse.py checks: 647 ran, 0 failed, 5 skipped.
  • The nine hd256 test functions on their own: 34 checks, 0 failed, 0 skipped. That includes test_mha_v4_head_dim_256_reads_stop_at_each_image, which needs HIP virtual memory management and ran.
  • python op_tests/test_mha_v4.py checks: 444 ran, 0 failed, 1 skipped.
  • python -m pytest -q op_tests/triton_tests/attention/test_sol_prepare.py op_tests/triton_tests/attention/test_sol_tilt.py (the base PR's tests, on this branch): 178 passed, 2 skipped.

Unverified:

  • Other architectures. On gfx942 and gfx1250, the refusal of hd256 sparse and Sol-Attn has not been run. There are no rows there, so _check_block_tile should raise NotImplementedError, but that was not run on those GPUs.
  • Performance. The hd256 kernels were not benchmarked in this run.
  • End-to-end model runs at this revision.

PR-specific question

Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?

  • Architecture: gfx950 only. The eight rows are in hsa/gfx950/fmha_v4_fwd/fmha_v4_fwd.csv alone. Elsewhere, mha_v4_block_tiles(operands, mode, head_dim=256) is empty, so _check_block_tile raises NotImplementedError ("has no head-dim 256 row") before anything is quantized. That matters because an MX quantizer aborts rather than raises on an arch without the row.

  • Dtypes. The rows exist for:

    • BF16 Q/K/V;
    • MXFP8 Q/K (E8M0 1x32 scales) with a per-tensor FP8 V;
    • MXFP6 Q/K/V and MXFP4 Q/K/V, both with an FP6-P V.

    _check_head_dim admits only these (Q/K, V) pairs at hd256, plus FP8 Q/K under E8M0 scales only; per-tensor FP8, i8fp8 and mixed recipes such as f8f6 are refused. A pair it admits but that has no row in a mode still fails _check_block_tile for that mode and head dim.

  • Shapes.

    • Q and V head dim are both 256, and the geometry is 256x64 only.
    • The rows are non-causal, take a ragged last KV block, support LSE, sorted dispatch and, for Sol-Attn, the Jensen term and the tilt.
    • They have no kv_range, so kv_range_tokens != 0 fails the launcher's cfg.kv_range check.
    • Because the geometry lookup is keyed by head dim, an hd128 tile at hd256 (MXFP8's 256x128) is refused with a ValueError listing the hd256 tiles, instead of matching a row of the wrong head dim.
  • Operand layout. These invariants keep a well-shaped but wrongly laid-out tensor from reaching the kernels:

    • An MXFP6 K, mean_k or mean_k_var must be a view of whole records of the layout for its head dim, backed through the packer's zeroed slack, and any head dim other than 128 or 256 is refused (check_mxfp6_k_record_storage).
    • An hd256 MXFP8 K, mean_k or mean_k_var must have the record strides of mxfp8_k_view_hd256 (_check_mxfp8_hd256_records). A natural BSHD tensor would otherwise run with its scales unread.
    • mean_v_scale must hold 4 * head_dim bytes per 128 pooled rows.
    • test_mha_v4_head_dim_256_reads_stop_at_each_image places each tensor's last byte at the end of a mapping, so a read past any image faults.

Changed op tests

  • op_tests/test_mha_v4_sparse.py adds the hd256 coverage. Each case runs only where a manifest row exists:

    • test_mha_v4_sparse_head_dim_256_follows_the_lut (BF16, MXFP8, MXFP6, MXFP4): all-selected matches the dense row bit for bit, and a random LUT matches the fp32 reference over exactly the selected blocks. The LUT has empty, one-block and two-block rows, a ragged last block, a partial query tile and GQA.
    • test_mha_v4_sol_head_dim_256_reduces_to_dense_and_meets_the_oracle: all-exact is the dense row, and the routed row meets sol_attn_ref on its own mask and beats keep-or-drop. mha_v4_sol is the same launch, for every recipe but MXFP8, which it cannot reach.
    • ..._jensen_term_is_the_block_k_variance and ..._reads_the_capped_jensen_variance: the Jensen term lands at its own weight in K's basis, and sol_jensen_cap's re-packed MXFP6/MXFP8 variance is the one read.
    • ..._tilt_reaches_the_pooled_values and ..._tilt_and_capped_jensen_run_together: the rows read the tilt planes at the right stride, alone and together with the capped Jensen term.
    • ..._packed_compile_parity: sol_prepare and the launch trace as one fullgraph and match eager bitwise.
    • test_mha_v4_head_dim_256_reads_stop_at_each_image: no hd256 row reads past any operand.
    • test_mha_v4_head_dim_256_block_tile_is_its_own: the hd128 MXFP8 geometry is refused at hd256 before quantizing.

    These are not redundant. The existing tests in this file run at head dim 128, and the base PR's test_sol_prepare.py and test_sol_tilt.py check the Triton helpers' tensors without running any kernel, so nothing else runs the hd256 objects.

  • op_tests/test_mha_v4.py removes test_mha_v4_rejects_sparse_head_dim_256, which asserted "head dimension 256 is dense-only". This PR lifts that refusal, so the test would fail. What it guarded is now covered by op_tests/test_mha_v4_sparse.py: the supported hd256 recipes run there, the unsupported geometry is refused by test_mha_v4_head_dim_256_block_tile_is_its_own, and the unsupported dtype pairs remain refused by test_mha_v4_rejects_mixed_mxfp6_head_dim_256 in this file.

nsakkine and others added 6 commits November 25, 2026 10:54
…head rows

The 64x64 MXFP8 Sol-Attn kernel (fmha_fwd_hd128_mxfp8_sol_64x64_gfx950)
reads its pooled E8M0 K scales past their last 128-row tile. sol_prepare
pads those scales only up to that tile, so the read faults whenever the
allocation ends at an unmapped page.

- mean_k_scale, tile mostly padding: reads 4 bytes past the end.
- mean_k_scale, tile full (pooled rows a multiple of 128, so no padding):
  reads 256 to 1024 bytes past the end, 32 to 128 rows into the next tile.
- mean_k_var_scale (Jensen term), tile full: reads 4 bytes past the end.

mha_v4_packed now copies both scales into block_scale_storage, which adds
MHA_V4_KV_SCALE_LOOKAHEAD_ROWS zeroed rows, the same padded storage AITER
already uses for its own K scales. The copy runs only for E8M0 FP8 K
scales on the 64x64 tile and costs a few KB per call.

The new test checks that the scales the kernel receives match the
prepared ones and have mapped, zeroed bytes past their last tile plus
the lookahead rows. It fails without the copy.

Signed-off-by: Niko Säkkinen <[email protected]>
…, MXFP4)

Adds 256x64 manifest rows for head dim 256: block-sparse, and Sol-Attn with sorted
dispatch and the Jensen variance term. No KV-range support (kv_range = 0). The .co
objects are not part of this commit.

- mha_v4.py: drop the hd256 dense-only rejection. The block-tile queries take a
  head dim, matched against the manifest's hdim_q. hd256 MXFP8 K, mean_k and
  mean_k_var must be record views.
- asm_mha_v4_fwd.cu: the MXFP6 K record and pooled V-scale size checks use
  head_dim. The MX-V scale slack check is limited to the 64x64 objects.
- test_mha_v4_sparse: hd256 tests per recipe. All-selected equals dense, and a
  random LUT matches the fp32 masked reference.

Signed-off-by: Niko Säkkinen <[email protected]>
Co-authored-by: Cursor <[email protected]>
The hd256 Sol-Attn objects (BF16, MXFP8, MXFP6, MXFP4) now accept sol_tilt.
They take the same parameter tensors as their hd128 rows, except that the
hd256 MXFP8 row's second stride is its V planes', since its K is packed
with its scales.

- fwd_hd256_{bf16,mxfp8,mxfp6,mxfp4}_sol_256x64.co: rebuilt with the tilt.
- mha_v4.py: the docstring covers the hd256 tilt parameters.

Signed-off-by: Niko Säkkinen <[email protected]>
Co-authored-by: Cursor <[email protected]>
…o them

No test launched an hd256 Sol-Attn kernel, so the new rows, the Jensen
term and the value tilt were checked only up to their host-side inputs.
The new tests run them on the kernels for BF16, MXFP8, MXFP6 and MXFP4.

- mha_v4.py: mha_v4_sol quantizes MXFP4 and MXFP6 at head dim 256 with
  the hd256 producers and K views, and its default softmax scale follows
  the head dim instead of 128. mha_v4_block_tiles_in_any_precision takes
  an optional head dim, and the _check_block_tile error passes it, so the
  message lists only that head dim's tiles.
- test_mha_v4_sparse: hd256 Sol-Attn tests per recipe. An all-exact
  selection is the dense row: bit for bit over whole blocks, to rounding
  over a ragged last one. Routed, the row meets sol_attn_ref on its own
  mask, beats keep-or-drop, and is the same launch as mha_v4_sol. The
  Jensen term lands at its own weight rather than at none or double, and
  sorted dispatch leaves it bit for bit. On planted low-rank K/V the tilt
  moves the output toward exact attention, and under an all-exact
  selection it moves nothing. A new check refuses the hd128 MXFP8 geometry
  (256x128) at head dim 256 before anything is quantized, in place of the
  removed dense-only rejection.
- black over the hd256 changes in mha_v4.py and test_mha_v4_sparse.py.

Signed-off-by: Niko Säkkinen <[email protected]>
Co-authored-by: Cursor <[email protected]>
sol_tilt_planes takes q_abs_max in its K's basis, which for a packed K
is the unrotated BF16 source. The test passed rotated maxima. The
result barely changes; the test now matches the contract.

Signed-off-by: Niko Säkkinen <[email protected]>
@nsakkine
nsakkine added this pull request to stack #8685 November 25, 2026 11:07
@nsakkine nsakkine changed the title mha_v4: hd256 block-sparse and Sol-Attn on gfx950 (BF16, MXFP8, MXFP6, MXFP4) MHA v4: hd256 block-sparse and Sol-Attn on gfx950 Nov 25, 2026
@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 8684 --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.

@jcaraban jcaraban 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.

Thanks Niko! I read this together with #8683. That was code reading plus a trial merge with current main; I haven't run anything on a GPU.

Passing the head dim through the manifest-driven tile lookup is a nice cleanup. The hd256 Sol tests are a solid set: all-exact equals dense, the oracle bound, Jensen at its own weight, and the tilt moving toward exact attention. Two things need attention before this lands, I think:

  1. The first commit (7bdf5b4) is the same change as #8196; git range-diff shows it identical to that PR's head. So the points from my #8196 review (#8196 (review)) apply here unchanged, including the tilt case that faults. See the inline note on _backed_pooled_k_scale.
  2. A merge with current main breaks THD: main's _mha_v4_thd still calls _check_head_dim with the sparse argument this PR removes. Details inline.

Smaller ones:

  • The CSV conflict with main is only main's new pair_split column, so the 8 new rows need a ,0 before knl_name.
  • mha_v4_kv_tile, mha_v4_block_tile and mha_v4_kv_tile_for_q_tile default head_dim to 128, while the new docstring says the head dim "is not a filter that may be left out". Keeping the default for compatibility seems fine, but the docstring could then say that leaving it out means head dim 128.

Comment thread aiter/ops/mha_v4.py Resolved
Comment thread aiter/ops/mha_v4.py Resolved
Comment thread csrc/py_itfs_cu/asm_mha_v4_fwd.cu Resolved
Comment thread csrc/py_itfs_cu/asm_mha_v4_fwd.cu Resolved
Comment thread op_tests/test_mha_v4_sparse.py Resolved
The hd256 Jensen test took mean_k_var straight from sol_prepare, so no
hd256 launch read a capped variance, and for MXFP6 and MXFP8 that variance
is a new pack with its scales inside the records. The new check alternates
narrow and wide K blocks so about half are capped, launches the four hd256
rows with the capped pair, and checks the result against the reference at
each block's own gain: it has to beat the uncapped reference by over 0.02
in cosine, with the LSE within 0.15.

Signed-off-by: Niko Säkkinen <[email protected]>
Place each operand of every hd256 Sol row at the end of a HIP VMM
mapping, so any read past its image faults. The MXFP4 K scales keep
their 4-byte producer slack. All rows run in one child process.

Signed-off-by: Niko Säkkinen <[email protected]>
…-sparse-hdim_256

# Conflicts:
#	aiter/ops/mha_v4.py
#	hsa/gfx950/fmha_v4_fwd/fmha_v4_fwd.csv
Under sol_tilt, mean_k_scale is plane 0 of sol_tilt_planes' K scales.
Copying the view dropped planes 1..rank, and those planes now carry
their own lookahead rows. Also say what an omitted head_dim means.
Drop the copy into block_scale_storage and its tests from this PR. No
hd256 row runs at 64x64, so nothing here needs it, and the copy is
being settled in #8196.
The launcher no longer checks the slack behind the hd256 256x64 MX-V
scales. Place every tensor of the hd256 block-sparse rows at the end
of a mapping too, as for the Sol rows, so a V-scale read past the
image faults.
… and under torch.compile

Signed-off-by: Niko Säkkinen <[email protected]>
@nsakkine
nsakkine marked this pull request as ready for review November 27, 2026 05:34
@nsakkine
nsakkine requested a review from a team November 27, 2026 05:34
@github-actions github-actions Bot changed the title MHA v4: hd256 block-sparse and Sol-Attn on gfx950 [ASM] [HIP] MHA v4: hd256 block-sparse and Sol-Attn on gfx950 Nov 27, 2026
@aiter-bot

aiter-bot commented Nov 27, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision dda605ec5315 · 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 at head dimension 256 was dense-only. Block-sparse and Sol-Attn calls at hd256 were refused: `_check_head_dim` raised "head dimension 256 is dense-only" in `mha_v4(block_mask=...)` and in `mha_v4_packed`, which `mha_v4_sol` launches through. So models with 256-wide heads could not use sparse attention at all.

This PR adds gfx950 hd256 objects for BF16, MXFP8, MXFP6 and MXFP4, each as a block-sparse row and a Sol-Attn row (eight rows, all 256x64), and routes the Python entry points to them:

- **Manifest lookup keyed by head dim.** `mha_v4_block_tile`, `mha_v4_kv_tile_for_q_tile`, `mha_v4_block_tiles`, `mha_v4_ragged_kv` and `_check_block_tile` take a `head_dim`, which defaults to 128 so hd128 callers are unchanged. The lookup has to know the head dim because hd256 runs its own tile: MXFP8 is 256x128 at hd128 and 256x64 at hd256.
- **Producers per head dim.** `mha_v4(block_mask=...)` and `mha_v4_sol` take the hd256 quantizers and K views (`mha_v4_mx_producers`, `_MXFP6_K_VIEWS`), and the softmax scale defaults to `head_dim**-0.5` instead of a hard-coded `128**-0.5`. The hd256 MXFP8 Sol-Attn row is reached through `mha_v4_packed`, as hd128 MXFP8 is.
- **Record checks per head dim.** `check_mxfp6_k_record_storage` in `asm_mha_v4_fwd.cu` checks hd256's 64-token, 13312-byte MXFP6 K records as well as hd128's 128-token, 17408-byte ones. The `mean_v_scale` size check scales with head dim. `_check_mxfp8_hd256_records` now covers `mean_k` and `mean_k_var` as well as K.
- **V-scale slack check narrowed.** The MX V-scale slack check applies only to the 64x64 objects, which gather V scales through a raw pointer. The hd256 256x64 objects bound that gather with a buffer descriptor, like every 256-row object.

hd128 behavior is unchanged.

Validation and unverified scope

On one MI355X (gfx950) with torch 2.13.0 and Triton 3.8.0, at `787e83551cea`. The `module_mha_v4_quant` and `module_fmha_v4_fwd` JIT modules were rebuilt from this revision's sources. Results:

- **`python op_tests/test_mha_v4_sparse.py` checks:** 647 ran, 0 failed, 5 skipped.
- **The nine hd256 test functions on their own:** 34 checks, 0 failed, 0 skipped. That includes `test_mha_v4_head_dim_256_reads_stop_at_each_image`, which needs HIP virtual memory management and ran.
- **`python op_tests/test_mha_v4.py` checks:** 444 ran, 0 failed, 1 skipped.
- **`python -m pytest -q op_tests/triton_tests/attention/test_sol_prepare.py op_tests/triton_tests/attention/test_sol_tilt.py`** (the base PR's tests, on this branch): 178 passed, 2 skipped.

Unverified:

- **Other architectures.** On gfx942 and gfx1250, the refusal of hd256 sparse and Sol-Attn has not been run. There are no rows there, so `_check_block_tile` should raise `NotImplementedError`, but that was not run on those GPUs.
- **Performance.** The hd256 kernels were not benchmarked in this run.
- **End-to-end model runs** at this revision.

PR-specific question

Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?

- **Architecture: gfx950 only.** The eight rows are in `hsa/gfx950/fmha_v4_fwd/fmha_v4_fwd.csv` alone. Elsewhere, `mha_v4_block_tiles(operands, mode, head_dim=256)` is empty, so `_check_block_tile` raises `NotImplementedError` ("has no <arch> head-dim 256 row") before anything is quantized. That matters because an MX quantizer aborts rather than raises on an arch without the row.
- **Dtypes.** The rows exist for:
  - BF16 Q/K/V;
  - MXFP8 Q/K (E8M0 1x32 scales) with a per-tensor FP8 V;
  - MXFP6 Q/K/V and MXFP4 Q/K/V, both with an FP6-P V.

  `_check_head_dim` admits only these (Q/K, V) pairs at hd256, plus FP8 Q/K under E8M0 scales only; per-tensor FP8, i8fp8 and mixed recipes such as f8f6 are refused. A pair it admits but that has no row in a mode still fails `_check_block_tile` for that mode and head dim.
- **Shapes.**
  - Q and V head dim are both 256, and the geometry is 256x64 only.
  - The rows are non-causal, take a ragged last KV block, support LSE, sorted dispatch and, for Sol-Attn, the Jensen term and the tilt.
  - They have no `kv_range`, so `kv_range_tokens != 0` fails the launcher's `cfg.kv_range` check.
  - Because the geometry lookup is keyed by head dim, an hd128 tile at hd256 (MXFP8's 256x128) is refused with a `ValueError` listing the hd256 tiles, instead of matching a row of the wrong head dim.
- **Operand layout.** These invariants keep a well-shaped but wrongly laid-out tensor from reaching the kernels:
  - An MXFP6 K, `mean_k` or `mean_k_var` must be a view of whole records of the layout for its head dim, backed through the packer's zeroed slack, and any head dim other than 128 or 256 is refused (`check_mxfp6_k_record_storage`).
  - An hd256 MXFP8 K, `mean_k` or `mean_k_var` must have the record strides of `mxfp8_k_view_hd256` (`_check_mxfp8_hd256_records`). A natural BSHD tensor would otherwise run with its scales unread.
  - `mean_v_scale` must hold 4 * head_dim bytes per 128 pooled rows.
  - `test_mha_v4_head_dim_256_reads_stop_at_each_image` places each tensor's last byte at the end of a mapping, so a read past any image faults.

Changed op tests

- **`op_tests/test_mha_v4_sparse.py`** adds the hd256 coverage. Each case runs only where a manifest row exists:
  - `test_mha_v4_sparse_head_dim_256_follows_the_lut` (BF16, MXFP8, MXFP6, MXFP4): all-selected matches the dense row bit for bit, and a random LUT matches the fp32 reference over exactly the selected blocks. The LUT has empty, one-block and two-block rows, a ragged last block, a partial query tile and GQA.
  - `test_mha_v4_sol_head_dim_256_reduces_to_dense_and_meets_the_oracle`: all-exact is the dense row, and the routed row meets `sol_attn_ref` on its own mask and beats keep-or-drop. `mha_v4_sol` is the same launch, for every recipe but MXFP8, which it cannot reach.
  - `..._jensen_term_is_the_block_k_variance` and `..._reads_the_capped_jensen_variance`: the Jensen term lands at its own weight in K's basis, and `sol_jensen_cap`'s re-packed MXFP6/MXFP8 variance is the one read.
  - `..._tilt_reaches_the_pooled_values` and `..._tilt_and_capped_jensen_run_together`: the rows read the tilt planes at the right stride, alone and together with the capped Jensen term.
  - `..._packed_compile_parity`: `sol_prepare` and the launch trace as one fullgraph and match eager bitwise.
  - `test_mha_v4_head_dim_256_reads_stop_at_each_image`: no hd256 row reads past any operand.
  - `test_mha_v4_head_dim_256_block_tile_is_its_own`: the hd128 MXFP8 geometry is refused at hd256 before quantizing.

  These are not redundant. The existing tests in this file run at head dim 128, and the base PR's `test_sol_prepare.py` and `test_sol_tilt.py` check the Triton helpers' tensors without running any kernel, so nothing else runs the hd256 objects.
- **`op_tests/test_mha_v4.py`** removes `test_mha_v4_rejects_sparse_head_dim_256`, which asserted "head dimension 256 is dense-only". This PR lifts that refusal, so the test would fail. What it guarded is now covered by `op_tests/test_mha_v4_sparse.py`: the supported hd256 recipes run there, the unsupported geometry is refused by `test_mha_v4_head_dim_256_block_tile_is_its_own`, and the unsupported dtype pairs remain refused by `test_mha_v4_rejects_mixed_mxfp6_head_dim_256` in this file.

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
  • PASS — Aiter Test Gate: passed

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

@jcaraban jcaraban 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.

Rechecked 787e835. The _check_head_dim call now supplies the required scale-mode argument, and the added tests cover the capped-Jensen operand, combined tilt/cap path, packed compile parity and mapped-allocation boundaries. I found no new correctness blocker in the source review.

The top-level PR description's 'Also included' section and original test summary still describe a launcher-side scale copy that has been removed; please update them to match the validation-only launcher and the current tests, as the later self-review does. Also coordinate landing/rebasing with #8800/#8801 so both the hd128 backing fix and the hd256 repack/layout checks survive the combined changes.

Validation: the seven CPU source/contract checks across these revisions passed, including the internal call signature and all eight hd256 geometry/object entries. I have not independently reproduced the GPU numerical, compile or boundary-test results; the available test nodes were occupied. This is advisory feedback, not an approval.

This branch has not been deployed

No deployments
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.

3 participants