Repository navigation
[Triton/Gluon] Sol-Attn: block pooling, routing and low-rank tilt factors - #7729
Conversation
…tors Add the Triton side of Sol-Attn. The mha_v4 Sol-Attn rows read these operands; that ASM change follows in a separate PR. - sol_prepare() in attention/utils.py builds the LUT, the block bitmap and the pooled K/V from one block selection. The selection is routed from beta or supplied as a mask. It can also give the Jensen K variance. - sol_attn_pool pools a BSHD tensor into one row per block: the block mean and, optionally, the variance or the mean of squares, in one read. - attention/sol_tilt.py builds the Jensen cap and the low-rank tilt factors and planes for each Sol recipe. - mxfp6_fmha_pack.fill_fp6_k_scale_tails writes the MXFP6 K scale tails; reorder_fp6_k_lds_order_triton and sol_tilt use it. - Tuned gfx950 configs for the pool and the tilt factor kernels. Tests: test_sol_prepare.py and test_sol_tilt.py check each wrapper against a Torch reference and under torch.compile(fullgraph=True). Benchmark: bench_sol_tilt.py. Signed-off-by: Niko Säkkinen <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
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
Critical unresolved issues can collapse rank-2 results to rank 1, cause out-of-bounds writes when block and tile sizes mismatch, and expose uninitialized rotation data across graph and eager calls.
4 open issues
What changed in this PR
This PR adds Triton preparation operators for Sol-Attn’s pooled block-sparse attention path. It prepares routing, pooled operands and low-rank corrections for ASM consumers planned in the next PR.
Changes:
- Add block pooling, routing, LUT/bitmap generation and quantized operand preparation.
- Add Jensen caps, low-rank tilt factors and planes, plus gfx950 tuning configs.
- Add reference and full-graph compilation tests, a tilt benchmark and a reusable MXFP6 scale-tail helper.
| File | Description |
|---|---|
op_tests/triton_tests/attention/test_sol_tilt.py |
Tests caps, tilt formats, scale padding and compilation parity. |
op_tests/triton_tests/attention/test_sol_prepare.py |
Tests routing, pooled values, output contracts and compilation. |
op_tests/op_benchmarks/triton/bench_sol_tilt.py |
Benchmarks tilt and cap wrappers on Wan shapes. |
aiter/ops/triton/quant/mxfp6_fmha_pack.py |
Extracts a public MXFP6 K scale-tail writer. |
aiter/ops/triton/configs/gfx950/triton/attention/sol_tilt_factor/DEFAULT.json |
Adds factor-kernel launch schedules. |
aiter/ops/triton/configs/gfx950/triton/attention/sol_attn_pool/DEFAULT.json |
Adds pooling schedules by statistic, dtype size and block size. |
aiter/ops/triton/attention/utils.py |
Adds Sol-Attn routing and pooled-operand preparation. |
aiter/ops/triton/attention/sol_tilt.py |
Adds public cap, factor and plane wrappers. |
aiter/ops/triton/attention/sol_attn_pool.py |
Adds the public block-pooling wrapper and config loading. |
aiter/ops/triton/_triton_kernels/attention/sol_tilt.py |
Implements maxima, caps, factorization and plane encoding. |
aiter/ops/triton/_triton_kernels/attention/sol_attn_pool.py |
Implements block means, variance and mean of squares. |
Review effort: Balanced
…lock mismatch Build the q_abs_max rotation signs in the kernel. A first sol_q_abs_max(rotate=True) call inside a CUDA graph capture put the rotation signs into a device-wide cache before their initialization kernels ran, so an eager call or another graph before the first replay read uninitialized signs. The packers' hd128 rotation is the Sylvester Hadamard matrix, H[i, j] = (-1)^popcount(i & j), so the kernel now makes it from the row and column indices, and the cache is removed. Rotated outputs are byte-identical, and the rotated q_abs_max is 20% faster on MI355X (55.7 -> 44.5 us at 720p, Ulysses 8). Refuse pooled K/V of another kv_tile. sol_tilt_factors and sol_tilt_planes took the block count from mean_k, but the factor kernel writes one plane row per full kv_tile block of K, unmasked. Means pooled at sol_prepare's default 128-token blocks used with kv_tile=64 allocated two plane rows and wrote four, which corrupted the next rank's plane and the B planes after it. Both wrappers now check, before anything is allocated, that mean_k, mean_v and the pooled BF16 rows have ceil(seqlen_k / kv_tile) blocks. The pack kernel reads mean_v over mean_k's blocks, so a short mean_v is refused too. Add tests for a first rotated call inside a graph capture, and for pooled K/V of another kv_tile or a short mean_v in both wrappers. Signed-off-by: Niko Säkkinen <[email protected]>
…ng pool sol_jensen_cap and sol_tilt_factors read q_abs_max and take only Q's shape, but the benchmark passed the full Q, and the rotating pool counts every tensor in the kwargs. At 720p with Ulysses 8, Q's 46-92 MB made each Jensen-cap entry look about 100 MB against the 1.6-3.1 MB the call reads. The 256 MB target then gave 4-6 entries, and the read set stayed in cache. Pass Q as a one-element view of its shape in those two cases. The Jensen-cap pool grows from 4-6 to 84-165 entries, and its times rise by 1-2 us to uncached values. Outputs are bit-identical, and the factors case, which reads 93 MB of K/V, does not change. Signed-off-by: Niko Säkkinen <[email protected]>
…tors (#7729) * [Triton/Gluon] Sol-Attn: block pooling, routing and low-rank tilt factors Add the Triton side of Sol-Attn. The mha_v4 Sol-Attn rows read these operands; that ASM change follows in a separate PR. - sol_prepare() in attention/utils.py builds the LUT, the block bitmap and the pooled K/V from one block selection. The selection is routed from beta or supplied as a mask. It can also give the Jensen K variance. - sol_attn_pool pools a BSHD tensor into one row per block: the block mean and, optionally, the variance or the mean of squares, in one read. - attention/sol_tilt.py builds the Jensen cap and the low-rank tilt factors and planes for each Sol recipe. - mxfp6_fmha_pack.fill_fp6_k_scale_tails writes the MXFP6 K scale tails; reorder_fp6_k_lds_order_triton and sol_tilt use it. - Tuned gfx950 configs for the pool and the tilt factor kernels. Tests: test_sol_prepare.py and test_sol_tilt.py check each wrapper against a Torch reference and under torch.compile(fullgraph=True). Benchmark: bench_sol_tilt.py. Signed-off-by: Niko Säkkinen <[email protected]> * [Triton/Gluon] Sol-Attn: make the tilt safe under graph capture and block mismatch Build the q_abs_max rotation signs in the kernel. A first sol_q_abs_max(rotate=True) call inside a CUDA graph capture put the rotation signs into a device-wide cache before their initialization kernels ran, so an eager call or another graph before the first replay read uninitialized signs. The packers' hd128 rotation is the Sylvester Hadamard matrix, H[i, j] = (-1)^popcount(i & j), so the kernel now makes it from the row and column indices, and the cache is removed. Rotated outputs are byte-identical, and the rotated q_abs_max is 20% faster on MI355X (55.7 -> 44.5 us at 720p, Ulysses 8). Refuse pooled K/V of another kv_tile. sol_tilt_factors and sol_tilt_planes took the block count from mean_k, but the factor kernel writes one plane row per full kv_tile block of K, unmasked. Means pooled at sol_prepare's default 128-token blocks used with kv_tile=64 allocated two plane rows and wrote four, which corrupted the next rank's plane and the B planes after it. Both wrappers now check, before anything is allocated, that mean_k, mean_v and the pooled BF16 rows have ceil(seqlen_k / kv_tile) blocks. The pack kernel reads mean_v over mean_k's blocks, so a short mean_v is refused too. Add tests for a first rotated call inside a graph capture, and for pooled K/V of another kv_tile or a short mean_v in both wrappers. Signed-off-by: Niko Säkkinen <[email protected]> * [Triton/Gluon] Sol-Attn: keep unread Q out of the tilt bench's rotating pool sol_jensen_cap and sol_tilt_factors read q_abs_max and take only Q's shape, but the benchmark passed the full Q, and the rotating pool counts every tensor in the kwargs. At 720p with Ulysses 8, Q's 46-92 MB made each Jensen-cap entry look about 100 MB against the 1.6-3.1 MB the call reads. The 256 MB target then gave 4-6 entries, and the read set stayed in cache. Pass Q as a one-element view of its shape in those two cases. The Jensen-cap pool grows from 4-6 to 84-165 entries, and its times rise by 1-2 us to uncached values. Outputs are bit-identical, and the factors case, which reads 93 MB of K/V, does not change. Signed-off-by: Niko Säkkinen <[email protected]> --------- Signed-off-by: Niko Säkkinen <[email protected]>


Motivation
Sol-Attn (arXiv 2607.24027) adds a pooled pass to block-sparse attention: a block that the LUT leaves out adds its pooled K/V term instead of nothing. This PR adds the Triton operators that prepare those operands. The mha_v4 ASM kernels that read them follow in the next PR.
Changes
sol_prepare()(attention/utils.py): from one block selection, it builds the LUT, the block bitmap and the pooled K/V. The selection is routed frombetaor supplied as a mask. It can also give the Jensen K variance.sol_attn_pool(attention/sol_attn_pool.py, kernel in_triton_kernels/): pools a BSHD tensor into one row per block. It gives the block mean and, optionally, the variance or the mean of squares, in one read.attention/sol_tilt.py: the Jensen cap and the low-rank tilt factors and planes for each Sol recipe.mxfp6_fmha_pack.fill_fp6_k_scale_tails: a public helper that writes the MXFP6 K scale tails.sol_attn_poolandsol_tilt_factor. An arch without a config file uses a portable fallback.Tests
op_tests/triton_tests/attention/test_sol_prepare.pyop_tests/triton_tests/attention/test_sol_tilt.pyEach wrapper is checked against a Torch reference and under
torch.compile(fullgraph=True).Benchmark:
op_tests/op_benchmarks/triton/bench_sol_tilt.py.Stack
1 of 3. This PR has no HIP or ASM change.
PR Self-Review
Reviewed revision
b9987e0
Behavior and intent
This PR adds new Triton operators. It does not change the behavior of an existing operator.
sol_prepare()(attention/utils.py) builds the inputs of the Sol-Attn kernels from one block selection: the LUT, the block bitmap and the pooled K/V in the kernel's own formats, with E8M0 scales where the recipe needs them. The selection is routed frombeta(mean or error router) or supplied as a mask. It can also give the Jensen K variance.sol_attn_poolpools a BSHD tensor into one row per block (the mean, plus optionally the variance or the mean of squares) in one read.attention/sol_tilt.pybuilds the Jensen cap and the low-rank tilt factors and planes for each Sol recipe. It refuses pooled K/V whose block count does not matchkv_tilebefore any kernel writes. It keeps no device-wide state, so a first call inside a CUDA graph capture is safe.mxfp6_fmha_pack.fill_fp6_k_scale_tailsis a public helper for the MXFP6 K scale tails.reorder_fp6_k_lds_order_tritonnow calls it instead of launching the kernel itself. Its output does not change (see Validation).Why the existing behavior is not sufficient: block-sparse attention (
block_attn_mask_to_lutand the mha_v4 sparse rows) keeps or drops each block. A dropped block adds nothing. Sol-Attn (arXiv 2607.24027) adds a pooled pass, in which each dropped block adds its pooled K/V term. That pass needs the LUT, the bitmap and the pooled operands from the same selection, quantized as the kernel reads them. No existing operator makes them. The mha_v4 kernels that consume them follow in #PR2.Validation and unverified scope
Summary: validated on MI355X (gfx950) with the two op tests, the benchmark, lint and the review-time byte and sweep checks below. What remains unverified: architectures other than gfx950, shapes other than Wan 2.2 at head dim 128, end-to-end accuracy with the ASM kernels (#PR2), and the #PR2 mha_v4 tests against this revision. Details follow.
Hardware and software: MI355X (gfx950), ROCm 10.1.0, torch 2.13.0 (HIP 7.16), Triton 3.8.0. The test, lint and benchmark runs below used this revision (main at 97d2389 plus this PR only). The byte and sweep checks after them ran during development, on a branch with the same Triton files.
python3 -m pytest -q op_tests/triton_tests/attention/test_sol_prepare.py: 91 passed.python3 -m pytest -q op_tests/triton_tests/attention/test_sol_tilt.py: 94 passed.ruff checkandblack --checkon the changed Python files: clean.python3 op_tests/op_benchmarks/triton/bench_sol_tilt.py --rank 2(720p, Ulysses 8, KV tile 128):sol_q_abs_max: 17.4-51.3 us over the 4 Q kinds (rotated 44.2 us);sol_jensen_cap: 21.5-28.9 us over the 5 K kinds;sol_tilt_planes: 113.6-215.6 us over the 8 recipes;sol_tilt_factors: 109.7 us.sol_q_abs_maxoutputs are byte-identical to the earlier cached signs on 4 shapes, and 20% faster (55.7 to 44.5 us). The new graph-capture test failed on the cached signs (all 7680 maxima wrong) and passes now.reorder_fp6_k_lds_order_tritonbefore and after the helper change: byte-identical buffers for 256, 300 and 37 rows (full and partial last tile). Fresh allocations were filled with 0xA5, so unwritten bytes also compare equal.sol_attn_poolschedule: a check with a sentinel config confirmed that the launch reads the JSON. The published values give the same launches as the earlier formulas in Python, and a missing file gives the fallback.sol_tilt_factorschedule: a sweep of num_warps 1/2/4/8 x waves_per_eu 0/1/2/4 over 21 cases (fp8, bf16 and int8 paths; KV tile 64 and 128; rank 1-4; 5 and 40 heads). With the published values, everybench_sol_tilt.pycase (720p, Ulysses 8, rank 2, KV tile 64 and 128, all 9 factors and planes recipes) is 11-54% faster than with 4 warps / 2 waves. The outputs are byte-identical, including every tilt plane.What remains unverified:
op_tests/test_mha_v4_sparse.py).op_tests/test_mha_v4.py, which callsreorder_fp6_k_lds_order_triton. I ran it only on the full stack, where all its checks pass. The byte-identity check above covers that caller.BLOCK_Nequal to the tile, so they are expected to pass it.PR-specific question
Which exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?
Both config families are new. No existing config file changes: the only config changes in this PR are two added files.
configs/gfx950/triton/attention/sol_attn_pool/DEFAULT.jsonis read only bysol_attn_pool._pool_tile(block, element_size, aux), throughresolve_config_dir("attention", "SOL_ATTN_POOL"). The key ismean_<element size>for the mean alone, oraux_<element size>when a second statistic is pooled, with element size 1, 2 or 4. Each key is bucketed by block size withBLOCK_LEQ_<n>andany. The only callers aresol_prepare's pooling of Q, K and V.configs/gfx950/triton/attention/sol_tilt_factor/DEFAULT.jsonis read only bysol_tilt._factor_launch(to_bf16, kv_tile), throughresolve_config_dir("attention", "SOL_TILT_FACTOR"). The key isfp8when K and V are both FP8 andbf16otherwise, which includes int8 K. It is bucketed by KV tile withBLOCK_N_LEQ_64andany. The only callers aresol_tilt_factorsandsol_tilt_planes.Evidence that unrelated shapes keep their selection:
rg "SOL_ATTN_POOL|SOL_TILT_FACTOR" aiterfinds only these two loaders.git diff --name-status 97d2389d41 b9987e01b578 -- aiter/ops/triton/configslists only the two added files. No other operator reads these families, and no existing family changes, so every other kernel's config selection is the same as on main.Changed op tests
op_tests/triton_tests/attention/test_sol_prepare.py(new) coverssol_prepareandsol_attn_pool:torch.compile(fullgraph=True)parity, with no graph breaks.It is not redundant: no existing test calls these operators.
test_mha_v4_sparse.pyin #PR2 tests the kernels end to end, not the contracts of the preparation step.op_tests/triton_tests/attention/test_sol_tilt.py(new) coverssol_q_abs_max,sol_jensen_cap,sol_tilt_factors,sol_tilt_planesand the parameter builders:torch.compile(fullgraph=True);sol_q_abs_maxcall inside a CUDA graph capture leaves the eager and compiled calls before the replay correct.It is not redundant: these operators are new, and no other test checks them against a reference.
op_tests/op_benchmarks/triton/bench_sol_tilt.py(new) times the tilt wrappers at Wan 2.2 shapes. README rule 17 requires a benchmark per Triton op. No other benchmark times these wrappers, and its numbers are the evidence for the tunedsol_tilt_factorvalues. The Jensen-cap and factors cases pass Q as a one-element view of its shape: those calls readq_abs_max, not Q, so the rotating pool is sized by what the call reads.