Skip to content

[Triton/Gluon] Sol-Attn: hd256 pooled K/V packing, value tilt and Jensen cap - #8683

Open
nsakkine wants to merge 14 commits into
mainfrom
nsakkine/sol-attn-triton-hdim_256
Open

nsakkine wants to merge 14 commits into
mainfrom
nsakkine/sol-attn-triton-hdim_256

Conversation

@nsakkine

@nsakkine nsakkine commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Host-side Triton support for Sol-Attn at head dimension 256, for the hd256 recipes (BF16, MXFP8, MXFP6, MXFP4):

  • packing pooled K/V;
  • building value-tilt planes;
  • capping the Jensen variance term;
  • rotated Q maxima.

The hd256 MHA v4 kernels that consume these come in a stacked follow-up PR.

The one hd128 change: the MXFP8 tilt K-scale stack now carries zeroed lookahead rows behind its last plane, because the 64x64 MXFP8 row reads past it.

Two Q inputs that score Q and K in different bases are now refused: q_scale with a packed K in sol_prepare, and q_scale with rotate in sol_q_abs_max.

Changes

  • aiter/ops/triton/attention/utils.py
    • sol_prepare packs pooled K/V with the hd256 quantizers and K views.
    • An MXFP8 K is packed at hd256 only, as 64-token records with the scales inline. An hd128 MXFP8 K stays addressable, and the packer refuses it.
    • sol_prepare refuses k_scale at hd256. Every hd256 row with a block-scaled K reads a packed one, so a K pooled from its codes gives rows no hd256 row reads. Before, only the kernel launch's record check caught this, later. The error points to k_packed_format="mxfp8".
    • sol_prepare refuses q_scale with k_packed_format. A packed K routes on its unrotated k_source, while an MXFP8 Q's codes are rotated by its quantizer, so Q dequantized through q_scale would be scored in the wrong basis and could select the wrong blocks. Routing against a packed K takes Q's pre-quantization tensor without q_scale.
    • The packed K's rotation turns each 128-channel half as an hd128 row, as the hd256 packers do. The rotation and the variance re-pack are factored into _sol_attn_rotate and _sol_attn_pack_k_variance, shared by pooled-K packing and the Jensen cap.
    • The sol_prepare docstrings say which K formats are packed at which head dim, and which Q goes with which K: an MXFP8 Q's codes and q_scale with an addressable MXFP8 K, Q's unrotated source with a packed K.
  • aiter/ops/triton/attention/sol_tilt.py
    • sol_tilt_planes treats an hd256 MXFP8 K as packed and builds its planes from the BF16 source through the hd256 packer. FP6-P V planes use the hd256 quantizers.
    • sol_jensen_cap handles hd256 MXFP6 and MXFP8 K. These hold their scales inline, so the capped variance is re-packed from mean_k_var_pooled times the per-block gain, instead of having its scale bytes patched. A missing mean_k_var_pooled fails before the launch.
    • sol_q_abs_max(rotate=True) accepts hd256, rotating each 128-channel half as an hd128 row.
    • sol_q_abs_max refuses q_scale with rotate. An MXFP8 Q's codes are already rotated, and rotate takes an unrotated BF16 source, so the pair would rotate Q twice.
    • hd128 MXFP8: _stack_planes takes tail_rows, and the K-scale stack carries MHA_V4_KV_SCALE_LOOKAHEAD_ROWS (256) zeroed rows behind its last plane. The stack kernel writes the whole allocation, so torch.compile keeps the rows.
  • aiter/ops/triton/_triton_kernels/attention/sol_tilt.py
    • The Jensen cap kernel takes a STORE_SCALE constexpr. When the hd256 variance is re-packed, which replaces its scale, the kernel skips the scale load and store and only finds the gain.
    • The Q-maxima kernel static-asserts that HAS_SCALE and ROTATE are not combined.

hd256 rotation

The hd256 packers rotate each 128-channel half with the hd128 Hadamard rather than one 256-wide Hadamard. MX formats scale per 32-element block, so the quantization error is the same either way; a simulation agreed with this. Tilt planes take Q maxima in K's basis: the unrotated BF16 source for packed K. The Jensen cap takes rotated maxima for packed rows. Routing also needs Q and K in one basis: a packed K is pooled from its unrotated source, so Q is routed from its unrotated source too.

Jensen cap kernel and packed formats

  • HAS_VAR_SCALE decodes var by the E8M0 bytes at var_scale_ptr, one per 32 dims. EXPONENT_GAIN applies 2^floor(log2 gain) to those bytes instead of scaling var, and stores that power of two as the gain. With STORE_SCALE=False the kernel skips the scale load and store and only stores the gain, for a caller that packs the capped variance again.
  • A V named *_fp6_p is packed in the token order an FP6 P operand contracts over (AttentionPack.V_FOR_FP6_P), the only packed V order a Sol-Attn row reads. The name says which packer the pooled operand goes through, so it has to be the one the row reads.
  • An MXFP8 K is packed at hd256 only, where its records carry their scales. An hd128 MXFP8 K is addressable and pools from its codes through k_scale.

Overlap with the pooled K-scale fix

The hd128 MXFP8 tilt lookahead rows (3258f6ae86) are the same _stack_planes change as in nsakkine/fix-sol-attn-pooled-k-scale-backing. Whichever PR lands second picks up the other's version when it is rebased.

Testing (MI355X, gfx950)

op_tests/triton_tests/attention/test_sol_prepare.py and op_tests/triton_tests/attention/test_sol_tilt.py: 178 passed, 2 skipped. Run against main's code, the same files fail 20 cases; see the self-review below. The stacked HIP/ASM PR's op_tests/test_mha_v4_sparse.py passes on top of this revision.

  • Tilt planes: plane decode runs at hd256 for the addressable formats. The packed-plane layout test covers the hd256 MXFP8, MXFP6 and MXFP4 rows, including the zeroed hd256 MXFP4 K-scale slack.
  • MXFP8 K-scale stack: each plane is zeroed to a whole scale tile, and the lookahead rows behind the last plane are zeroed, for a padded and a full last tile.
  • Rotated maxima: the rotated hd256 Q maxima are checked against a per-half hd128 rotation. q_scale with rotate is refused at hd128 and hd256.
  • Jensen cap: the hd256 MXFP4, MXFP6 and MXFP8 cap moves each block's variance scale by log2 of its gain, and leaves it unchanged when no block is capped.
  • torch.compile: the tilt planes, the Jensen cap and the Q maxima match eager under fullgraph at hd256.
  • sol_prepare: k_scale is refused at hd256, and q_scale is refused with a packed K.

PR Self-Review

Reviewed revision

4d4868f88a59

Behavior and intent

Sol-Attn's host-side Triton helpers only handled head dimension 128, and the hd256 Sol-Attn kernels in the stacked follow-up PR need all four of them at 256:

  • sol_prepare could not pack pooled K/V for an hd256 row. k_packed_format accepted only MXFP4 and MXFP6, and those K quantizers were hd128-only.
  • sol_tilt_planes could not build tilt planes for a packed hd256 K.
  • sol_jensen_cap could not cap a variance whose scales sit inline in hd256 MXFP6 and MXFP8 records.
  • sol_q_abs_max(rotate=True) rejected head dim 256.

This PR:

  • Packs hd256 pooled K/V with the hd256 quantizers and K views, with an MXFP8 K as 64-token records with inline scales. Each 128-channel half is rotated as an hd128 row, as the packers do.
  • Builds tilt planes for a packed hd256 K from the BF16 source.
  • Re-packs the capped hd256 MXFP6 and MXFP8 variance from mean_k_var_pooled instead of patching scale bytes, and skips the scale copy that path no longer uses.
  • Makes sol_prepare refuse k_scale at hd256, because no hd256 row reads a K pooled from its codes.
  • Makes sol_prepare refuse q_scale with a packed K. Packing hd256 MXFP8 K is what first pairs an addressable MXFP8 Q with a packed K, and its rotated codes would be routed against K's unrotated pooled means. xDiT and bench_sage.py already route packed recipes on the BF16 Q without q_scale.
  • Makes sol_q_abs_max refuse q_scale with rotate, which would rotate an MXFP8 Q's already-rotated codes again.
  • Backs the hd128 MXFP8 tilt K-scale stack with the producer's zeroed lookahead rows past its last plane, which the 64x64 MXFP8 row reads. The rows survive torch.compile.

