Skip to content

[HIP] [Fix] MHAv4: refuse pooled K scales in 64x64 MXFP8 Sol-Attn - #8801

Open
nsakkine wants to merge 1 commit into
nsakkine/fix-sol-attn-pooled-k-scale-backingfrom
nsakkine/fix-mha_v4-mxfp8-k_scale-invalid-read
Open

nsakkine wants to merge 1 commit into
nsakkine/fix-sol-attn-pooled-k-scale-backingfrom
nsakkine/fix-mha_v4-mxfp8-k_scale-invalid-read

Conversation

@nsakkine

@nsakkine nsakkine commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #8800, which backs the pooled K scales with lookahead rows where they are made. Review that first.

Summary

The 64x64 MXFP8 Sol-Attn kernel reads its pooled E8M0 K scales, and the Jensen variance's, past their last 128-row tile and into the producer's lookahead rows. The producers now back them with those rows. A scale without them, a clone for instance, still faulted at the end of an allocation; the launch now refuses it with an error instead.

The earlier version of this PR copied the scales at launch. Under the tilt that copy dropped the K-scale planes behind mean_k_scale, and under torch.compile the backing did not survive. The copy is gone.

Motivation

A scale without the lookahead rows can still reach the kernel's read past its allocation. A clone of a pooled scale is one example. The launch accepted such a scale before this check, so the fault was reachable from a caller that bypasses the producers.

Changes

  • asm_mha_v4_fwd.cu: check_pooled_k_scale_backing_storage requires the tile padding plus kKvScaleLookaheadRows rows of mapped storage behind mean_k_scale and mean_k_var_scale on the hd128 64x64 FP8-K rows. With the tilt it bounds plane 0; sol_tilt_planes backs the last plane.
  • test_mha_v4_sparse.py: on the 64x64 MXFP8 row:
    • sol_prepare's scales carry the zeroed lookahead rows, eager and under torch.compile, and a clone of either is refused.
    • The tilt reaches the row at ranks 2 and 8.
    • Each pooled K-scale allocation, the tilt's stack included, placed at the end of a mapping with an unmapped granule after it, leaves the output unchanged at 8, 128, 136 and 1024 pooled rows. The cases run in a child process, since a fault ends it.

Performance (if applicable)

Not applicable. This is a launch check and tests. 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/test_mha_v4_sparse.py 619 ran, 5 skipped, 0 failed
op_tests/test_mha_v4.py 357 ran, 0 failed
op_tests/triton_tests/attention/test_sol_tilt.py 95 passed

On the earlier version of this PR, all four new checks fail: the tilt does not reach the row, the scales have no backing until the launch, the tilt stack placed at the end of a mapping changes the output, and a clone is accepted.

Documentation

  • Docstrings updated: no public docstring changed
  • User guide updated: not applicable
  • Performance guide updated: not applicable
  • No documentation change is needed: internal launch check, no user-facing behavior

Dependencies

  • No new third-party dependencies added

Breaking Changes

None. A pooled K scale without lookahead rows now raises at launch. The producers in #8800 always supply the rows.

PR Self-Review

Reviewed revision

3437013

Behavior and intent

