Skip to content

[Triton/Gluon] Fused GDN decode kernel for any value/key head ratio (Qwen3.5/3.8) - #6488

Merged
vgokhale merged 3 commits into
ROCm:mainfrom
eky-amd:gdn-fused-decode-ratio3
Oct 21, 2026
Merged

vgokhale merged 3 commits into
ROCm:mainfrom
eky-amd:gdn-fused-decode-ratio3

Conversation

@eky-amd

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

Copy link
Copy Markdown
Contributor

Motivation

AITER PR #5520 added a fused Gated-DeltaNet decode op for gfx950 (packed qkvz/ba split + causal conv1d + delta-rule
recurrence + gated RMSNorm, optional FP8 epilogue), but its kernels hardcode Qwen3-Next's geometry: two value heads per key head, the interleaved per-group qkvz packing, dense state pools. Qwen3.5/3.8-27B has 48 value heads over 16 key
heads (ratio 3) and a flat [q_all | k_all | v_all | z_all] packing, so it could not use the op and ran the decode step as three kernels (conv1d 8 µs + recurrence 79 µs + norm 4 µs per layer at 64 tokens).

This PR adds a ratio-generic sibling kernel, _decode_group_ratio, and routes it from the existing wrapper.

Companion vLLM PR: vllm-project/vllm#61428

Technical Details

  • aiter/ops/triton/_gluon_kernels/gfx950/gated_delta_net/fused_gdn_decode_qkvz_ratio.py (new): one program per
    (token, key-head group) owns the group's RATIO [V, K] fp32 state tiles in registers. Three gl.static_range
    phases with per-head values carried in tuples: (1) issue every independent load — state tiles, gating scalars, output
    gates, conv inputs; (2) conv through LDS, q/k L2 norms, per-head delta-rule update and buffer_store; (3) per-head
    gated RMSNorm from registers. Carrying the tiles in a tuple keeps all loads ahead of the first store. Tile layout is the
    ratio-2 kernels' BlockedLayout([1, 4], [4, 16], [NW, 1]) (16 lanes × 4 fp32 per row = one contiguous 16 B access
    per lane). Reuses _exp/_sigmoid/_quantization_scale from the ratio-2 file, softplus from _gluon_kernels/common/utils.py and _silu from _triton_kernels/common/activation.py.
  • Wrapper fused_gdn_decode_qkvz / fused_gdn_decode_qkvz_supported: new keyword arguments are qkvz_layout
    ("interleaved" | "flat"), query_start_loc (rows with an empty query segment are padded CUDA-graph rows and are skipped) and out (preallocated bf16 [T, VH, VD] output, saves a copy). State pools may be strided along the slot dimension and the conv window may be any strided view; the recurrent state stays dense within a slot. Dispatched at ratio != 2, or with flat layout, or when query_start_loc is provided.
  • op_tests/op_benchmarks/triton/bench_fused_gdn_decode_qkvz.py: --ratio, --num-k-heads, --layout.

Not changed: the generated ratio-2 kernels, their dispatch, and _decode_group.

Test Plan

pytest op_tests/triton_tests/gated_delta_net/test_fused_gdn_decode_qkvz.py -q
python3 op_tests/op_benchmarks/triton/bench_fused_gdn_decode_qkvz.py --ratio 3 --num-k-heads 16
python3 op_tests/op_benchmarks/triton/bench_fused_gdn_decode_qkvz.py --ratio 3 --num-k-heads 16 --layout flat

New/extended tests (46 total pass, MI355X, Triton 3.8), correctness vs the torch reference for:

  • (KH, ratio) ∈ {(16, 3), (8, 1), (4, 4)} × batch ∈ {1, 16, 64, 128} with the FP8 epilogue
  • flat packing for ratios 1–4
  • slot-strided pools in channel-major and width-major conv layouts
  • query_start_loc padding
  • preallocated out
  • bf16-only + PAD_SLOT_ID

Test Result

Op benchmark, Qwen3.8-27B dims (KH 16 / VH 48, K = V = 128), bf16 output, 512 slots:

batch µs TB/s % of peak (8 TB/s)
1 13.7 0.47 6
8 15.8 3.26 41
16 23.9 4.32 54
32 39.2 5.27 66
64 69.0 5.99 75
128 149.2 5.54 69
256 287.9 5.74 72