hd128 behavior is otherwise unchanged. The one hd128 input now refused, q_scale with rotate in sol_q_abs_max, had no correct use: no caller wants the maxima of a twice-rotated Q.

Validation and unverified scope

On one MI355X (gfx950) with torch 2.13.0 and Triton 3.8.0, I ran python -m pytest -q op_tests/triton_tests/attention/test_sol_prepare.py op_tests/triton_tests/attention/test_sol_tilt.py:

  • This revision: 178 passed, 2 skipped. The skips are intentional: packed-K formats are checked for layout instead of decode.
  • The same two test files against main's code (merge base 04500613c6): 20 failed, 158 passed, 2 skipped. The failures are the hd256, lookahead and refusal cases listed under the PR-specific question.
  • The stacked HIP/ASM PR's kernels: op_tests/test_mha_v4_sparse.py on the HIP branch with this revision merged in (787e83551c) ran 647 checks: 0 failed, 5 skipped.

Unverified at this revision:

  • gfx942, where the requires_gfx950 cases do not run.
  • End-to-end model runs.

PR-specific question

What would each changed op test fail on before this PR? I checked by running this PR's test files against main's code:

  • test_hd256_rejects_a_stored_k_scale: DID NOT RAISE. sol_prepare accepted k_scale at hd256 and pooled rows no hd256 kernel reads.
  • test_packed_k_rejects_a_scaled_q: ValueError "k_packed_format 'mxfp8' is not one of ('mxfp4', 'mxfp6')", instead of the refusal of q_scale.
  • test_q_abs_max_refuses_a_scaled_q_with_rotate: at 128, DID NOT RAISE, because main accepted q_scale with rotate and rotated the already-rotated codes again; at 256, ValueError "the packers' rotation is hd128, got head dim 256", instead of the refusal.
  • test_rotated_hd256_q_abs_max_rotates_each_half and test_q_abs_max_compiles_fullgraph_and_matches_eager[rotated-256]: ValueError "the packers' rotation is hd128, got head dim 256".
  • test_packed_tilt_planes_keep_plane_zero_and_the_packers_backing, test_tilt_planes_compile_fullgraph_and_match_eager, test_hd256_jensen_cap_moves_each_block_scale_by_its_gain and test_jensen_cap_compiles_fullgraph_and_matches_eager, at 256 for MXFP4, MXFP6 and MXFP8: ValueError. Either the K quantizer is "packed for head dimension 128, got 256", or "k_packed_format 'mxfp8' is not one of ('mxfp4', 'mxfp6')".
  • test_tilt_planes_pad_each_mxfp8_k_scale_plane_to_a_whole_scale_tile, for both the padded and the full last tile: no zeroed lookahead rows behind the last plane (assert 0 >= (256 * 8)).

The new head_dim=256 cases of test_tilt_planes_decode_to_the_truncated_block_covariance pass on main too. Main already decoded hd256 planes for the addressable formats, but no test exercised it.

Why no existing canonical test already covers this: test_sol_prepare.py and test_sol_tilt.py are the canonical tests for these helpers, and before this PR they ran at head dim 128 only. The kernel tests in test_mha_v4_sparse.py see these tensors only through a kernel's output, so they cannot pin a byte layout or a backing. The hd256 kernels also only land in the follow-up PR.

Changed op tests

  • op_tests/triton_tests/attention/test_sol_prepare.py adds two tests of sol_prepare's input contract at hd256:

    • test_hd256_rejects_a_stored_k_scale: k_scale is refused, and the error points to k_packed_format="mxfp8". Without it, the mistake would surface only later, in the kernel launch's record check.
    • test_packed_k_rejects_a_scaled_q: q_scale is refused with a packed MXFP8 K, and the error says to pass Q's pre-quantization tensor. Without it, the mismatch selects wrong blocks silently, with no error at all.

    They are not redundant: no other test passes k_scale at head dim 256, or q_scale together with a packed K.

  • op_tests/triton_tests/attention/test_sol_tilt.py extends the existing tests with head_dim=256: tilt-plane decode, packed-plane layout, Q maxima and the Jensen cap, both eager and under torch.compile fullgraph. It also:

    • adds the per-half rotation check for hd256 Q maxima and the hd256 Jensen cap's per-block scale-gain check;
    • adds test_q_abs_max_refuses_a_scaled_q_with_rotate, at hd128 and hd256;
    • asserts the zeroed hd256 MXFP4 K-scale slack;
    • extends the MXFP8 K-scale stack test to a full last tile and its lookahead rows.

    It is not redundant: these are the only tests that check these helpers' outputs directly. Extending the existing tests by parametrization rather than adding new files keeps one canonical test per behavior.