The only code change against its base (#8800) is the launch check in asm_mha_v4_fwd.cu. A pooled K scale (mean_k_scale or mean_k_var_scale) without the lookahead rows, on the 64x64 hd128 FP8-K rows, is now refused with a RuntimeError. Before, the launch accepted it. #8800 backs the scales where they are made, so the check catches only a scale made some other way, such as a clone.

Validation and unverified scope

  • MI355X (gfx950), at 859b28c. The four new 64x64 tests run through the harness runner, since CI runs this file as a script and pytest cannot run these cases: 10 of 10 cases passed.
  • Against the base (9b6a954): 9 passed, 1 failed. The failure is refuses_pooled_k_scales_without_lookahead_rows, which raised no RuntimeError.
  • Against main (3486e43), for context only: 4 passed (the tilt cases), 6 failed (the lookahead cases, the refusal test, and the allocation-reads child process, which faults on the GPU). Main lacks [Triton/Gluon] [Fix] Sol-Attn: back pooled E8M0 K scales with lookahead rows #8800, so this result belongs to [Triton/Gluon] [Fix] Sol-Attn: back pooled E8M0 K scales with lookahead rows #8800's review.
  • Earlier runs, not repeated at this head: test_mha_v4_sparse.py 619 ran, 5 skipped, 0 failed; test_mha_v4.py 357 ran, 0 failed.
  • The earlier-version failures in Testing are not reproduced here.
  • The base is now 5274fbf, which adds the test_sol_prepare.py check. The merge brings in only that file, so the results above stand; test_sol_prepare.py at this head is 95 passed (run on the same file at 5274fbf).
  • Not run: gfx942 (MI300X), performance.

PR-specific question

Before this PR (the base, 9b6a954), only refuses_pooled_k_scales_without_lookahead_rows fails. That is the test for this PR's check. The other three new tests pass on the base. pooled_k_scales_carry_lookahead_rows overlaps the lookahead assertion in #8800's test_sol_tilt.py, and the other two check #8800's backing on the 64x64 row end to end. None of the three checks this PR's change. tilt_reads_its_k_scale_planes also passes on main.

Changed op tests

  • op_tests/test_mha_v4_sparse.py, the four tests on the 64x64 MXFP8 row:
    • refuses_pooled_k_scales_without_lookahead_rows: a clone without backing is refused. Fails on the base, so this covers this PR's check.
    • pooled_k_scales_carry_lookahead_rows (eager and compiled, two sizes): sol_prepare's scales carry the zeroed rows. Fails on main, passes on the base. Overlaps [Triton/Gluon] [Fix] Sol-Attn: back pooled E8M0 K scales with lookahead rows #8800's test_sol_tilt.py lookahead check at the op level.
    • tilt_reads_its_k_scale_planes (ranks 2 and 8, two sizes): the tilt reaches the row. Passes on main and on the base, so it does not guard either change.
    • pooled_k_scale_reads_stay_in_their_allocation (child process, VMM): reads end inside their allocations. Faults on main, passes on the base. Covers [Triton/Gluon] [Fix] Sol-Attn: back pooled E8M0 K scales with lookahead rows #8800's backing end to end.

@nsakkine
nsakkine added this pull request to stack #8802 November 27, 2026 05:24
@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 8801 --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 84a2fb4 on #8800. Moving the backing allocation to the producers and keeping the launcher validation-only avoids the old implicit-copy and layout-validation problems. I found no new correctness blocker in the source review.

The added tests cover compiled backing, rejection of truncated scale storage, rank-2/rank-8 tilt and mapped-allocation boundaries. The finite/nonidentical tilt check establishes that the planes affect the output; it is not an independent numerical oracle. Please keep this stack coordinated with #8683/#8684 so the shared hd128 backing fix is not landed twice.

Validation: source review and the seven CPU source/contract checks across these revisions passed. I have not independently run these GPU tests; the available test nodes were occupied. This is advisory feedback, not an approval.

@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] MHAv4: refuse pooled K scales in 64x64 MXFP8 Sol-Attn [HIP] [Fix] MHAv4: refuse pooled K scales in 64x64 MXFP8 Sol-Attn Nov 30, 2026
@github-actions github-actions Bot added the HIP label Nov 30, 2026
@aiter-bot

aiter-bot commented Nov 30, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 3437013420ee · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA

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

@nsakkine
nsakkine force-pushed the nsakkine/fix-mha_v4-mxfp8-k_scale-invalid-read branch from 2404f65 to 7cf5688 Compare November 30, 2026 21:06
…d read past

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 producer's lookahead rows. sol_prepare,
sol_jensen_cap and sol_tilt_planes back them with those rows. A scale
without them, a clone for instance, faulted whenever its allocation ended
at an unmapped page; the launch now refuses it.

- asm_mha_v4_fwd.cu: check_pooled_k_scale_backing_storage requires the
  tile padding plus kKvScaleLookaheadRows rows of mapped storage behind
  mean_k_scale and mean_k_var_scale on the hd128 64x64 FP8-K rows. With
  the tilt, mean_k_scale is plane 0 of a stack, so this bounds plane 0;
  sol_tilt_planes backs the last plane the same way.
- test_mha_v4_sparse: on the 64x64 MXFP8 row, sol_prepare's scales carry
  the zeroed lookahead rows, eager and under torch.compile, and a clone of
  either is refused. The tilt reaches the row at ranks 2 and 8. Each
  pooled K-scale allocation, sol_tilt_planes' stack included, placed at
  the end of a mapping with an unmapped granule after it, leaves the output
  unchanged at 8, 128, 136 and 1024 pooled rows.

Signed-off-by: Niko Säkkinen <[email protected]>
@nsakkine
nsakkine force-pushed the nsakkine/fix-mha_v4-mxfp8-k_scale-invalid-read branch from 7cf5688 to 3437013 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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants