Repository navigation
[Triton/Gluon] [CI] [Kernel] Gluon paged-decode attention with sigmoid output gate and group-128 FP8 epilogue (gfx950) - #5715
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
PR title tags & labels: |
bbcb468 to
c4ff48e
Compare
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Critical and moderate validation issues remain, including gfx950 FP8 dtype handling, layout assumptions, scale validation, and embedded tuning choices.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (4)
What changed in this PR
Adds a gfx950 Gluon paged-decode attention operator that fuses sigmoid gating with optional group-128 FP8 quantization.
Changes:
- Added long- and short-context kernels with wrapper dispatch and validation.
- Added correctness tests and performance benchmarks.
- Added documentation and CI timing registration.
| File | Summary |
|---|---|
op_tests/triton_tests/attention/test_paged_attention_output_gate.py |
Correctness and dispatch coverage; add distinct non-unit scale values to test dequantization. |
op_tests/op_benchmarks/triton/bench_paged_attention_output_gate.py |
Benchmark tooling; baseline currently measures four launches rather than the documented three. |
aiter/ops/triton/gluon/README.md |
Documents the new operator. |
aiter/ops/triton/attention/paged_attention_output_gate.py |
Public API and dispatch; address fnuz rejection, query/CSR layout validation, scale validation, tuning configuration, and fallback documentation. |
aiter/ops/triton/_gluon_kernels/gfx950/attention/paged_attention_output_gate.py |
Long-context kernel; include specialization values in repr. |
aiter/ops/triton/_gluon_kernels/gfx950/attention/paged_attention_output_gate_short_context.py |
Short-context kernel; include specialization values in repr. |
.github/scripts/split_tests.sh |
CI test timing registration. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
a358f55 to
82876ff
Compare
…oup-128 FP8 epilogue (gfx950)
WIP: first body only, not yet run on hardware.
Adds paged_attention_output_gate_group_fp8_quant for Qwen3-Next-style
full-attention layers. Replaces three launches -- paged decode attention,
out * sigmoid(gate), and the per-group activation quant the next GEMM needs --
with two, by folding the gate and the quant into the split-K merge the attention
already performs.
This is a new op rather than a flag on an existing one because no aiter
paged-decode op has this KV layout. pa_decode and pa_decode_gluon are block-table
ops (kv_block_size in {16,64,1024}); this takes a CSR index list at page_size 1.
pa_decode_sparse takes exactly that CSR layout but is MLA-style (K == V), so it
cannot express distinct K and V caches.
No batch table: the row comes from gl.program_id(0) and the context bound from
kv_indptr, so one binary serves any batch size and any context length. That
matters because a CUDA graph capture asks for non-power-of-two decode batches
(12, 24, 40, 48, 56 ...) and dispatch happens once at capture -- a miss is baked
into the captured graph permanently. HEAD_TILE=16 with masking makes the head
count a runtime value too.
Two guards the reference implementation lacks: the gate is indexed through its
row stride rather than assuming stride(0) == heads*HEAD_DIM, and the support
predicate checks the cache dim stride the gather relies on.
max_context is accepted as a launch-geometry hint only. It is not a compile-time
constant and never clamps the live length.
The epilogue's three BF16 rounding boundaries (attention -> bf16 -> fp32,
sigmoid -> bf16 -> fp32, product -> bf16, then the group absmax) are contract;
the test reproduces them exactly.
Still to do before this is reviewable:
* second body for short contexts at low batch, selected by a max_context range
check -- measured 17-21% faster below bs~32 at 8K context, while this body is
2.0x faster at 64K
* op benchmark
* run the test suite on gfx950; nothing here has touched hardware yet
Signed-off-by: Rita Brugarolas Brufau <[email protected]>
Exposes run_benchmark(args) and emits the CSV/PNG the bench harness expects. --compare also times the three launches the op replaces so the speedup can be read directly. Times with CUDA-graph capture rather than triton.testing.do_bench, which has no graph mode in this Triton. At decode shapes the launch overhead dominates and, worse, the distortion is not common-mode: the fused op is two launches and the stock composition is four, so do_bench understates the speedup. Measured at bs=8 / ctx 8192: do_bench reads 26.6 vs 34.7 us (1.31x), graph-captured reads 9.85 vs 20.85 us (2.12x). --do-bench restores the conventional path. The bandwidth metric reports KV traffic (tokens * context * 256 * 2 bytes) over the measured time; below ~8 tokens the kernel is latency-bound and the number is a small fraction of peak by construction. Signed-off-by: Rita Brugarolas Brufau <[email protected]>
…_gate, selected by range check Adds the short-context body for paged_attention_output_gate_group_fp8_quant and picks between it and the existing long-context body on max_context. Both are now GPU-validated on gfx950 (MI355X). Why two bodies. They compute the same thing and differ only in how the work is decomposed. The short body gives four producer waves 64 QK channels each and uses the native 4x64x64 MFMA, so four query heads are not padded to a 16-row tile; the long body pays that padding but amortises it over a much longer context. Measured on gfx950 they are a dead heat at real context 32768 -- the short body is up to 24% faster at bs=1 / 8K and the long body ~4% faster at 64K -- so the split is at 32768, on the caller's capacity hint. max_context=None takes the short body. Body choice is never a correctness question: an input the short body cannot express (head count not a multiple of 4, a cache whose row pitch is not 16-element aligned) simply goes to the long one. Three deviations from the Artemis source this body was ported from: * No MAX_CONTEXT. The original clamps the live length to a constexpr capacity in both kernels, which silently truncates the context if the caller understates the capacity, and puts capacity into the compilation key. The live length here comes from kv_indptr and is never clamped, matching the long body. The one place capacity was load-bearing -- proving a page-index buffer load fits a 32-bit offset -- is proved host-side from kv_indices.numel() and arrives as a plain constexpr predicate, the way narrow_offsets already did. A test runs a 40960-token context behind a max_context of 1024 and checks the full result. * quant_dtype=None. The original always writes the FP8 output and its scales. That is not merely a wasted store here: the producer stages sigmoid(gate) in the gated buffer as scratch, and with no FP8 epilogue the launcher has nothing but that buffer to point the FP8 stores at. They are compiled out under a QUANTIZE constexpr instead. * USE_SCALES. k_scale/v_scale are optional, as they are for the long body, rather than asserted present. ROWS stays a gl.constexpr in this body -- it selects the K/V staging strategy -- but every arm is derived from it arithmetically rather than from a table, so non-power-of-two decode batches compile and run like any other size. Verified at 3, 5, 6, 7, 9, 12, 24, 40, 48, 56, 96, 100; Artemis's attention_output_m16.py fails to compile at several of these. Validation on gfx950: * 172/172 op tests pass. The parametrization now carries a max_context on each side of the crossover, so every shape -- including the non-power-of-two batches 12, 24, 40, 48, 56 -- runs through both bodies, and a new test asserts the two agree with each other as well as with the fp32 reference. * Head-to-head against Artemis attention_16k_m1_m2_m8_m32.py at ctx 8192, capacity 8192, heads 4: identical error against the fp32 reference at every batch (0.00185-0.00193, matching to five decimals), timing ratio 0.99-1.03 across bs 1, 2, 8, 16, 32, 64. Still to do before this is reviewable: * op benchmark Signed-off-by: Rita Brugarolas Brufau <[email protected]>
The short body accepts HEADS in (4, 8, 16) -- its QK mfma is 4x64x64 over the head axis, so the count must be a multiple of 4 and a power of two -- and the long body masks a 16-row tile and takes 1..16. Only 4 and 8 were parametrized, so the 16 arm was reachable but untested in CI. 253 passed. Signed-off-by: Rita Brugarolas Brufau <[email protected]>
…ction
Two gaps, both in tests we wrote ourselves, so both are ours to fix.
1. The support predicate admits 0 < heads <= 16, but the suite only covered
{4, 8, 16}. Qwen3-Next has 16 query heads, so TP1/2/4/8/16 give a rank
16/8/4/2/1 of them -- heads=2 (TP8) and heads=1 (TP16) were admitted and
untested. Verified all of 1,2,3,4,5,8,16 against the fp32 reference (rel err
0.0016-0.0017, same band as the covered counts), so the predicate was honest;
the parametrization is now {1, 2, 3, 4, 8, 16}, with 3 as a non-power-of-two
the predicate also admits.
2. Nothing pinned WHICH body runs. Body choice is a three-condition performance
contract -- max_context > 32768, heads not in (4,8,16), and cache alignment --
and any of them could have changed silently. test_body_selection_contract now
asserts all three.
The head-count condition is worth stating out loud because it is a performance
cliff, not just a detail: the short body's QK mfma tiles 4x64x64 over the head
axis, so a TP8 deployment (2 heads/rank) never gets it, even at short context
where it is ~24% faster. Correctness is unaffected -- body choice never changes
the answer, which is now covered by heads 1..16 in test_matches_reference -- but
such a deployment gets less of the win, and that should be visible in the tests
rather than discovered in production.
Expanding the head coverage also exposed that test_bodies_agree asserted the
short body was selected. That holds only for _SHORT_HEADS, so it now skips where
there is no second body to compare against, rather than re-testing selection.
488 passed, 9 skipped.
Signed-off-by: Rita Brugarolas Brufau <[email protected]>
split_tests.sh shards by expected runtime and defaults unknown files to 15s. The new test measures 7.6s wall (488 passed, 9 skipped) on an idle MI355X; registered at 20 to leave headroom on a loaded runner. Signed-off-by: Rita Brugarolas Brufau <[email protected]>
…s README Adds the Quick Reference row and a detail section matching the format the other two attention kernels use. The bandwidth figure is the output of the command the row cites (bench_paged_attention_output_gate.py --context 8192 --compare --metric bandwidth, tokens=64), not a number from elsewhere, since that column is documented as the perf of the typical test. Signed-off-by: Rita Brugarolas Brufau <[email protected]>
… benchmark baseline Four review findings, all confirmed against the code. Reject float8_e4m3fnuz. gfx950 reads OCP e4m3 natively and fnuz is the gfx942 encoding, so the same bytes denote different values; accepting it dequantized silently wrong rather than failing, and it was never tested. Rejected as both cache and output dtype, matching pa_decode_sparse. Require query.stride(2) == 1. The long body adds the head-dim offset unscaled, and only the short body receives a QUERY_DIM_STRIDE, so a transposed query produced wrong attention whenever the long body was selected. The predicate already guarded the cache and gate dim strides; the query was missed. Require contiguous kv_indptr/kv_indices. Both bodies walk them as flat pointer offsets, so a strided view read the wrong row boundaries or page slots. Fix the benchmark baseline. --compare timed 'flat * torch.sigmoid(gate)', which is two kernels, against a caller that runs one fused sigmoid-gate multiply -- four launches rather than the three documented, inflating the baseline by a launch this op does not remove. Now uses aiter's own fused_sigmoid_mul. The stock column moves from +4.2%/+16.6% above the PR's measured baseline to within 0.9% of it at every cell, and the reported speedup from +4.4%/+21.2% overstated to within 3.6%. The PR's own numbers were always measured against the fused composition and do not change. Tests: 489 passed, 9 skipped on gfx950. Signed-off-by: Rita Brugarolas Brufau <[email protected]>
82876ff to
b63d2cb
Compare
The call arguments were hand-wrapped; black's magic trailing comma explodes them one per line. Formatting only, no behaviour change. This was the sole cause of the red CI: black failing made the Checks workflow fail, which check_signal.sh gates on, which failed check-signal in three workflows and skipped every job behind the Aiter test gate. Signed-off-by: Rita Brugarolas Brufau <[email protected]>
|
On the benchmark baseline — fixed in Flagging this here because there's no inline thread on that file: the Copilot review's file summary noted "baseline currently measures four launches rather than the documented three." That was correct.
It now uses aiter's own
The numbers in the PR body do not change — they were always measured against the fused three-launch composition, which is what the target caller actually runs. To be precise about the size of the error: the baseline itself was inflated by +4.2% to +16.6%, worst at low batch where launch count dominates. That compounded with a small |
vgokhale
left a comment
There was a problem hiding this comment.
Review: PR #5715 — Gluon paged-decode attention with sigmoid output gate + group-128 FP8 epilogue (gfx950)
This is a well-built kernel and the most careful of the recent gfx950 Gluon wrappers — the support probe, fp8-encoding handling, two-body dispatch, repr coverage, and tests are all in good shape. There are two gaps to fix before merge, both import-safety/gating issues with a merged precedent to copy (fused_gdn_prefill_qkvz.py / gemm_a16w16.py).
What's solid
_supported() -> (bool, reason)probe (L74), documented as "callers should fall back rather than assert on False" — the-O-safe, caller-friendly pattern, plus aValueErroron direct misuse (L195).- Correct fp8 encoding handling:
e4m3fnuzis explicitly rejected (L101) rather than reinterpreted, with an accurate note that fnuz is the gfx942 encoding and the same bytes would dequantize wrong on this gfx950 body. This is exactly the arch-correctness care the fp8 path needs. - Two-body design (rule 5): main vs short-context bodies selected by one documented range check (
_short_body_selectedL131, dispatched at L207), with a measured rationale. One wrapper, one place to look — not a scatter. - Rule 1 (repr): all four launched kernels (
_attention_partials,_merge_gate_quantize,_short_attention_partials,_short_finish) carryrepr=; device helpers are exempt. - Tests / bench / docs complete: clean dtypes (bf16 + fp8 e4m3fn, no fp16/fp32 output), an explicit fnuz-rejection test, body-selection coverage, a benchmark, the Gluon README registration, and CI timing. Not re-exported by
attention/__init__.py, so the blast radius of issue 1 is limited to direct importers.
1. Blocker — top-level Gluon import defeats the probe
The wrapper imports all four kernels at module top level, unguarded:
# aiter/ops/triton/attention/paged_attention_output_gate.py:45
from aiter.ops.triton._gluon_kernels.gfx950.attention.paged_attention_output_gate import (
_attention_partials, _merge_gate_quantize,
)
from aiter.ops.triton._gluon_kernels.gfx950.attention.paged_attention_output_gate_short_context import (
_short_attention_partials, _short_finish,
)Each body module does from triton.experimental import gluon at its own top level, so import aiter.ops.triton.attention.paged_attention_output_gate eagerly pulls the Gluon dialect and raises ImportError on any build without it (Triton < 3.8, the ROCm 3.7 backport, non-gluon platforms).
This defeats the module's own design: paged_attention_output_gate_supported() exists so callers "fall back rather than assert" — but if importing the module already crashed, a cross-arch dispatcher can never reach the probe. Milder than #5520 (not re-exported by __init__), but the same class.
Fix: defer the four kernel imports to the launch sites, behind the gfx950 branch — the fused_gdn_prefill_qkvz.py / gemm_a16w16.py pattern (lazy import inside the function body).
2. Blocker — no Triton >= 3.8 gate, and both bodies use the 3.7-fragile ops
_supported() gates on get_arch() and shape/dtype, but has no version check. Both bodies are built from the Gluon ops that miscompile on ROCm's 3.7-backported dialect — gl.BlockedLayout (x6 / x8) and gl.amd.slice / gl.amd.cdna* (x14 / x19). On a gfx950 box with 3.7-backport Gluon, import triton.experimental.gluon succeeds (so nothing catches it) and the kernel then miscompiles.
Fix: add the >= 3.8 check to _supported(), mirroring #5606's _gluon_supported() — ideally folded into the same probe so this and issue 1 land together.
Minor
Head coverage [1, 2, 3, 4, 8, 16] is dense at the low end, but defensible: the stated goal is to cover every head count the HEAD_TILE = 16 predicate admits, and each exercises a different masking path rather than a scaled size — distinct-regime coverage, not a power-of-2 ladder. Low priority.
Summary
Strong kernel — probe, fnuz rejection, two-body dispatch, repr, and tests are all where they should be. The two blockers are the same pair seen on the other recent gfx950 Gluon ops: move the Gluon imports off the module top level into the launch sites, and add the >= 3.8 gate to _supported(). Both are small and both have a merged precedent to copy.
Meta-note for the team: across the recent gfx950 Gluon wrappers, the _supported() probe and validation are now consistent, but the lazy-import + version-gate that fused_gdn_prefill_qkvz established keeps getting dropped. A shared gluon-dispatch helper (or a review checklist item) would stop each new op from re-introducing these two gaps.
|
@rbrugaro-amd my review comment is now almost 2 weeks old and isn't addressed. Is this PR still relevant? |
# Conflicts: # .github/scripts/split_tests.sh
Replaces the FILE_TIMES entry this PR previously added to split_tests.sh. Upstream moved per-file timings into .github/split-test-times/<type>.tsv in ROCm#6246, explicitly to reduce the merge conflicts that a hand-edited table in the script kept producing -- which is exactly what this PR hit twice. 20s is the measured runtime rounded up for headroom on a loaded runner. Signed-off-by: Rita Brugarolas Brufau <[email protected]>
Two review blockers, both with a merged precedent in fused_gdn_prefill_qkvz. Defer the kernel imports. The wrapper imported all four Gluon bodies at module scope, so importing it pulled the Gluon dialect and raised on any build without it -- which made paged_attention_output_gate_supported() unreachable on exactly the builds it exists to protect. The imports now sit inside each launch branch. Gate on the dialect, not just the arch. _gluon_supported() checks Triton >= 3.8, because ROCm backported an earlier incompatible Gluon into some 3.7 builds where the import succeeds and the kernel then miscompiles. The version check alone is not sufficient here. shared_memory_descriptor gained a public reinterpret partway through 3.8 development (previously _reinterpret), and these bodies use it; builds either side of that rename both report 3.8.0. The probe therefore also tests for the attribute, and the bodies now call the public name. Without the attribute check a pre-rename 3.8 build passes the version gate and fails at compile time -- which is what CI hit. Tests pin all three: the wrapper imports with the dialect blocked, the probe is satisfied on a supported toolchain, and a failing probe surfaces as a reason through the public predicate rather than an exception. Signed-off-by: Rita Brugarolas Brufau <[email protected]>
…tack Re-measured with the command the row cites (--context 8192 --compare, tokens=64) on ROCm 7.2.4 with the Triton aiter installs: 6468 GB/s, against 6530 on the ROCm 7.0 stack the figure was originally taken on. Signed-off-by: Rita Brugarolas Brufau <[email protected]>
|
@vgokhale thanks for the review, and apologies for the delay. Both blockers are addressed, along with the CI failure. Summary of what changed and the re-measured data. 1. Gluon imports deferred to the launch sitesThe four kernel imports moved off module scope into each launch branch, following Pinned by a test that makes 2.
|
| context | bs | Before (µs) | After (µs) | Speedup |
|---|---|---|---|---|
| 1 536 | 1 | 16.79 | 5.22 | 3.22x |
| 1 536 | 8 | 17.09 | 4.91 | 3.48x |
| 1 536 | 32 | 17.75 | 6.87 | 2.58x |
| 1 536 | 64 | 23.97 | 10.20 | 2.35x |
| 8 192 | 1 | 17.22 | 5.65 | 3.05x |
| 8 192 | 8 | 18.79 | 7.79 | 2.41x |
| 8 192 | 32 | 38.39 | 22.68 | 1.69x |
| 8 192 | 64 | 60.87 | 41.49 | 1.47x |
| 32 768 | 1 | 19.34 | 8.56 | 2.26x |
| 32 768 | 8 | 40.08 | 23.39 | 1.71x |
| 32 768 | 32 | 125.12 | 95.38 | 1.31x |
| 32 768 | 64 | 235.18 | 168.04 | 1.40x |
| 65 536 | 1 | 23.89 | 12.55 | 1.90x |
| 65 536 | 8 | 65.57 | 44.81 | 1.46x |
| 65 536 | 32 | 239.61 | 164.98 | 1.45x |
| 65 536 | 64 | 477.25 | 326.00 | 1.46x |
| 131 072 | 1 | 37.46 | 19.60 | 1.91x |
| 131 072 | 8 | 129.28 | 85.30 | 1.52x |
| 131 072 | 32 | 426.98 | 326.09 | 1.31x |
| 131 072 | 64 | 914.66 | 633.23 | 1.44x |
Geomean 1.77x over all 60 cells; range 1.06-3.48x.
The headline number moved, and it is not the new stack
The description currently claims geomean 1.97x. Restricted to the same power-of-two batch set that number came from, this stack measures 1.952x — unchanged. The drop to 1.77x is entirely from the benchmark also sweeping the non-power-of-two decode sizes a CUDA-graph capture actually requests (12, 24, 40, 48, 56), which geomean 1.546x and hold the weakest cells (131 072 / bs 40 is 1.06x).
Stating it that way rather than quietly keeping the old cell set: this op is slower at exactly the sizes its coverage argument is about. It is still a win at every cell measured, but a smaller one there.
Bandwidth and roofline
Traffic is bs * context * 256 * 2 and identical for both implementations at a given cell, so achieved bandwidth is runtime re-expressed against the hardware limit. MI355X HBM3E peak is 8.0 TB/s:
| achieved | % of peak | |
|---|---|---|
| this op | 6.78 TB/s | 85% |
| stock | 5.03 TB/s | 63% |
5.03 / 6.78 = 0.74, the long-context ratio in the table. At 85% of peak there is at most ~15% more available to any implementation.
Method
A graph holding one kernel costs ~13.9 µs to replay on this host regardless of the kernel, so each measurement captures 50 invocations per graph (per-invocation floor 1.80 µs). This matters for the comparison, not just the absolutes: do_bench has no graph mode here and the distortion is not common-mode — it inflates the fused op 3.51x and stock 2.17x at bs=8 / ctx 8192, reading 1.49x where graph capture reads 2.41x. --do-bench restores the conventional path.
Numerics
Against an fp32 reference, this op agrees to 0.00-0.01% where stock paged_attention_ragged on the FP8 KV path is 6.1-7.8% off. (On the ROCm 7.0 stack the same comparison read ~14%; the defect is smaller on 7.2.4 but still present.) Root cause and fix are in #5642, which is still open — the two columns are not computing the same thing to the same accuracy until it lands.