In vLLM serving (companion vLLM PR above), Qwen3.8-27B BF16 TP1 on one MI355X, 64 decode tokens per step:

  • conv (8 us) + recurrence (75–79 us) + norm (4–9 us) → fused kernel (70–76 us)

GSM8K unchanged (0.7263 vs 0.7233 flexible).

Submission Checklist

@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 6488 --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 force-pushed the gdn-fused-decode-ratio3 branch 4 times, most recently from ba5c59a to a194014 Compare October 14, 2026 22:28
@eky-amd
eky-amd marked this pull request as ready for review October 14, 2026 22:28
@eky-amd
eky-amd requested a review from a team October 14, 2026 22:28
@github-actions github-actions Bot changed the title [Gluon] Fused GDN decode kernel for any value/key head ratio (Qwen3.5/3.8) [Triton/Gluon] Fused GDN decode kernel for any value/key head ratio (Qwen3.5/3.8) Oct 14, 2026
@Boss2002n
Boss2002n requested a balanced review from Copilot October 15, 2026 01: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.

🟡 Changes recommended

The support predicate rejects an intended padding mode and omits device checks for optional GPU operands.

2 open findings
What changed in this PR

Extends the gfx950 fused GDN decode operator for Qwen3.5/3.8 while retaining the existing ratio-2 kernels.

Changes:

  • Adds a generic kernel for value/key head ratios 1–4 and flat packing.
  • Adds strided-state support, padding metadata and preallocated output.
  • Extends correctness tests and benchmark options.
File Description
op_tests/​triton_tests/​gated_delta_net/​test_fused_gdn_decode_qkvz.py Tests ratios, layouts, strided states, padding and output reuse.
op_tests/​op_benchmarks/​triton/​bench_fused_gdn_decode_qkvz.py Adds ratio and layout options; adjusts traffic estimates.
aiter/​ops/​triton/​gated_delta_net/​fused_gdn_decode_qkvz.py Extends validation, arguments and kernel dispatch.
aiter/​ops/​triton/​_gluon_kernels/​gfx950/​gated_delta_net/​fused_gdn_decode_qkvz_ratio.py Implements ratio-generic fused decode.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@zufayu
zufayu requested review from a team and azaidy October 15, 2026 02:11
@azaidy
azaidy requested a review from vgokhale October 15, 2026 15:19
@azaidy azaidy assigned vgokhale and unassigned azaidy Oct 15, 2026
@eky-amd
eky-amd force-pushed the gdn-fused-decode-ratio3 branch from a194014 to 138f74b Compare October 15, 2026 18:59
@eky-amd
eky-amd force-pushed the gdn-fused-decode-ratio3 branch from 138f74b to f723a0d Compare October 16, 2026 14:28

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

The generic kernel can also run ratio 2, but the dispatch keeps the generated
pair kernels for it:

if ratio != 2 or flat or query_start_loc is not None:
    # ratio-generic kernel
elif tokens >= _LARGE_BATCH:
    # generated large-batch kernel
else:
    # generated small-batch kernel

So two kernels now compute the same math. Should we keep just one?

Can you also confirm it falls back to the triton path on gfx != 950?

@eky-amd

eky-amd commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

nfirm it falls back to the triton path on gfx != 950?

I can run some benchmarks to compare their performance but I'm a little hesitant to remove the generated pair kernels because they're used in SGLang, and they specialize by batch size.

On the second point, I don't think there is a fused Triton version in AITER. From the vLLM side, we fall back to the unfused set of kernels if it's not gfx950.

@eky-amd

eky-amd commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Got some comparison results between the generic kernel and the pair-specific kernels from #5520 (both running with interleaved layout, FP8, KH=4, VH=8, head dim = 128):

Batch Pair Generic Δ
1 9.01 11.50 +27.6%
2 9.01 11.46 +27.2%
4 9.10 11.52 +26.6%
8 9.37 11.59 +23.7%
16 9.13 11.93 +30.7%
32 10.44 13.48 +29.1%
64 13.96 17.18 +23.1%
128 26.50 27.94 +5.4%
256 46.27 47.33 +2.3%

So for the Qwen3-Next-80B-A3B-Instruct-FP8 config, the pair-specific kernels are faster.

katopz added a commit to riir-ai/riir-refine that referenced this pull request Nov 24, 2026
…rch 441): rust_perf +1 (entries_97, output-buffer-prezero-when-kernel-writes-all-rows, DEMOTED NotBenchable-by-platform at landing) + 8 count-neutral faces on kernel hosts

