Skip to content

[Triton/Gluon] Add sigmoid output gate to pa_decode_gluon - #6842

Merged
eky-amd merged 3 commits into
ROCm:mainfrom
eky-amd:pa-gluon-output-gate
Nov 13, 2026
Merged

eky-amd merged 3 commits into
ROCm:mainfrom
eky-amd:pa-gluon-output-gate

Conversation

@eky-amd

@eky-amd eky-amd commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR adds an optional output_gate argument to pa_decode_gluon that applies the gate in the kernel that already writes the final output, so decode needs one fewer launch. Without output_gate nothing 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) before o_proj. With pa_decode_gluon that 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):
    • The result is out * sigmoid(output_gate).
    • output_gate must match output in 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.
    • It is viewed as [batch, query_length, num_kv_heads, query_group_size, head_size], like the output.
  • The gate is applied in PS reduce: in paged_attention_decode_ps_reduce_kernel (Triton), after the partition merge. With a gate, the reduce always takes the Triton kernel, launched with num_warps from configs/<arch>/gluon/attention/pa_decode_gluon/DEFAULT.json. The HIP reduce is not modified and stays the default without a gate.
  • Other paths reject the gate: output_gate asserts unless ps=True and max_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.
  • The sigmoid uses _sigmoid_exp2 from _triton_kernels/common/activation.py, in fp32.
  • The new constexpr USE_OUTPUT_GATE is added to the reduce kernel; with the default False.
  • A zero-length sequence (a padded CUDA-graph row) has no partitions; the Triton reduce writes 0 for it instead of NaN.

Performance (if applicable)

Kernel time from bench_pa_decode.py with this PR's --output_gate and -d. Shape: Qwen3.8-27B decode (24 query heads / 4 KV heads, 256 head dim, bf16, 16-token pages), get_recommended_splits partitions (≥ 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)
batch context partitions no gate (µs) before: + separate out * sigmoid(gate) (µs) after: output_gate (µs) after vs before
1 1056 8 12.31 14.19 12.73 −1.46 µs (−10.3 %)
16 1056 8 40.00 42.99 39.67 −3.32 µs (−7.7 %)
64 1056 2 78.53 81.27 78.38 −2.89 µs (−3.6 %)
1 4096 16 9.45 11.40 10.14 −1.26 µs (−11.0 %)
16 4096 8 63.36 66.53 63.56 −2.97 µs (−4.5 %)
64 4096 2 206.05 210.82 206.58 −4.24 µs (−2.0 %)

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None. Without output_gate nothing changes.

PR Self-Review

Reviewed revision

399003a034442f99115b1f6263cf615534b346b0

Behavior and intent

pa_decode_gluon gains an optional output_gate, applied in the PS reduce; other paths reject it. Without output_gate nothing changes, except that the Triton PS reduce writes 0 instead of NaN for a zero-length sequence.

Validation and unverified scope

python3 -m pytest op_tests/triton_tests/test_pa_decode_gluon.py -k output_gate   # new cases
python3 -m pytest op_tests/triton_tests/test_pa_decode_gluon.py                  # existing callers

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):

  • With -k output_gate: 11 / 11 pass.
  • Full test file: 60 / 60 pass.

Unverified: gfx942, where the gated num_warps is not measured (its config keeps 4).

PR-specific question

Configuration keys. The new pa_decode_gluon/DEFAULT.json (gfx950, gfx942) has ps_reduce and ps_reduce_output_gate, each with num_warps; only the Triton PS reduce launch reads it. ps_reduce is 4, the num_warps that launch used before, so callers without a gate keep their launch, and ps_reduce_output_gate is read only with a gate.

