Repository navigation
[Triton/Gluon] Add sigmoid output gate to pa_decode_gluon - #6842
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
b782a1a to
e319edb
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The fused benchmark can select an unsupported one-partition path, and the tuning storage and test locations violate repository requirements.
3 open issues
What changed in this PR
This PR adds optional sigmoid output gating to pa_decode_gluon, combining gating with the final attention reduction to avoid a separate elementwise launch.
Changes:
- Applies gating in the Triton PS reduce and rejects unsupported decode paths.
- Adds tests for strided gates, query lengths, partition counts, and path rejection.
- Adds fused and separate gate benchmark modes and a custom head-size option.
| File | Description |
|---|---|
op_tests/triton_tests/test_pa_decode_gluon.py |
Tests gated output and unsupported-path rejection. |
op_tests/op_benchmarks/triton/bench_pa_decode.py |
Adds gate comparison modes, head-size selection, and memory accounting. |
aiter/ops/triton/gluon/pa_decode_gluon.py |
Adds gate validation, dispatch, and sigmoid multiplication in PS reduce. |
Review effort: Balanced
NOT 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 |
a6b7293 to
8b36884
Compare
8b36884 to
21686bc
Compare
ffe352b to
399003a
Compare


Summary
This PR adds an optional
output_gateargument topa_decode_gluonthat applies the gate in the kernel that already writes the final output, so decode needs one fewer launch. Withoutoutput_gatenothing changes.Companion vLLM integration PR: vllm-project/vllm#65419
Motivation
Qwen3-Next-style gated attention (Qwen3.5 / Qwen3.8 full-attention layers) multiplies the attention output by
sigmoid(gate)beforeo_proj. Withpa_decode_gluonthat is a separate elementwise kernel after the decode: it reads the attention output and the gate, then writes the gated output back.Changes
pa_decode_gluon(..., output_gate=None):out * sigmoid(output_gate).output_gatemust matchoutputin shape and dtype and have stride 1 in its last dimension. A strided view is fine, for example the gate half of a fused[T, H, 2 * D]projection.[batch, query_length, num_kv_heads, query_group_size, head_size], like the output.paged_attention_decode_ps_reduce_kernel(Triton), after the partition merge. With a gate, the reduce always takes the Triton kernel, launched withnum_warpsfromconfigs/<arch>/gluon/attention/pa_decode_gluon/DEFAULT.json. The HIP reduce is not modified and stays the default without a gate.output_gateasserts unlessps=Trueandmax_context_partition_num > 1. That rules out one-shot calls (a single partition) and the non-PS v2 reduce; the caller applies the gate itself there._sigmoid_exp2from_triton_kernels/common/activation.py, in fp32.USE_OUTPUT_GATEis added to the reduce kernel; with the defaultFalse.Performance (if applicable)
Kernel time from
bench_pa_decode.pywith this PR's--output_gateand-d. Shape: Qwen3.8-27B decode (24 query heads / 4 KV heads, 256 head dim, bf16, 16-token pages),get_recommended_splitspartitions (≥ 2 up to 127 sequences at 4 KV heads). Each value is the median of 3 runs; runs agree within ~1.5 µs.python3 op_tests/op_benchmarks/triton/bench_pa_decode.py --backend gluon -b 64 -hq 24 -hk 4 -d 256 -sq 1056 \ -dtype bf16 -kv_cache_dtype bf16 -compute_type bf16 -output_type bf16 \ --output_gate fused # or: separate (before), none (no gate)out * sigmoid(gate)(µs)output_gate(µs)Testing
Documentation
Dependencies
Breaking Changes
None. Without
output_gatenothing changes.PR Self-Review
Reviewed revision
399003a034442f99115b1f6263cf615534b346b0Behavior and intent
pa_decode_gluongains an optionaloutput_gate, applied in the PS reduce; other paths reject it. Withoutoutput_gatenothing changes, except that the Triton PS reduce writes 0 instead of NaN for a zero-length sequence.Validation and unverified scope
MI355X (gfx950), this branch (main 75a36b8 merged in), on AITER v0.1.27 with this branch's files on top (main's AITER needs FlyDSL ≥ 0.5.0):
-k output_gate: 11 / 11 pass.Unverified: gfx942, where the gated
num_warpsis not measured (its config keeps 4).PR-specific question
Configuration keys. The new
pa_decode_gluon/DEFAULT.json(gfx950, gfx942) hasps_reduceandps_reduce_output_gate, each withnum_warps; only the Triton PS reduce launch reads it.ps_reduceis 4, thenum_warpsthat launch used before, so callers without a gate keep their launch, andps_reduce_output_gateis read only with a gate.Changed op tests
op_tests/triton_tests/test_pa_decode_gluon.py:test_pa_decode_output_gatecompares against the ungated output timessigmoid(gate):test_pa_decode_output_gate_empty_sequencechecks that a zero-length sequence gives 0, not NaN (2 cases).test_pa_decode_output_gate_rejects_unfused_pathschecks that one-shot calls and the non-PS v2 reduce raise (3 cases).op_tests/op_benchmarks/triton/bench_pa_decode.py:--output_gate none|fused|separate(gluon backend) and-d(head size for custom shapes); gated modes skip shapes with one recommended partition. It also fixesoverride_parser_action(parser, "backend", ...)to"--backend".