rust_perf 392->393 (entries_97): the dead-pre-zero law transcribed from vLLM
@ 92b52792d #67733 ('No zero fill in either branch: the kernels write every
actual row, and padding rows only feed row-wise ops' + the NaN/poison canary
as the coverage falsifier), INVERSE polarity of vec-macro-zero-fill — one
question, ARE THE ZEROES EVER READ, disagreeing answers. THE GOAT FALSIFIER
FIRED AT LANDING: the Pareto validator priced the pair ParetoDominated
(0 faster / 3 slower / 0 tie — the fixed push-loop arm lost at every size)
and the isolated probe (identical indexing loops, only the allocation
differing) read the pure-allocation delta at 0.967/0.979 twice, inside the
tie band: the Rust class vec![0.0; n] rides alloc_zeroed, whose zero-page
path serves the zeros without a separate memset pass on this platform
posture, so the pass the rule teaches deleting is already absent where we
can validate. Per the pre-registered bar ('a Tie/Slower demotes
in-landing'): bench_spec removed (143->142 benchable / 250->251
notbenchable), the measured negative + the re-arm condition (an allocator
that memsets alloc_zeroed) recorded in-rule, the grade rewritten
NotBenchable-by-platform. The LAW stays decision content: the torch win is
real where it was measured (torch.zeros pays a real memset) and the
correctness half (uninit-read avoidance, the partial-write and
padding-row boundaries) stands.

Faces count-neutral on their OWNERS same commit (vLLM @ 78f20a5a3 #69065 +
34c653886 #61428, Apache-2.0, byte-verified at the pins; the third+fourth
stack instances of the whole-step law, never land): F1 gpu_126
whole-step-gdn-decode-window-one-launch += the CUDA-MTP 9-token +
ROCm-AITER instances; F2 gpu_152 gdn-state-snapshot += the slot-indexed
per-token store; F3 gpu_65 gqa-zero-stride += the WEIGHT-side stride-0
instance (norm.weight.expand + stride_w_group=0); F4 popcorn
alignment-gated-zero-copy-view += the contiguous-drop instance; F5 gpu_164
dependency-version += the signature-introspection variant (inspect.signature
+ 'added in ROCm/aiter#6488'); F6 gpu_09 xor-swizzle += the integer-pad
polarity face (qk_column 12-per-8 — deliberate pad buying conflict-freedom
AND mma-fragment pairing); R2-fold gpu_51 dtype-native += the state-side
polarity (widen-at-load, narrow-at-store, compute f32; the storage dtype IS
the checkpoint's own — not the lossy class); F7 gpu_78 validated-exact-shape
+= the consumer-constraint conjunct ('The kernel emits the normed output, so
out_proj cannot quantize it'). DROPS recorded: reduce_scatter butterfly
thin, zero-bias padding plumbing, capability-envelope refusal face-only
(well-owned), _encode_layer_name plumbing.

Fixtures b407_fixtures 5/5 standalone-compiled AND executed pre-entry
(debug AND -O: parity / poison-canary / anti-regime-accumulation /
padding-boundary + the tamper partial-write arm the regime condition is
load-bearing). Gates (LOCAL on amo, CARGO_TARGET_DIR=/tmp/plan407): lib
4153/0 at kernel_opt,rust_perf,rust_perf_bench,latent_retrieval; clippy -D
x2 postures clean; bare rustfmt on the touched files; pins_manifest
--write (manifest + prose agree); count web one-landing (AGENTS head,
README, .docs/11_domains/rust_perf.md, health_views perf 393 + total 1780,
the kernel-side rust_perf witness, 5 hand-typed count pins, 3
annotated-count pins 341, serde pin). Score-bench/freeze NOT owed (zero
clippy_lints delta — the Batch-401 standing convention). Plans 404/405 NOT
landed at the landing HEAD (no delta). Records: Research 441 Status ->
LANDED (the demotion disclosed), plan 406 T0-T8 ticked + lease folded,
snapshot LANDING row. LANE INTEL (T8): the 16-bit recurrent-state traffic
lever is LOSSY-GATED — never a bit-identity arm; any future
decode-state-traffic cell opens under the lossy law's per-family retention
gate (our f32 state + issue-879 quant-cert stand; the named decode blocker
stays ffn_gate_up). Teardown: .raw/vllm-gdn + /tmp/plan407 + the fixture
scratch removed at close.

Session: zed-e7e471a3@amo, 1795473279
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.

4 participants