Skip to content

[Triton/Gluon] [CI] [Kernel] Gluon paged-decode attention with sigmoid output gate and group-128 FP8 epilogue (gfx950) - #5715

Merged
vgokhale merged 13 commits into
ROCm:mainfrom
rbrugaro-amd:feat/paged-attention-output-gate
Oct 13, 2026
Merged

vgokhale merged 13 commits into
ROCm:mainfrom
rbrugaro-amd:feat/paged-attention-output-gate

Conversation

@rbrugaro-amd

@rbrugaro-amd rbrugaro-amd commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

[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-decode
attention 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 the
per-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:

existing op KV layout why it does not fit
pa_decode, pa_decode_gluon block-table, kv_block_size ∈ {16,64,1024} the target runs page_size = 1 with a CSR index list; and neither has an epilogue seam — the store is a bare tl.store in eight kernel bodies
pa_decode_sparse CSR, page_size = 1 ✓ MLA-style: K and V are the same tensor. Measured, not assumed — feeding a [pages, 2D] pool and testing three candidate references, only K = V = kv[:, :D] matches (mean rel 0.0019; reading V = 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.py is exactly out * sigmoid(gate);
_triton_kernels/quant/fused_fp8_quant.py::_fp8_quant_op is the same
max(abs)/FP8_MAX group formula with a 1e-10 floor. This op folds both into a
merge 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 in
its own docstring — "an (fp8, scale) pair a GEMM can consume directly instead
of 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

file content
_gluon_kernels/gfx950/attention/paged_attention_output_gate.py long-context body: split-K attention producing (numerator, denominator, maximum) partials, plus the merge carrying the gate + group-FP8 epilogue
_gluon_kernels/gfx950/attention/paged_attention_output_gate_short_context.py short-context body
attention/paged_attention_output_gate.py wrapper, body selection, paged_attention_output_gate_supported() -> (bool, reason)
op_tests/triton_tests/attention/test_paged_attention_output_gate.py fp32 reference, torch.testing.assert_close, pytest.skip off-gfx950
op_tests/op_benchmarks/triton/bench_paged_attention_output_gate.py run_benchmark(args), CSV + PNG

No tuned config JSON: no pa_* op in the tree ships one, and
configs/CLAUDE.md forbids reusing the GEMM M_LEQ_x/M_GEQ_x scheme for
attention.

API

paged_attention_output_gate_group_fp8_quant(
    query,            # [T, H, 256] bf16
    key_cache,        # [pages, 1, 256] fp8_e4m3
    value_cache,      # [pages, 1, 256] fp8_e4m3
    kv_indptr,        # [T+1] int32, true prefix sum
    kv_indices,       # [total] int32, per-token slots (page_size = 1)
    gate,             # [T, H*256] bf16
    *,
    scale: float,
    max_context: int | None = None,         # body selector; never clamps
    k_scale=None, v_scale=None,             # per-tensor
    quant_dtype: torch.dtype | None = None, # None -> skip the FP8 epilogue
) -> tuple[Tensor, Tensor | None, Tensor | None]
#    (bf16 [T, H*256], fp8 [T, H*256], fp32 scales [T, H*2])

Two bodies, one range check. max_context <= 32768 selects the
short-context body, above it the long-context one; they differ in the split-K
decomposition, which is what the two regimes want differently. max_context is
a body selector only — it never clamps, the live length always comes from
kv_indptr.

Neither body is specialised to batch. BATCH is not a kernel constant in
the long body (the row comes from gl.program_id(0)), so one binary serves any
batch 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_bench has no graph mode in this Triton, and the
distortion is not common-mode — the fused op is two launches and the stock
composition is four — so do_bench reads this as 1.31× where graph capture reads
2.12×. The shipped benchmark graph-captures by default; --do-bench restores the
conventional 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.

context batch Before (us) After (us) Improvement
1 536 1 16.81 5.15 3.26x
1 536 8 17.22 5.04 3.41x
1 536 32 17.78 7.05 2.52x
1 536 64 23.89 10.59 2.26x
8 192 1 17.50 5.92 2.96x
8 192 8 18.74 8.09 2.32x
8 192 32 39.28 22.89 1.72x
8 192 64 63.57 41.18 1.54x
32 768 1 19.74 8.60 2.29x
32 768 8 41.22 24.13 1.71x
32 768 32 119.28 95.81 1.24x
32 768 64 237.59 172.01 1.38x
65 536 1 23.69 12.49 1.90x
65 536 8 68.49 45.78 1.50x
65 536 32 222.82 167.56 1.33x
65 536 64 483.62 336.17 1.44x
131 072 1 37.42 19.23 1.95x
131 072 8 139.00 90.00 1.54x
131 072 32 480.82 333.73 1.44x

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 * 2 bytes and is identical for both implementations at a
given cell
-- same bytes, same gather. Achieved bandwidth is therefore just
traffic / time, i.e. the same fact as runtime re-expressed against the hardware
limit. 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:

achieved % of peak
this op 6.52 TB/s 81%
stock 4.82 TB/s 60%

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

  • Unit test added — fp32 PyTorch reference, 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_context on each side of the crossover so
    both bodies are exercised, with and without quant_dtype, plus a
    non-contiguous-gate case, a case proving max_context never clamps, a
    both-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
  • Benchmark added.
  • pytest.skip on non-gfx950.
  • FILE_TIMES entry added in .github/scripts/split_tests.sh (7.6 s
    measured, 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 stride
the 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 attention
kernels 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

  • No new third-party dependencies.

Breaking changes

None — new op, no existing signature touched.

Scope

  • gfx950 only. Guarded by arch_info; paged_attention_output_gate_supported()
    returns (False, reason) elsewhere so callers fall back rather than crash.
  • No CUDA path affected.
  • page_size = 1, head_dim = 256, heads ≤ 16, per-tensor k_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 fails
without it.

# Dockerfile
ARG BASE=lmsysorg/sglang-rocm:v0.5.19-rocm700-mi35x-20260910
FROM ${BASE}

# Gluon needs llvm_fn_attrs, added in Triton 3.8. The base ships 3.7.
ARG TRITON_VERSION=3.8.0
ARG TRITON_INDEX=https://download.pytorch.org/whl/nightly/rocm7.0
RUN python -m pip install --no-deps --force-reinstall --pre \
      --index-url "${TRITON_INDEX}" \
      "triton==${TRITON_VERSION}"
docker build -t pa-gate:local \
  --build-arg BASE=lmsysorg/sglang-rocm:v0.5.19-rocm700-mi35x-20260910 .

docker run --rm --device=/dev/kfd --device=/dev/dri \
  --security-opt seccomp=unconfined --group-add video --group-add render \
  --ipc=host --shm-size 32G -e ROCR_VISIBLE_DEVICES=0 \
  -v $PWD:/w -w /w pa-gate:local bash -lc '
    python3 -m pytest op_tests/triton_tests/attention/test_paged_attention_output_gate.py -q
    python3 op_tests/op_benchmarks/triton/bench_paged_attention_output_gate.py \
      --context 8192  --compare
    python3 op_tests/op_benchmarks/triton/bench_paged_attention_output_gate.py \
      --context 65536 --compare
  '

Exact versions the numbers above were taken on:

base image lmsysorg/sglang-rocm:v0.5.19-rocm700-mi35x-20260910
ROCm 7.0.0
torch 2.9.0a0+git7bcbafe
triton 3.8.0 (upgraded from the base's 3.7.0)
aiter 4ad99832 + this PR
GPU 1x MI355X (gfx950)

ROCm 7.0 specifically. The same base is published for 7.2
(...-rocm724-...); this op has not been validated there, and on ROCm >= 7.2
SGLang 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-normalized
softmax probabilities to e4m3, where at partition_size = 256 they 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.

@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
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; main branch always runs both MI35X and MI300X
multigpu 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: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 5715 --add-label <label>

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 opt this PR out.

@rbrugaro-amd
rbrugaro-amd force-pushed the feat/paged-attention-output-gate branch from bbcb468 to c4ff48e Compare September 22, 2026 04:10
@rbrugaro-amd
rbrugaro-amd marked this pull request as ready for review September 22, 2026 04:27
@rbrugaro-amd
rbrugaro-amd requested a review from a team September 22, 2026 04:27
@github-actions github-actions Bot changed the title [Kernel] Gluon paged-decode attention with sigmoid output gate and group-128 FP8 epilogue (gfx950) [Triton/Gluon] [CI] [Kernel] Gluon paged-decode attention with sigmoid output gate and group-128 FP8 epilogue (gfx950) Sep 22, 2026
@Boss2002n
Boss2002n requested a lite review from Copilot September 22, 2026 05:33

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.

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 High severity · 3 Medium severity

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.

@rbrugaro-amd
rbrugaro-amd force-pushed the feat/paged-attention-output-gate branch from a358f55 to 82876ff Compare September 22, 2026 20:38
…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]>
@rbrugaro-amd
rbrugaro-amd force-pushed the feat/paged-attention-output-gate branch from 82876ff to b63d2cb Compare September 22, 2026 20:50
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]>
@rbrugaro-amd

Copy link
Copy Markdown
Contributor Author

On the benchmark baseline — fixed in b63d2cbc6.

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.

_stock_composition used flat * torch.sigmoid(gate) — two kernels — against a caller that runs a single fused sigmoid-gate multiply, so --compare timed four launches and
inflated the baseline by a launch this op does not remove. The file contradicted itself too: "three launches" in the module docstring, "four" in _time_us.

It now uses aiter's own fused_sigmoid_mul, with a separate destination buffer since that op writes in place by default and the benchmark captures many invocations per graph.
Measured at ctx 8192:

bs stock before stock after reported speedup before → after
1 20.40 µs 17.35 3.58× → 3.06×
8 21.01 18.75 2.63× → 2.37×
32 41.65 39.47 1.81× → 1.71×
64 66.24 63.61 1.61× → 1.54×

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
fused-side difference between harnesses (~4% at bs=1). After the fix, the benchmark's stock column lands within 0.9%
of the PR's baseline at every cell and the reported speedup within 3.6%, so the shipped benchmark now reproduces the claimed table instead of beating it.

@zufayu
zufayu requested review from a team and vgokhale September 23, 2026 01:13

@vgokhale vgokhale 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.

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 a ValueError on direct misuse (L195).
  • Correct fp8 encoding handling: e4m3fnuz is 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_selected L131, 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) carry repr=; 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.

@vgokhale

Copy link
Copy Markdown
Contributor

@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]>
@rbrugaro-amd