nsakkine and others added 3 commits November 25, 2026 10:53
sol_prepare packs pooled K and V for head dim 256, so the hd256 Sol-Attn
rows (BF16, MXFP8, MXFP6, MXFP4) can read them. The rows themselves come
in a follow-up.

- utils.py: pooled K/V use the hd256 quantizers and K views. An MXFP8 K
  is packed at head dim 256 only, as 64-token records with the scales
  inline; an hd128 MXFP8 K stays addressable and is refused here. The
  packed K's rotation turns each 128-channel half as an hd128 row, as the
  hd256 packers do.

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

- sol_tilt.py: sol_tilt_planes treats an hd256 MXFP8 K as packed and builds
  its planes from the BF16 source through the hd256 packer. FP6-P V planes
  use the hd256 quantizers when head_dim is 256.
- test_sol_tilt: make_tilt_inputs takes a head_dim. The plane-decode test
  runs at hd256 for the addressable formats. The packed-plane layout test
  covers the hd256 MXFP8, MXFP6 and MXFP4 rows. The hd128 scale-slack check
  stays hd128-only, because the hd256 readers stay within the image.

Signed-off-by: Niko Säkkinen <[email protected]>
Co-authored-by: Cursor <[email protected]>
The hd256 Sol-Attn rows can take the capped Jensen term next to sol_tilt.

- sol_tilt.py: sol_jensen_cap handles an hd256 MXFP6 or MXFP8 K. These
  records hold their scales inline, so the capped variance is packed again
  from mean_k_var_pooled times the per-block gain, instead of having its
  scale bytes patched. It raises if mean_k_var_pooled is missing.
  sol_q_abs_max(rotate=True) accepts head dim 256. There the packers rotate
  each 128-channel half as an hd128 row.
- utils.py: the K packers' rotation and the variance re-pack are now
  _sol_attn_rotate and _sol_attn_pack_k_variance. _sol_attn_pool_packed_k
  and the Jensen cap share them.
- test_sol_tilt: the rotated hd256 Q maxima are checked against a per-half
  hd128 rotation. make_jensen_inputs takes a head_dim. A new gfx950 test
  checks that the hd256 MXFP4, MXFP6 and MXFP8 cap moves each block's
  variance scale by log2 of its gain, and leaves it unchanged when no block
  is capped.