[Kernel] Gluon paged-decode attention with sigmoid output gate and group-128 FP8 epilogue (gfx950)
Summary
Adds
paged_attention_output_gate_group_fp8_quant, a Gluon paged-decodeattention op for gfx950 whose epilogue applies a sigmoid output gate and
optionally emits group-128 FP8 alongside the BF16 result.
It replaces three launches with two at the Qwen3-Next full-attention
boundary — paged decode attention, then
out * sigmoid(gate), then theper-group activation quant the next GEMM consumes — by folding the gate and the
quant into the split-K merge the attention already performs.
Motivation
aiter has no op that fits this shape. Checked at HEAD:
pa_decode,pa_decode_gluonkv_block_size ∈ {16,64,1024}page_size = 1with a CSR index list; and neither has an epilogue seam — the store is a baretl.storein eight kernel bodiespa_decode_sparsepage_size = 1✓[pages, 2D]pool and testing three candidate references, onlyK = V = kv[:, :D]matches (mean rel 0.0019; readingV = kv[:, D:]is off by 1.48). It cannot express distinct K and V caches.So there is currently no separate-K/V CSR paged-decode op in aiter at all,
with or without an epilogue. That gap is worth filling independently of the gate.
Both halves of the epilogue already exist here, unfused.
fusions/fused_sigmoid_mul.pyis exactlyout * sigmoid(gate);_triton_kernels/quant/fused_fp8_quant.py::_fp8_quant_opis the samemax(abs)/FP8_MAXgroup formula with a1e-10floor. This op folds both into amerge that is already reading the partials, so they cost no extra pass over
[tokens, H*256].Emitting
(fp8, scales)is an established argument in this repo.fusions/attn_res.py:352 attn_res_gate(..., out_quant_dtype=None)makes it inits own docstring — "an
(fp8, scale)pair a GEMM can consume directly insteadof a BF16 tensor that each consumer quantizes for itself." This op follows that
convention, and the FP8 output is opt-in via
quant_dtype=None.Changes
_gluon_kernels/gfx950/attention/paged_attention_output_gate.py(numerator, denominator, maximum)partials, plus the merge carrying the gate + group-FP8 epilogue_gluon_kernels/gfx950/attention/paged_attention_output_gate_short_context.pyattention/paged_attention_output_gate.pypaged_attention_output_gate_supported() -> (bool, reason)op_tests/triton_tests/attention/test_paged_attention_output_gate.pytorch.testing.assert_close,pytest.skipoff-gfx950op_tests/op_benchmarks/triton/bench_paged_attention_output_gate.pyrun_benchmark(args), CSV + PNGNo tuned config JSON: no
pa_*op in the tree ships one, andconfigs/CLAUDE.mdforbids reusing the GEMMM_LEQ_x/M_GEQ_xscheme forattention.
API
Two bodies, one range check.
max_context <= 32768selects theshort-context body, above it the long-context one; they differ in the split-K
decomposition, which is what the two regimes want differently.
max_contextisa body selector only — it never clamps, the live length always comes from
kv_indptr.Neither body is specialised to batch.
BATCHis not a kernel constant inthe long body (the row comes from
gl.program_id(0)), so one binary serves anybatch size at any context length.
That matters for coverage: a CUDA graph capture asks for decode
batches of 1, 2, 4, 8, 12, 16, 24, 32, 40, 48, 56, 64, and
dispatch happens once at capture — a miss is baked into the captured graph
permanently rather than retried per step. The test parametrizes over exactly
those sizes.
Performance
MI355X (gfx950), ROCm 7.0, Triton 3.8, torch 2.9.0a0. Qwen3-Next-80B-A3B shapes:
H=4,head_dim=256,page_size=1, fp8_e4m3 KV.Method. A CUDA graph holding one kernel costs ~9.3 µs to replay on this host
regardless of the kernel, so every measurement captures 50 invocations per graph
(live floor 1.70 µs). This matters for the comparison and not just the absolute
numbers:
triton.testing.do_benchhas no graph mode in this Triton, and thedistortion is not common-mode — the fused op is two launches and the stock
composition is four — so
do_benchreads this as 1.31× where graph capture reads2.12×. The shipped benchmark graph-captures by default;
--do-benchrestores theconventional path.
Configuration: vs. the three launches this op replaces —
paged_attention_ragged(what SGLang's aiter backend calls today) + a sigmoid-gate multiply + a group-128
activation quant. Microseconds per decode step for one attention layer,
H=4,head_dim=256,page_size=1, fp8_e4m3 KV.34 (context, batch) cells, 3 rounds each with measurement order shuffled and the
fixture seed varied per round; live floor 1.70 us and no cell within 2x of it.
Representative batches shown.
Geomean 1.97x over all 34 cells; range 1.24-3.41x.
Bandwidth utilisation and roofline
The roofline shows why the long-context ratio settles where it does. Traffic is
bs * context * 256 * 2bytes and is identical for both implementations at agiven cell -- same bytes, same gather. Achieved bandwidth is therefore just
traffic / time, i.e. the same fact as runtime re-expressed against the hardwarelimit. It is reported because it answers what a raw speedup cannot: how much
headroom is left. MI355X HBM3E peak is 8.0 TB/s, and at the largest cells:
4.82 / 6.52 = 0.74, which is exactly the long-context ratio in the table above.
At 81% of peak
there is at most 19% more available to any implementation, so the asymptotic win
is gather efficiency, not fusion. Below bs~8 the kernel is latency-bound rather
than bandwidth-bound (9% of peak at bs=1) -- only a few MB to move, and the limit
is occupancy and launch, which is why the fused epilogue matters most there.
Testing
torch.testing.assert_close,over batch ∈ {1,2,4,8,12,16,24,32,40,48,56,64,128}, heads ∈ {4,8,16},
context ∈ {1,129,1024}, a
max_contexton each side of the crossover soboth bodies are exercised, with and without
quant_dtype, plus anon-contiguous-gate case, a case proving
max_contextnever clamps, aboth-bodies-agree case, and predicate coverage.
488 passed, 9 skipped on gfx950 (the skips are heads 1/2/3, which
have no short-body path, and say so). Correctness is additionally established outside
pytest.skipon non-gfx950.FILE_TIMESentry added in.github/scripts/split_tests.sh(7.6 smeasured, registered at 20 for headroom on a loaded runner).
The epilogue's numerics are contract. Three BF16 rounding boundaries —
attention→bf16→fp32, sigmoid→bf16→fp32, product→bf16 — before the group absmax.
The test reproduces them exactly; an implementation that keeps the intermediates
in fp32 produces different FP8 codes.
Two guards the reference implementation lacked, both now asserted by tests:
the gate is indexed through its row stride rather than assuming
stride(0) == heads*256, and the support predicate checks the cache dim stridethe gather relies on.
Documentation
A Quick Reference row plus a detail section in
aiter/ops/triton/gluon/README.md, matching the format the other two attentionkernels use. The bandwidth quoted there is the output of the command that row
cites (
--context 8192 --compare --metric bandwidth, tokens=64: 6530 GB/s),since that column documents the perf of the typical test.
Dependencies
Breaking changes
None — new op, no existing signature touched.
Scope
arch_info;paged_attention_output_gate_supported()returns
(False, reason)elsewhere so callers fall back rather than crash.page_size = 1,head_dim = 256,heads ≤ 16, per-tensork_scale/v_scale,fp8 e4m3 KV. All checked by the predicate, all reported with a reason.
Reproduction
The measurements use a public base image plus one change — Triton upgraded to
3.8. The upgrade is required, not incidental: the Gluon launcher passes
llvm_fn_attrs=, which does not exist in Triton 3.7, and the first launch failswithout it.
Exact versions the numbers above were taken on:
lmsysorg/sglang-rocm:v0.5.19-rocm700-mi35x-202609102.9.0a0+git7bcbafe4ad99832+ this PRROCm 7.0 specifically. The same base is published for 7.2
(
...-rocm724-...); this op has not been validated there, and on ROCm >= 7.2SGLang additionally enables FP8 weight preshuffling, which changes surrounding
behaviour.
Numerical note on the stock baseline
The stock FP8-KV path is not numerically equivalent to this op: it diverges
from an fp32 reference by ~14% mean relative error (13.7–14.8% at every measured
cell), where this op agrees to 0.18–0.27%.
That is a defect in
paged_attention_ragged— it casts already-normalizedsoftmax probabilities to e4m3, where at
partition_size = 256they sit at ~2⁻⁸and are subnormal (
csrc/cpp_itfs/pa/pa_kernels.cuh:586-588,:633-647).It is already fixed: #5642.
The fix is timing-neutral, so every "Before" number in this PR stands as
measured. Verified directly on the same container before and after: FP8 kernel
time 13.49 → 13.51 µs at bs=1 and 59.68 → 59.50 µs at bs=64, i.e. within noise,
while the error drops 0.142 → 0.027 (5.2×) and the BF16 path is bit-identical.
The defect is a scaling choice with no instruction-count, branch or
data-movement consequence.
The two columns should still be read as not computing the same thing to the
same accuracy until #5642 lands.