Copy link
Copy Markdown
Contributor Author

@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 sites

The four kernel imports moved off module scope into each launch branch, following fused_gdn_prefill_qkvz. Importing the wrapper no longer pulls the Gluon dialect, so a caller can always reach the probe and fall back.

Pinned by a test that makes triton.experimental.gluon unimportable via a sys.meta_path hook and asserts the wrapper still imports.

2. _gluon_supported() — version gate, plus an API gate

Added following #5606, with the >= 3.8 version check you asked for. It needs a second gate, and the reason is the same thing that was failing CI.

shared_memory_descriptor gained a public reinterpret partway through 3.8 development — it was _reinterpret before — and these bodies use it. These kernels were developed against a pre-rename wheel, so they were calling the private name; they now call the public one, which is what upstream and ROCm's fork both ship today.

The catch is that builds on either side of that rename both report 3.8.0, so a version check cannot separate them. Without an attribute check, a pre-rename 3.8 build passes the gate and then fails at compile time with AttributeError — which is exactly what Shard 6 hit (486 failures, all in this file; the only survivors were the three tests that never compile a body).

So the probe checks both:

if not hasattr(shared_memory_descriptor, "reinterpret"):
    return False, f"this Gluon build predates shared_memory_descriptor.reinterpret (Triton {version})"

Net effect: on a lagging toolchain the op declines with a reason and the caller falls back, instead of dying inside the compiler. This is not a shim — there is no dual-spelling fallback; the kernels use the public name only.

Two tests cover the gate — the probe must pass on a supported toolchain (otherwise the whole suite is silently testing fallbacks), and a failing probe must surface as a reason through the public predicate.

3. CI timing registration moved

#6246 replaced the FILE_TIMES table in split_tests.sh with .github/split-test-times/<type>.tsv. Our entry moved there, which also removes the recurring conflict that motivated that change.

Validation

ROCm 7.2.4 with the Triton install_triton.sh provides — 3.8.0+amd.rocm7.2.0.git7cb7b059, the same build CI uses:

492 passed, 9 skipped. The skips are heads 1/2/3, which have no short-body path and say so.

Re-measured performance

Every number in the PR description was taken on ROCm 7.0, which this op no longer supports, so all of it was re-measured on the stack above with the shipped benchmark (--compare, graph-captured).

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.

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.

3 participants