Signed-off-by: Niko Säkkinen <[email protected]>
Co-authored-by: Cursor <[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 8683 --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.

@nsakkine
nsakkine added this pull request to stack #8685 November 25, 2026 11:07
@nsakkine nsakkine changed the title Sol-Attn: hd256 pooled K/V packing, value tilt and Jensen cap (gfx950) Sol-Attn: hd256 pooled K/V packing, value tilt and Jensen cap Nov 25, 2026

@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 went through this together with #8684. That was code reading plus a trial merge with current main; I haven't run anything on a GPU.

The host side looks right to me. The hd256 packers do rotate each 128-channel half (_hd256_half_heads), which is what _sol_attn_rotate assumes. The sol_q_abs_max reshape keeps the (head, half) order. And since the cap's gain is a power of two, re-packing mean_k_var_pooled * gain gives the same codes with the scale moved by log2(gain), which your new test checks. It also still merges cleanly into main.

A few smaller things are inline, mostly docs and test coverage.

Comment thread aiter/ops/triton/attention/utils.py Resolved
Comment thread aiter/ops/triton/attention/sol_tilt.py Resolved
With "mxfp8" among the packed K formats, two sol_prepare docstrings and
the comment on the tuples said more than they meant.

- q: names the packed Q formats (MXFP4, MXFP6) instead of the tuple. An
  MXFP8 Q is addressable at either head dim and takes q_scale.
- mean_k_scale: an hd256 MXFP8 K keeps its scales inside its records,
  as an MXFP6 K does.
- The tuple comment says MXFP8 is a packed K format at head dim 256 only.

Signed-off-by: Niko Säkkinen <[email protected]>
Every hd256 row with a block-scaled K reads a packed one, so a K pooled
from its codes through k_scale gives BSHD rows that no hd256 row reads.
Until now only mha_v4_packed's record check refused them later.
sol_prepare now raises up front and points to
k_packed_format="mxfp8". test_sol_prepare covers it.

Signed-off-by: Niko Säkkinen <[email protected]>
The hd256 MXFP6 and MXFP8 variance is packed again from mean_k_var_pooled,
which replaces both the variance and its scale, so the kernel's shifted
copy of the scale image was allocated and written for nothing. A
STORE_SCALE constexpr skips the scale load and store there; the kernel
then only finds the gain. A missing mean_k_var_pooled now fails before
the launch.

Signed-off-by: Niko Säkkinen <[email protected]>
The slack check skipped hd256 on the claim that its readers stay inside
the image. The hd256 MXFP4 K scale reader reads one dword past its last
row, as at hd128, so the check now asserts the zeroed slack for it at
both head dims. Only the V scale stays hd128-only: the hd256 V scale
readers stop at the image.

Signed-off-by: Niko Säkkinen <[email protected]>
Add hd256 rows to the fullgraph-vs-eager tests, so that the cap's
rotation and K re-pack at head dim 256 are traced under torch.compile.

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

# Conflicts:
#	op_tests/triton_tests/attention/test_sol_prepare.py
#	op_tests/triton_tests/attention/test_sol_tilt.py
The 64x64 MXFP8 row reads its K scales past the last 128-row tile, so
the last plane now carries the producer's zeroed lookahead rows. The
stack kernel writes the whole allocation, so torch.compile keeps them.
@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 Sol-Attn: hd256 pooled K/V packing, value tilt and Jensen cap [Triton/Gluon] Sol-Attn: hd256 pooled K/V packing, value tilt and Jensen cap Nov 27, 2026
@aiter-bot

aiter-bot commented Nov 27, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 4d4868f88a59 · 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

Sol-Attn's host-side Triton helpers only handled head dimension 128, and the hd256 Sol-Attn kernels in the stacked follow-up PR need all four of them at 256:

- `sol_prepare` could not pack pooled K/V for an hd256 row. `k_packed_format` accepted only MXFP4 and MXFP6, and those K quantizers were hd128-only.
- `sol_tilt_planes` could not build tilt planes for a packed hd256 K.
- `sol_jensen_cap` could not cap a variance whose scales sit inline in hd256 MXFP6 and MXFP8 records.
- `sol_q_abs_max(rotate=True)` rejected head dim 256.

This PR:

- Packs hd256 pooled K/V with the hd256 quantizers and K views, with an MXFP8 K as 64-token records with inline scales. Each 128-channel half is rotated as an hd128 row, as the packers do.
- Builds tilt planes for a packed hd256 K from the BF16 source.
- Re-packs the capped hd256 MXFP6 and MXFP8 variance from `mean_k_var_pooled` instead of patching scale bytes, and skips the scale copy that path no longer uses.
- Makes `sol_prepare` refuse `k_scale` at hd256, because no hd256 row reads a K pooled from its codes.
- Makes `sol_prepare` refuse `q_scale` with a packed K. Packing hd256 MXFP8 K is what first pairs an addressable MXFP8 Q with a packed K, and its rotated codes would be routed against K's unrotated pooled means. xDiT and `bench_sage.py` already route packed recipes on the BF16 Q without `q_scale`.
- Makes `sol_q_abs_max` refuse `q_scale` with `rotate`, which would rotate an MXFP8 Q's already-rotated codes again.
- Backs the hd128 MXFP8 tilt K-scale stack with the producer's zeroed lookahead rows past its last plane, which the 64x64 MXFP8 row reads. The rows survive torch.compile.

hd128 behavior is otherwise unchanged. The one hd128 input now refused, `q_scale` with `rotate` in `sol_q_abs_max`, had no correct use: no caller wants the maxima of a twice-rotated Q.

Validation and unverified scope

On one MI355X (gfx950) with torch 2.13.0 and Triton 3.8.0, I ran `python -m pytest -q op_tests/triton_tests/attention/test_sol_prepare.py op_tests/triton_tests/attention/test_sol_tilt.py`:

- **This revision:** 178 passed, 2 skipped. The skips are intentional: packed-K formats are checked for layout instead of decode.
- **The same two test files against main's code** (merge base `04500613c6`): 20 failed, 158 passed, 2 skipped. The failures are the hd256, lookahead and refusal cases listed under the PR-specific question.
- **The stacked HIP/ASM PR's kernels:** `op_tests/test_mha_v4_sparse.py` on the HIP branch with this revision merged in (`787e83551c`) ran 647 checks: 0 failed, 5 skipped.

Unverified at this revision:

- gfx942, where the `requires_gfx950` cases do not run.
- End-to-end model runs.

PR-specific question

What would each changed op test fail on before this PR? I checked by running this PR's test files against main's code:

- `test_hd256_rejects_a_stored_k_scale`: DID NOT RAISE. `sol_prepare` accepted `k_scale` at hd256 and pooled rows no hd256 kernel reads.
- `test_packed_k_rejects_a_scaled_q`: ValueError "k_packed_format 'mxfp8' is not one of ('mxfp4', 'mxfp6')", instead of the refusal of `q_scale`.
- `test_q_abs_max_refuses_a_scaled_q_with_rotate`: at 128, DID NOT RAISE, because main accepted `q_scale` with `rotate` and rotated the already-rotated codes again; at 256, ValueError "the packers' rotation is hd128, got head dim 256", instead of the refusal.
- `test_rotated_hd256_q_abs_max_rotates_each_half` and `test_q_abs_max_compiles_fullgraph_and_matches_eager[rotated-256]`: ValueError "the packers' rotation is hd128, got head dim 256".
- `test_packed_tilt_planes_keep_plane_zero_and_the_packers_backing`, `test_tilt_planes_compile_fullgraph_and_match_eager`, `test_hd256_jensen_cap_moves_each_block_scale_by_its_gain` and `test_jensen_cap_compiles_fullgraph_and_matches_eager`, at 256 for MXFP4, MXFP6 and MXFP8: ValueError. Either the K quantizer is "packed for head dimension 128, got 256", or "k_packed_format 'mxfp8' is not one of ('mxfp4', 'mxfp6')".
- `test_tilt_planes_pad_each_mxfp8_k_scale_plane_to_a_whole_scale_tile`, for both the padded and the full last tile: no zeroed lookahead rows behind the last plane (`assert 0 >= (256 * 8)`).

The new head_dim=256 cases of `test_tilt_planes_decode_to_the_truncated_block_covariance` pass on main too. Main already decoded hd256 planes for the addressable formats, but no test exercised it.

Why no existing canonical test already covers this: `test_sol_prepare.py` and `test_sol_tilt.py` are the canonical tests for these helpers, and before this PR they ran at head dim 128 only. The kernel tests in `test_mha_v4_sparse.py` see these tensors only through a kernel's output, so they cannot pin a byte layout or a backing. The hd256 kernels also only land in the follow-up PR.

Changed op tests

- **`op_tests/triton_tests/attention/test_sol_prepare.py`** adds two tests of `sol_prepare`'s input contract at hd256:
  - `test_hd256_rejects_a_stored_k_scale`: `k_scale` is refused, and the error points to `k_packed_format="mxfp8"`. Without it, the mistake would surface only later, in the kernel launch's record check.
  - `test_packed_k_rejects_a_scaled_q`: `q_scale` is refused with a packed MXFP8 K, and the error says to pass Q's pre-quantization tensor. Without it, the mismatch selects wrong blocks silently, with no error at all.

  They are not redundant: no other test passes `k_scale` at head dim 256, or `q_scale` together with a packed K.
- **`op_tests/triton_tests/attention/test_sol_tilt.py`** extends the existing tests with head_dim=256: tilt-plane decode, packed-plane layout, Q maxima and the Jensen cap, both eager and under torch.compile fullgraph. It also:
  - adds the per-half rotation check for hd256 Q maxima and the hd256 Jensen cap's per-block scale-gain check;
  - adds `test_q_abs_max_refuses_a_scaled_q_with_rotate`, at hd128 and hd256;
  - asserts the zeroed hd256 MXFP4 K-scale slack;
  - extends the MXFP8 K-scale stack test to a full last tile and its lookahead rows.

  It is not redundant: these are the only tests that check these helpers' outputs directly. Extending the existing tests by parametrization rather than adding new files keeps one canonical test per behavior.

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 hd256 recursive kernel rotates Q before applying unequal q_scale groups, producing incorrect Q maxima when rotation is enabled.

2 open issues
What changed in this PR

This PR extends Sol-Attn’s Triton helpers to head dimension 256, preparing pooled tensors and statistics for the attention kernels planned in a stacked follow-up PR.

Changes:

  • Add hd256 pooled K/V packing and value-tilt planes using the matching quantizers.
  • Support per-half Q rotation and Jensen variance capping for packed hd256 formats.
  • Add zeroed hd128 MXFP8 K-scale lookahead storage and extend layout, numerical, and fullgraph compilation tests.
File Description
op_tests/​triton_tests/​attention/​test_sol_tilt.py Extends hd256 tilt, rotation, cap, layout, and compilation coverage.
op_tests/​triton_tests/​attention/​test_sol_prepare.py Tests rejection of addressable K scales at hd256.
aiter/​ops/​triton/​attention/​utils.py Adds hd256 packing, shared rotation and variance-packing helpers, and input validation.
aiter/​ops/​triton/​attention/​sol_tilt.py Extends tilt planes, Q maxima, Jensen capping, and scale-stack backing.
aiter/​ops/​triton/​_triton_kernels/​attention/​sol_tilt.py Lets the Jensen kernel skip scale reads and writes when variance is repacked.

Review effort: Balanced

Comment thread aiter/ops/triton/attention/sol_tilt.py Resolved
Comment thread aiter/ops/triton/attention/utils.py Resolved
The Q-maxima kernel rotates before applying the E8M0 scales, which is
wrong whenever a 128-channel half has unequal scale groups. No caller
combines them: q_scale dequantizes an MXFP8 Q's codes, which the
quantizer already rotated, while rotate takes an unrotated BF16 source.
Refuse the combination in the wrapper and the kernel instead of
defining it, and test it at hd128 and hd256.

Signed-off-by: Niko Säkkinen <[email protected]>
A packed K routes on its unrotated k_source, while an MXFP8 Q's codes are
rotated by its quantizer, so dequantizing them with q_scale scores Q and K
in different bases. Refuse the pair and document that a packed K takes Q's
pre-quantization tensor without q_scale.

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

@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 ce13af7. The early scaled-Q/rotation and addressable-hd256-K-scale checks, per-half rotation and repack handling address the earlier findings. I found no new correctness blocker in the source review.

The remaining scope and documentation follow-ups are inline. There is also a real conflict when combining this stack with #8800/#8801, rather than a conflict with this PR's own base: in sol_jensen_cap, retain the hd256 repack conditional and replace only the non-repack _backed_scale_copy call with _sol_attn_pad_scale_rows. Preserve and not k_packed in sol_tilt_planes and both test import lists when resolving the combined changes.

Validation: seven CPU source/contract checks across these revisions passed, including early guard behavior and changed call signatures. I have not independently run the GPU numerical or torch.compile tests; the available test nodes were occupied. This is advisory feedback, not an approval.

Comment thread aiter/ops/triton/attention/sol_tilt.py Resolved
Comment thread aiter/ops/triton/attention/utils.py Resolved
The packed-format comment in utils.py and the Jensen-kernel docstring are
now two sentences each, as the repo's comment rule asks. The longer
explanations are in the PR description.

Signed-off-by: Niko Säkkinen <[email protected]>
@zufayu
zufayu requested a review from a team December 1, 2026 03:27

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.

4 participants