Skip to content

[Triton/Gluon] [Fix] Sol-Attn: back pooled E8M0 K scales with lookahead rows - #8800

Open
nsakkine wants to merge 3 commits into
mainfrom
nsakkine/fix-sol-attn-pooled-k-scale-backing
Open

nsakkine wants to merge 3 commits into
mainfrom
nsakkine/fix-sol-attn-pooled-k-scale-backing

Conversation

@nsakkine

@nsakkine nsakkine commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The 64x64 MXFP8 Sol-Attn kernel (fmha_fwd_hd128_mxfp8_sol_64x64_gfx950) reads its pooled E8M0 K scales, and the Jensen variance's, past their last 128-row tile and into the next tile's rows, as it reads K's own. sol_prepare and sol_jensen_cap padded them only to that tile, and sol_tilt_planes stacks the tilt's K-scale planes behind mean_k_scale with nothing past the last plane. So the read faulted whenever the allocation ended at an unmapped page. The bytes past the end are read but not used, so this is a fault, not a wrong result.

This fixes it where the scales are made, so the tilt and torch.compile paths are covered too. A follow-up PR makes the launch refuse a scale without the backing.

Motivation

Without the backing rows, the kernel reads past the end of the scale allocation and faults on an unmapped page. Padding to the last tile is not enough, because the kernel reads past it. The tilt and torch.compile paths build the scales differently, so the fix goes where the scales are made.

Changes

  • utils.py: _sol_attn_pad_scale_rows copies a pooled scale into block_scale_storage, with MHA_V4_KV_SCALE_LOOKAHEAD_ROWS (256) zeroed rows and the MXFP4 K slack past its last tile. sol_prepare and sol_jensen_cap share it; sol_tilt._backed_scale_copy is removed.
  • sol_tilt.py: _stack_planes takes tail_rows, and the MXFP8 K-scale stack carries the lookahead rows behind its last plane.
  • mha_v4_quant.py, sol_tilt.py: block_scale_storage and _stack_planes view their whole allocation. torch.compile cut a written-through slice down to the slice's own size, which dropped the rows behind it.

Performance (if applicable)

Not applicable. This is a fault fix on scale allocation and makes no performance claim. Not measured.

Testing

  • Unit tests added or updated
  • Performance benchmarks run: not applicable (see above)
  • Tested on MI250X: not run
  • Tested on MI300X: not run (gfx950 only)

Results on MI355X (gfx950):

Suite Result
op_tests/triton_tests/attention/test_sol_tilt.py 95 passed
op_tests/test_mha_v4_sparse.py 609 ran, 5 skipped, 0 failed
op_tests/test_mha_v4.py 357 ran, 0 failed

The MXFP8 K-scale stack test now covers a full last tile too, and checks the zeroed lookahead rows behind the last plane. The follow-up PR's new 64x64 checks pass on this PR alone: tilt at ranks 2 and 8, eager and compiled backing, and each allocation placed against an unmapped page.

Documentation

  • Docstrings updated: _sol_attn_pad_scale_rows in aiter/ops/triton/attention/utils.py
  • User guide updated: not applicable, internal kernel path
  • Performance guide updated: not applicable
  • No documentation change is needed

Dependencies

  • No new third-party dependencies added

Breaking Changes

None.

PR Self-Review

Reviewed revision

f04ed99

Behavior and intent

The pooled E8M0 K scales of the 64x64 MXFP8 Sol-Attn row, and the Jensen variance's, now have MHA_V4_KV_SCALE_LOOKAHEAD_ROWS zeroed rows behind their last tile. sol_prepare, sol_jensen_cap and the tilt's K-scale planes back them where they are made. The kernel reads those rows as it reads K's own. Before this, nothing supplied them, so a read at the end of an allocation on an unmapped page faulted. The bytes past the end are unused, so this fixes a fault, not a wrong result.

Validation and unverified scope

  • MI355X (gfx950), at 5274fbf: op_tests/triton_tests/attention/test_sol_prepare.py 95 passed, including the new 8192-token case. black 26.10.1 and ruff 0.16.0 pass on the changed file.
  • MI355X (gfx950), at 9b6a954, which the new commit does not change: op_tests/triton_tests/attention/test_sol_tilt.py 95 passed.
  • Against the PR's merge-base (5939459) with the new test_sol_prepare.py case: the lookahead assertion fails, for example assert 896 >= (368 * 8).
  • Against main (3486e43) with this PR's test file: test_sol_tilt.py 2 failed, 93 passed. The two failures are the new lookahead assertion for padded-tile and full-tile.
  • Earlier runs, from before the docstring-only commit: test_mha_v4_sparse.py 609 ran, 5 skipped, 0 failed; test_mha_v4.py 357 ran, 0 failed.
  • Not run: gfx942 (MI300X), performance.

