Repository navigation
Conversation
… at H=32 On gfx950, pa_prefill_sparse calls mla_gluon. For bf16 q and KV with 32 heads of a 512-wide latent, a new single-pass kernel now serves the call. One program computes one query row for all 32 heads. It copies each 64-key tile from the pool straight into LDS and runs the QK and PV MFMAs on it. mla_gluon still serves other shapes, has_invalid=True and calls with fewer than MIN_TOKENS rows. - Kernel: _gluon_kernels/gfx950/attention/pa_prefill_sparse.py, without a torch import. - Config: configs/gfx950/gluon/attention/pa_prefill_sparse/DEFAULT.json (MIN_TOKENS, BLOCK_K, num_warps). - At H=32, a row with no slots now writes zeros. mla_gluon does not write such rows. - Tests: H=32 in test_pa_prefill_sparse_gfx950 (an 8 GiB pool at T=16384), and test_pa_prefill_sparse_gfx950_single_pass (empty, short and partial rows into a NaN-filled out, with and without a sink). Signed-off-by: Rony Leppänen <[email protected]>
…er tile The QK mask's column index is built inside the tile loop instead of before it. The compiled kernel changes in instruction order and register count (6 more VGPRs, still 2 waves per SIMD); the output is bitwise equal. On MI355X at H=32 the kernel takes, against its previous time: - 0.944-0.952x with Triton 3.8 and 0.994-1.002x with Triton 3.7, on index lists captured from GLM-5.3-Flash prefill in SGLang (8,499 and 16,179 rows) and on synthetic lists whose rows hold up to 512 runs of 4 adjacent slots (8,192 and 16,384 rows); - 0.992-1.010x with Triton 3.8 on the generated tables of bench_sparse_attention_dsv4.py and test_mla_sparse_prefill.py. Signed-off-by: Rony Leppänen <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
…oo, and for small calls mla_gluon gets wrong The gfx950 single-pass kernel now also serves H=64, as two launches of its 32-head program, and calls with a sink below MIN_TOKENS rows. mla_gluon keeps the sink-free H=32 calls below MIN_TOKENS rows, which it gets right, and the shapes the kernel does not serve. On MI355X, mla_gluon on the calls that move: - H=64 (its bh64 regime) asserts unless T is a multiple of 64. With one key split it returns wrong output for every row of at most 128 keys (H=64 and 128, T=1024, rows of 1 to 2,046 keys). - With a sink and more than one key split, it adds the sink once per split. At T=1, H=32, with 128 keys of ones and a sink of log(128), it returns 1/3 where the answer is 1/2. At T=48 every row is wrong. At H=64 the two launches take 0.76-0.78x OPUS's time on index lists captured from GLM-5.3-Flash prefill (8,499 and 16,179 rows) and on synthetic lists (8,192 and 16,384 rows, and 8,192 after an 8,192-row prefix). On the one input of these that mla_gluon gets right (8,192 rows after the prefix), it takes 0.75-0.76x OPUS's time against the two launches' 0.78x. - _single_pass_unsupported(): why the kernel cannot serve a call, or None. - Tests: test_pa_prefill_sparse_gfx950_single_pass runs H=32 and 64 at T=300 and 48, with and without a sink; test_pa_prefill_sparse_gfx950 adds H=16 for the mla_gluon branch. Signed-off-by: Rony Leppänen <[email protected]>
…g-denominators test_pa_prefill_sparse_gfx950_single_pass's T=48 sink cases check that the kernel, not mla_gluon, serves them: mla_gluon splits each row's keys in two there and adds the sink once per split. With sinks from randn(H), that error is small next to rows of hundreds of keys. In a CPU estimate over 8 draws of the test's inputs, it exceeded the tolerance on 0 to 17 of the 48 rows. With randn(H) + 5 it does so on 26 to 33 rows in every draw. Signed-off-by: Rony Leppänen <[email protected]>
… every call it serves, at any T Sink-free H=32 calls below 64 query rows stayed on mla_gluon, which splits each row's keys over the CUs. On a device with fewer CUs (a CU_NUM setting or a compute partition) such a call runs in one key split, where mla_gluon leaves rows without keys unwritten. Every call the single-pass kernel serves now takes it, so MIN_TOKENS leaves the gfx950 config. The single-pass test runs with mla_gluon seeing 64 CUs, so a call routed back to mla_gluon fails it at any T. Signed-off-by: Rony Leppänen <[email protected]>
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
Accepted bf16 KV views can violate the new copy path’s alignment requirements, and zero softmax scaling can produce NaN outputs from masked scores.
2 open issues
What changed in this PR
Adds a single-pass Gluon path to pa_prefill_sparse on gfx950 for bf16 inputs with 32 heads and dimension 512. The public API stays unchanged, and other calls retain the existing dispatch.
Changes:
- Adds a kernel that shares KV loads across all 32 heads, supports an optional sink, and writes zeros for empty rows.
- Adds JSON launch settings and dispatch conditions for the new path.
- Extends tests for H=32, large KV offsets, and empty, short, and partial rows.
| File | Description |
|---|---|
op_tests/triton_tests/attention/test_pa_prefill_sparse.py |
Adds H=32 and ragged-row coverage; shares the row-generation helper. |
aiter/ops/triton/configs/gfx950/gluon/attention/pa_prefill_sparse/DEFAULT.json |
Defines the row threshold, tile size, and warp count. |
aiter/ops/triton/attention/pa_prefill_sparse.py |
Adds configuration loading, dispatch, and launch support. |
aiter/ops/triton/_gluon_kernels/gfx950/attention/pa_prefill_sparse.py |
Implements single-pass sparse attention with 64-bit row offsets. |
Review effort: Balanced
…kernel serves, H=64 too, and opus when pa_prefill_sparse cannot load backend="triton" now takes exactly the calls pa_prefill_sparse's gfx950 single-pass kernel serves (_single_pass_unsupported) within its own contract (one KV source, no split-K, out None or contiguous), and raises RuntimeError for the rest. Before, it also accepted q or unified_kv with an inner stride other than 1, and a unified_kv that is not 2-D. pa_prefill_sparse sent those to mla_gluon, which ignores those strides: on MI355X every row of a T=256, H=32 call came back wrong. Calls with a sink below MIN_TOKENS rows now run the kernel inside pa_prefill_sparse (merged from #7680), where mla_gluon added the sink once per key split. With #7680's H=64 support the triton backend serves H=64 too, and backend=None takes it for sink-free H=64 calls with at least MIN_TOKENS rows, as at H=32. Its choice at H=32 is unchanged. backend=None raised ImportError where pa_prefill_sparse's module cannot be imported (its gluon kernels need a Triton with gluon). It now runs opus there, and logs why once. Tests: test_triton_backend_rejects (q with inner stride 2, a 3-D unified_kv), test_default_backend_without_gluon, test_default_backend_gfx950 at H=32 and 64, and an H=64 one-source case in the sweep. Signed-off-by: Rony Leppänen <[email protected]>
… key equally, not NaN The single-pass kernel masks the scores of a partial key tile to -inf and then multiplies them by qk_scale, so softmax_scale=0 gave -inf * 0 = NaN, and a NaN output for every row with a partial last tile. _qk_scale now passes the smallest normal fp32 for a product in [0, that value): masked scores stay -inf and every key weighs 1, as at scale 0. Other scales pass the same value as before, to an unchanged kernel. Scaling the scores before the mask instead measured 1.07x the kernel time at H=32 on MI355X. test_pa_prefill_sparse_gfx950_single_pass also runs at softmax_scale=0. Signed-off-by: Rony Leppänen <[email protected]>
…f a row in one launch At H=64 the single-pass kernel ran twice, once per half of the heads, and each launch gathered every key. It now runs once with T * 2 programs: a row's two 32-head programs sit at program ids L and L + NUM_XCDS, on one XCD, so the second one's KV gathers can hit the first one's in L2. The last T % NUM_XCDS rows put their halves at adjacent ids. HEAD_GROUPS and NUM_XCDS are constexprs and T comes from the grid, so there is one compile per head count at any T; at H=32 (HEAD_GROUPS 1, NUM_XCDS 1) the instruction stream is unchanged. HEAD_GROUPS joins the kernel's name. Signed-off-by: Rony Leppänen <[email protected]>
…d/mla-sparse-prefill-triton-backend Brings in main up to 85ccf17 through #7680. Conflicts: - aiter/ops/mla_sparse_prefill.py: main routes the op through the plugin interface (#7791). mla_sparse_prefill now dispatches as mla_sparse_prefill_v41 does: enabled providers first, then a native fallback that picks triton or opus from backend=. The routed op (_mla_sparse_prefill_routed, opus) and its contract are unchanged. - op_tests/test_mla_sparse_prefill.py: docstrings. main replaced --total_tokens with --window and passes total_tokens=n, so the gfx950 triton candidate now keys on an empty kv_indices_extend (what the triton backend requires) instead of total_tokens == 0. tests/test_plugin_routed_ops.py: the backend-pin test also covers backend="triton". Signed-off-by: Rony Leppänen <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Negative softmax scales turn masked scores into +inf and invalidate the denominator for partial tiles, requiring scaling before masking and taking the maximum of the scaled scores.
1 open issue
4 resolved since last review
Review effort: Balanced
| s = gl.where((j * BLOCK_K + cols_c < n)[None, :], s, float("-inf")) | ||
| m_new = gl.maximum(m, gl.max(s, axis=1) * qk_scale) | ||
| p = gl.exp2(s * qk_scale - m_new[:, None]) |
|
No activity for 15 days, so this is now labelled |



