Repository navigation
Conversation
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]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
jcaraban
left a comment
There was a problem hiding this comment.
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.
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.
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
There was a problem hiding this comment.
🟡 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
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
left a comment
There was a problem hiding this comment.
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.
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]>


Summary
Host-side Triton support for Sol-Attn at head dimension 256, for the hd256 recipes (BF16, MXFP8, MXFP6, MXFP4):
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_scalewith a packed K insol_prepare, andq_scalewithrotateinsol_q_abs_max.Changes
aiter/ops/triton/attention/utils.pysol_preparepacks pooled K/V with the hd256 quantizers and K views.sol_preparerefusesk_scaleat 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 tok_packed_format="mxfp8".sol_preparerefusesq_scalewithk_packed_format. A packed K routes on its unrotatedk_source, while an MXFP8 Q's codes are rotated by its quantizer, so Q dequantized throughq_scalewould be scored in the wrong basis and could select the wrong blocks. Routing against a packed K takes Q's pre-quantization tensor withoutq_scale._sol_attn_rotateand_sol_attn_pack_k_variance, shared by pooled-K packing and the Jensen cap.sol_preparedocstrings say which K formats are packed at which head dim, and which Q goes with which K: an MXFP8 Q's codes andq_scalewith an addressable MXFP8 K, Q's unrotated source with a packed K.aiter/ops/triton/attention/sol_tilt.pysol_tilt_planestreats 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_caphandles hd256 MXFP6 and MXFP8 K. These hold their scales inline, so the capped variance is re-packed frommean_k_var_pooledtimes the per-block gain, instead of having its scale bytes patched. A missingmean_k_var_pooledfails before the launch.sol_q_abs_max(rotate=True)accepts hd256, rotating each 128-channel half as an hd128 row.sol_q_abs_maxrefusesq_scalewithrotate. An MXFP8 Q's codes are already rotated, androtatetakes an unrotated BF16 source, so the pair would rotate Q twice._stack_planestakestail_rows, and the K-scale stack carriesMHA_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.pySTORE_SCALEconstexpr. When the hd256 variance is re-packed, which replaces its scale, the kernel skips the scale load and store and only finds the gain.HAS_SCALEandROTATEare 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_SCALEdecodesvarby the E8M0 bytes atvar_scale_ptr, one per 32 dims.EXPONENT_GAINapplies 2^floor(log2 gain) to those bytes instead of scalingvar, and stores that power of two as the gain. WithSTORE_SCALE=Falsethe kernel skips the scale load and store and only stores the gain, for a caller that packs the capped variance again.*_fp6_pis 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.k_scale.Overlap with the pooled K-scale fix
The hd128 MXFP8 tilt lookahead rows (
3258f6ae86) are the same_stack_planeschange as innsakkine/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.pyandop_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'sop_tests/test_mha_v4_sparse.pypasses on top of this revision.q_scalewithrotateis refused at hd128 and hd256.sol_prepare:k_scaleis refused at hd256, andq_scaleis refused with a packed K.PR Self-Review
Reviewed revision
4d4868f88a59Behavior 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_preparecould not pack pooled K/V for an hd256 row.k_packed_formataccepted only MXFP4 and MXFP6, and those K quantizers were hd128-only.sol_tilt_planescould not build tilt planes for a packed hd256 K.sol_jensen_capcould 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:
mean_k_var_pooledinstead of patching scale bytes, and skips the scale copy that path no longer uses.sol_preparerefusek_scaleat hd256, because no hd256 row reads a K pooled from its codes.sol_preparerefuseq_scalewith 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 andbench_sage.pyalready route packed recipes on the BF16 Q withoutq_scale.sol_q_abs_maxrefuseq_scalewithrotate, which would rotate an MXFP8 Q's already-rotated codes again.hd128 behavior is otherwise unchanged. The one hd128 input now refused,
q_scalewithrotateinsol_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:04500613c6): 20 failed, 158 passed, 2 skipped. The failures are the hd256, lookahead and refusal cases listed under the PR-specific question.op_tests/test_mha_v4_sparse.pyon the HIP branch with this revision merged in (787e83551c) ran 647 checks: 0 failed, 5 skipped.Unverified at this revision:
requires_gfx950cases do not run.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_prepareacceptedk_scaleat 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 ofq_scale.test_q_abs_max_refuses_a_scaled_q_with_rotate: at 128, DID NOT RAISE, because main acceptedq_scalewithrotateand 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_halfandtest_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_gainandtest_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_covariancepass 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.pyandtest_sol_tilt.pyare the canonical tests for these helpers, and before this PR they ran at head dim 128 only. The kernel tests intest_mha_v4_sparse.pysee 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.pyadds two tests ofsol_prepare's input contract at hd256:test_hd256_rejects_a_stored_k_scale:k_scaleis refused, and the error points tok_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_scaleis 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_scaleat head dim 256, orq_scaletogether with a packed K.op_tests/triton_tests/attention/test_sol_tilt.pyextends 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:test_q_abs_max_refuses_a_scaled_q_with_rotate, at hd128 and hd256;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.