PR-specific question

Yes, it fails before this PR. test_tilt_planes_pad_each_mxfp8_k_scale_plane_to_a_whole_scale_tile (padded-tile, full-tile) fails on main at the lookahead assertion. The other 93 tests in test_sol_tilt.py pass on main, so none of them covers those rows. The new test_sol_prepare.py check fails at its lookahead assertion on the merge-base (see Validation).

Changed op tests

  • op_tests/triton_tests/attention/test_sol_tilt.py: test_tilt_planes_pad_each_mxfp8_k_scale_plane_to_a_whole_scale_tile (padded-tile, full-tile) checks that each MXFP8 K-scale plane is zeroed to a whole 128-row tile, and that the lookahead rows behind the last plane are backed and zeroed. It fails on main, and the other 93 tests in the file do not cover these rows.
  • op_tests/triton_tests/attention/test_sol_prepare.py: test_pooled_scales_run_zeroed_to_a_whole_scale_tile (eager and compiled, four sequence lengths) now also requires MHA_V4_KV_SCALE_LOOKAHEAD_ROWS zeroed rows behind both mean_k_scale and mean_k_var_scale, and adds an 8192-token case where the scale fills a whole 128-row tile at kv_tile 64. It is the only K-scale lookahead check on the prepare path. The V-scale slack check in the same file covers a different scale.

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

Rechecked a032997. The split keeps the backing-storage producer fix separate from launcher validation, and I found no new correctness blocker in the source review. The backing allocation, zeroed tail and full-storage as_strided approach address the earlier compiled-storage concern.

One documentation-rule follow-up is inline. Please also coordinate landing with #8683: both PRs change the hd128 final-plane backing, and their sol_jensen_cap changes conflict when combined. Keep the hd256 repack branch, use _sol_attn_pad_scale_rows only for the non-repack branch, and preserve the and not k_packed guard in sol_tilt_planes.

Validation: the seven CPU source/contract checks across these revisions pass. I have not independently rerun the GPU or torch.compile paths; the available test nodes were occupied. This is advisory feedback, not an approval.

Comment thread aiter/ops/triton/attention/utils.py Resolved
@nsakkine
nsakkine marked this pull request as ready for review November 30, 2026 06:58
@nsakkine
nsakkine requested a review from a team November 30, 2026 06:58
@github-actions github-actions Bot changed the title [Fix] Sol-Attn: back pooled E8M0 K scales with lookahead rows [Triton/Gluon] [Fix] Sol-Attn: back pooled E8M0 K scales with lookahead rows Nov 30, 2026
@aiter-bot

aiter-bot commented Nov 30, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision f04ed99c22c4 · 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

The pooled E8M0 K scales of the 64x64 MXFP8 Sol-Attn row, and the Jensen variance's, now have `MHA_V4_KV_SCALE_LOOKAHEAD_ROWS` zeroed rows behind their last tile. `sol_prepare`, `sol_jensen_cap` and the tilt's K-scale planes back them where they are made. The kernel reads those rows as it reads K's own. Before this, nothing supplied them, so a read at the end of an allocation on an unmapped page faulted. The bytes past the end are unused, so this fixes a fault, not a wrong result.

Validation and unverified scope

- MI355X (gfx950), at 5274fbf7b57f: `op_tests/triton_tests/attention/test_sol_prepare.py` 95 passed, including the new 8192-token case. black 26.10.1 and ruff 0.16.0 pass on the changed file.
- MI355X (gfx950), at 9b6a954645a5, which the new commit does not change: `op_tests/triton_tests/attention/test_sol_tilt.py` 95 passed.
- Against the PR's merge-base (593945921f08) with the new `test_sol_prepare.py` case: the lookahead assertion fails, for example `assert 896 >= (368 * 8)`.
- Against main (3486e43ba) with this PR's test file: `test_sol_tilt.py` 2 failed, 93 passed. The two failures are the new lookahead assertion for padded-tile and full-tile.
- Earlier runs, from before the docstring-only commit: `test_mha_v4_sparse.py` 609 ran, 5 skipped, 0 failed; `test_mha_v4.py` 357 ran, 0 failed.
- Not run: gfx942 (MI300X), performance.

PR-specific question

Yes, it fails before this PR. `test_tilt_planes_pad_each_mxfp8_k_scale_plane_to_a_whole_scale_tile` (padded-tile, full-tile) fails on main at the lookahead assertion. The other 93 tests in `test_sol_tilt.py` pass on main, so none of them covers those rows. The new `test_sol_prepare.py` check fails at its lookahead assertion on the merge-base (see Validation).

Changed op tests