Summary
On gfx950,
pa_prefill_sparsegets a single-pass Gluon kernel for bf16 q and KV with 32 or 64 heads of a 512-widelatent. It takes every call it serves, at any number of query rows.
mla_gluon, which serves these calls today.mla_gluon'sbh64path, which asserts unless T % 64 == 0 and gets rows of up to 128 keys wrong.bh64is correct: 0.4–1.6 % slower on the in-tree benchmark, 12–13 % with 1–2 GiB pools (Performance).Motivation
pa_prefill_sparseon gfx950 callsmla_gluon(..., min_kv_seq_len=float("inf"), has_pe=False). On that path (MI355X,main1eab5ae12c):bh16bn64,mla_gluon.py:26-27): heads are tiled into 16-head blocks, so two programs per query row gather thesame keys.
max(1, CUs // (T · head blocks))(:962): one split from T=65 at H=32 on 256 CUs, and at smallerT with fewer CUs (
CU_NUM, compute partitions).:155-156) and its output is never written.:675-686). T=1, q=0, 128 keys of ones, sink log 128:every output is 0.334, not 0.5.
bh64,:900)::932-933);(rel L2 0.31; H=128 the same).
min_kv_seq_len=infdisables the guard (:939-945) for the kernel'sgl.assume(num_iter >= 3)(:475). That thisassumption causes the wrong rows is a hypothesis.
The new kernel runs one program per query row for 32 heads:
sparse_mla_fp8.pyplaces a row's head blocks, so the second one'sKV gathers can hit the first one's in L2 (Performance);
It is a separate kernel, not a regime of
mla_gluon:mla_gluonis a split-KV decode kernel with a second reducestage; this one is single-pass over one CSR index list.
Scope: no caller reaches gfx950's
pa_prefill_sparsetoday. #7681 (stacked) makes itmla_sparse_prefill's defaultfor GLM-5.3-Flash at attention TP 2 (32 heads per rank); at TP 1 (64) only with
backend="triton".Changes
aiter/ops/triton/_gluon_kernels/gfx950/attention/pa_prefill_sparse.py(new):H,HEAD_GROUPS,BLOCK_KandHAS_SINK;HEAD_GROUPSprograms per query row,Hheads each. A row's programs areNUM_XCDSprogram ids apart; the lastT %
NUM_XCDSrows run theirs at adjacent ids;aiter/ops/triton/configs/gfx950/gluon/attention/pa_prefill_sparse/DEFAULT.json(new):BLOCK_K64,num_warps4.aiter/ops/triton/attention/pa_prefill_sparse.py, gfx950 branch:unified_kvis 2-D, both inner strides are 1 andhas_invalidis notTrue(_single_pass_unsupported), with or without a sink, at any T;NUM_XCDSfromget_num_xcds();mla_gluon, as before;equal; the effect on time is under "Validation and unverified scope".
dcbb9eaf7a:softmax_scale=0gave NaN in every row whose last tile is partial.-infbefore scaling, and-inf * 0is NaN._qk_scalepasses the smallest normal fp32 for a product in [0, that value), so masked scores stay-infandevery key weighs 1, as at 0. The kernel and the value passed at any other scale are unchanged.
03e16bc83e: H=64 runs as one launch with two head groups instead of one launch per 32 heads.kernel name gains
HEAD_GROUPS_1.Performance (if applicable)
bench_sparse_attention_dsv4.py --shapes prefill, bf16, no sink; slots drawn uniformly at random. Each backend's timeis the mean of 50 back-to-back launches.
main, ms)H=64:
gluoncolumn (mla_gluoncalled withmain's arguments). After: itspa_prefill_sparsecolumn. Both from one process; means of two processes.
bh64is correct on these inputs: T is a multiple of 64 and every row has 2,048 keys. Per process the kernel takes1.004–1.016×
bh64's time.(+12.6 %).
dcbb9eaf7a), with the same commands: 0.85–0.88× the time with the table'spools, 0.71–0.77× with 1–2 GiB pools.
rocprofv3,TCC_EA0_RDREQ_{32B,64B,128B}), Q 8,192 on a 1 GiB pool, in multiples of thelisted keys' bytes: two launches 2.03×, one launch 1.03×, one launch with a row's programs at adjacent ids 2.03×.
bh64asserts; thekernel takes 1.11× the time of
main's OPUS there ([Triton/Gluon] mla_sparse_prefill: triton backend on gfx950, the default at H=32 without a sink #7681).Testing
Documentation
Dependencies
Breaking Changes
None in the API. On gfx950:
mla_gluon's within the test tolerance, wheremla_gluon's are correct.PR Self-Review
Reviewed revision
2718e0df2b928c4092f8784d119f1154622e508cBehavior and intent
unified_kv, unit inner strides andhas_invalidnotTruerun the single-pass kernel instead ofmla_gluon, at any T, with or without a sink. Other calls keepmla_gluon.mla_gluonis slower (H=32), counts the sink once per key split, leaves rows without slots unwrittenat one split, and at H=64 asserts unless T % 64 == 0 and gets rows of up to 128 keys wrong.
Validation and unverified scope
Hardware: MI355X (gfx950, 256 CUs).
Image:
vllm/vllm-openai-rocm:nightly-rocm100-1648fefab91204f3b15bf8062217316f07f2c4bb(Triton 3.8.0). AITER isthis branch or
main(1eab5ae12c) from source.This revision is
03e16bc83ewithmain85ccf1794dmerged; this PR's diff is unchanged. Results below were takenat
03e16bc83eunless stated.python -m pytest op_tests/triton_tests/attention/test_pa_prefill_sparse.py:03e16bc83eand at this revision (with [Triton/Gluon] mla_sparse_prefill: triton backend on gfx950, the default at H=32 without a sink #7681 on top,which does not change the files tested);
dcbb9eaf7a, with this test file: the 8[*-zero-scale]cases fail (83–85 % of the elementsmismatch), the other 21 pass;
mainwith this PR's test file: the 16test_pa_prefill_sparse_gfx950_single_passcases fail, the other 13 pass.AssertionError: mla_gluon[bh64] requires batch_size divisible by 64, got 48(and 300).Mutations of this branch, each failing only the named cases of
test_pa_prefill_sparse_gfx950_single_pass:[300-64-True-*],[48-64-True-*];[*-64-*-scaled](atsoftmax_scale0 every key weighs 1,so the output does not depend on q);
[300-64-*](T=300 leaves 4 such rows, T=48 none);mla_gluon:[48-32-False-*];_qk_scalepassing 0 through, as beforedcbb9eaf7a: the eight[*-zero-scale]cases (run atdcbb9eaf7a).The
mla_gluonvalues in Motivation come from probes ofmain'spa_prefill_sparseagainst a reference softmax.Benchmark revisions:
mainand this branch atd25bc29d22, one after the other on one GPU. At this revision those callscompile to the same instructions and launch configuration.
03e16bc83e, on another MI355X; the OPUS ratio with this revision's kernelagainst
main85ccf1794d's OPUS.Second commit (column index per tile) against the first commit's kernel, H=32:
bench_sparse_attention_dsv4.pyandtest_mla_sparse_prefill.pydcbb9eaf7a's alternative, scaling the scores before the mask, also removes the NaN, but took 1.066–1.074× thekernel's time at H=32 (the same harness as the first two rows; Triton 3.8.0, 3 processes per input set).
Unverified:
mla_gluonfor calls below 64 query rows, which now take the kernel;mla_gluonand its behaviour above (other H, non-unit inner strides);i %
get_num_xcds(). The output does not depend on it (bitwise equal with a row's programs at adjacent ids);PR-specific question
The only new key is
_pa_prefill_sparse(BLOCK_K64,num_warps4) inaiter/ops/triton/configs/gfx950/gluon/attention/pa_prefill_sparse/DEFAULT.json._single_pass_config()reads it, for the single-pass kernel's launch; it does not decide which calls take thekernel.
_single_pass_unsupporteddecides: gfx950, H=32 or 64, D=512, bf16 q andunified_kv, a 2-Dunified_kvof widthD, unit inner strides for both and
has_invalidnotTrue.test_pa_prefill_sparse_gfx950runmla_gluonand pass), other dtypes or strides andhas_invalid=Truerunmla_gluon; gfx942 and gfx1250 areuntouched.
mla_gluonfor H=16 would pin it.Changed op tests
op_tests/triton_tests/attention/test_pa_prefill_sparse.py:test_pa_prefill_sparse_gfx950runs H=16, 32 and 64 (was 64):mla_gluon;main: T is a multiple of 64 and no row is empty or short.test_pa_prefill_sparse_gfx950_single_pass(new): H=32 and 64, T=300 and 48, with and without a sink, atsoftmax_scale512^-0.5 and 0.out.tolerance.
mla_gluonsees 64 CUs (get_num_smspatched), as underCU_NUMor a compute partition: at H=32 it then runs onekey split and leaves the empty rows unwritten, and at H=64 it asserts.
main. No existing test has empty rows on gfx950._ragged_rowsis moved out oftest_pa_prefill_sparse_single_source, unchanged, so that both tests use it.AI assistance (Claude) was used for this PR; the change, tests and measurements were reviewed and run by the submitter.