Changed op tests

  • op_tests/triton_tests/test_pa_decode_gluon.py:
    • test_pa_decode_output_gate compares against the ungated output times sigmoid(gate):
      • Qwen3.8 geometry: head 256, 6 query heads per KV head, bf16, 64-token shuffle-layout pages, context lengths 37 / 1000 / 4096;
      • the gate passed as a strided view of a fused projection;
      • paths: PS reduce with 2 and 4 partitions, PS reduce with one KV head;
      • query length 1 and 2 (6 cases).
    • test_pa_decode_output_gate_empty_sequence checks that a zero-length sequence gives 0, not NaN (2 cases).
    • test_pa_decode_output_gate_rejects_unfused_paths checks 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 fixes override_parser_action(parser, "backend", ...) to "--backend".

@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 (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu 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: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
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 6842 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

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 stop the title rewrites; labels stay in sync either way.

@eky-amd eky-amd changed the title [Gluon] Add sigmoid output gate to pa_decode_gluon [Triton/Gluon] Add sigmoid output gate to pa_decode_gluon Oct 22, 2026
@eky-amd
eky-amd force-pushed the pa-gluon-output-gate branch 3 times, most recently from b782a1a to e319edb Compare October 23, 2026 18:00
@eky-amd
eky-amd marked this pull request as ready for review October 23, 2026 18:00
@eky-amd
eky-amd requested a review from a team October 23, 2026 18:00
@azaidy
azaidy requested a review from vgokhale October 23, 2026 19:13
@Boss2002n
Boss2002n requested a balanced review from Copilot October 24, 2026 01:38

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.

🟡 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

@aiter-bot

aiter-bot commented Nov 3, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision 399003a03444 · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

`pa_decode_gluon` gains an optional `output_gate`, applied in the PS reduce; other paths reject it. Without `output_gate` nothing changes, except that the Triton PS reduce writes 0 instead of NaN for a zero-length sequence.

Validation and unverified scope

```bash
python3 -m pytest op_tests/triton_tests/test_pa_decode_gluon.py -k output_gate   # new cases
python3 -m pytest op_tests/triton_tests/test_pa_decode_gluon.py                  # existing callers
```

MI355X (gfx950), this branch (main 75a36b847d merged in), on AITER v0.1.27 with this branch's files on top (main's AITER needs FlyDSL ≥ 0.5.0):
- With `-k output_gate`: **11 / 11 pass**.
- Full test file: **60 / 60 pass**.

Unverified: gfx942, where the gated `num_warps` is not measured (its config keeps 4).

PR-specific question

**Configuration keys.** The new `pa_decode_gluon/DEFAULT.json` (gfx950, gfx942) has `ps_reduce` and `ps_reduce_output_gate`, each with `num_warps`; only the Triton PS reduce launch reads it. `ps_reduce` is 4, the `num_warps` that launch used before, so callers without a gate keep their launch, and `ps_reduce_output_gate` is read only with a gate.

Changed op tests

- `op_tests/triton_tests/test_pa_decode_gluon.py`:
  - `test_pa_decode_output_gate` compares against the ungated output times `sigmoid(gate)`:
    - Qwen3.8 geometry: head 256, 6 query heads per KV head, bf16, 64-token shuffle-layout pages, context lengths 37 / 1000 / 4096;
    - the gate passed as a strided view of a fused projection;
    - paths: PS reduce with 2 and 4 partitions, PS reduce with one KV head;
    - query length 1 and 2 (6 cases).
  - `test_pa_decode_output_gate_empty_sequence` checks that a zero-length sequence gives 0, not NaN (2 cases).
  - `test_pa_decode_output_gate_rejects_unfused_paths` checks 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 fixes `override_parser_action(parser, "backend", ...)` to `"--backend"`.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • FAIL — an active Copilot finding has no substantive reply from the PR author
  • FAIL — an active Copilot finding has no substantive reply from the PR author
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

k50112113
k50112113 previously approved these changes Nov 11, 2026
@eky-amd
eky-amd force-pushed the pa-gluon-output-gate branch from ffe352b to 399003a Compare November 12, 2026 19:17
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.

5 participants