- `op_tests/triton_tests/attention/test_sol_tilt.py`: `test_tilt_planes_pad_each_mxfp8_k_scale_plane_to_a_whole_scale_tile` (padded-tile, full-tile) checks that each MXFP8 K-scale plane is zeroed to a whole 128-row tile, and that the lookahead rows behind the last plane are backed and zeroed. It fails on main, and the other 93 tests in the file do not cover these rows.
- `op_tests/triton_tests/attention/test_sol_prepare.py`: `test_pooled_scales_run_zeroed_to_a_whole_scale_tile` (eager and compiled, four sequence lengths) now also requires `MHA_V4_KV_SCALE_LOOKAHEAD_ROWS` zeroed rows behind both `mean_k_scale` and `mean_k_var_scale`, and adds an 8192-token case where the scale fills a whole 128-row tile at `kv_tile` 64. It is the only K-scale lookahead check on the prepare path. The V-scale slack check in the same file covers a different scale.

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.

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.

🟡 Changes recommended

The non-tilt regression test still accepts tile-only backing, leaving zeroed lookahead rows for both scale tensors unchecked in eager and compiled runs, including full final tiles.

1 open issue
What changed in this PR

This PR prevents out-of-allocation reads in gfx950 MXFP8 Sol-Attn by adding backing rows to pooled E8M0 scales, including the Jensen variance and tilt paths.

Changes:

  • Share scale allocation logic that adds zeroed lookahead rows and MXFP4 slack.
  • Add lookahead rows after the final tilt scale plane and preserve full backing allocations under torch.compile.
  • Extend tilt tests to check zeroed lookahead for both partial and full final tiles.
File Description
op_tests/​triton_tests/​attention/​test_sol_tilt.py Checks lookahead backing for partial and full scale tiles.
aiter/​ops/​triton/​attention/​utils.py Adds shared lookahead-backed pooled scale allocation.
aiter/​ops/​triton/​attention/​sol_tilt.py Reuses the shared helper and backs the final tilt scale plane.
aiter/​ops/​mha_v4_quant.py Uses a whole-allocation view to preserve slack under compilation.

Review effort: Balanced

Comment thread aiter/ops/triton/attention/utils.py Resolved
@nsakkine
nsakkine force-pushed the nsakkine/fix-sol-attn-pooled-k-scale-backing branch from 5274fbf to f28d610 Compare November 30, 2026 21:06
@zufayu
zufayu requested review from a team and Boss2002n December 1, 2026 04:42
…hey are made

The 64x64 MXFP8 Sol-Attn kernel (fmha_fwd_hd128_mxfp8_sol_64x64_gfx950)
reads its pooled E8M0 K scales, and the Jensen variance's, past their
last 128-row tile and on into the next tile's rows, as it reads K's own.
sol_prepare and sol_jensen_cap padded them only to that tile, and
sol_tilt_planes stacks the tilt's K-scale planes behind mean_k_scale with
nothing past the last one, so the read faulted whenever the allocation
ended at an unmapped page. The bytes past the end are read but not used.

- utils.py: _sol_attn_pad_scale_rows copies a pooled scale into
  block_scale_storage, with MHA_V4_KV_SCALE_LOOKAHEAD_ROWS zeroed rows and
  the MXFP4 K slack past its last tile. sol_prepare and sol_jensen_cap use
  it, in place of sol_tilt's _backed_scale_copy.
- sol_tilt.py: _stack_planes takes tail_rows, and the MXFP8 K-scale stack
  carries the lookahead rows behind its last plane.
- mha_v4_quant.py, sol_tilt.py: block_scale_storage and _stack_planes view
  their whole allocation. torch.compile cut a slice that is written
  through down to the slice's own size, which dropped the rows behind it.
- test_sol_tilt: the MXFP8 K-scale stack test covers a full last tile too,
  and checks the zeroed lookahead rows behind the last plane.

Signed-off-by: Niko Säkkinen <[email protected]>
Review feedback: the docstring is now two sentences, as the repo's comment
rule asks. The backing-storage explanation stays in the PR description.

Signed-off-by: Niko Säkkinen <[email protected]>
test_pooled_scales_run_zeroed_to_a_whole_scale_tile now requires MHA_V4_KV_SCALE_LOOKAHEAD_ROWS zeroed rows behind both mean_k_scale and mean_k_var_scale, eager and compiled. It also covers an 8192-token K, where the scale fills a whole 128-row tile at kv_tile 64.

Signed-off-by: Niko Säkkinen <[email protected]>
@nsakkine
nsakkine force-pushed the nsakkine/fix-sol-attn-pooled-k-scale-backing branch from f28d610 to f04ed99 Compare December 1, 2026 05:47

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.

5 participants