Skip to content

[Triton/Gluon] [gfx1250] Add a gfx1250 Gluon KDA gating kernel for ATOM's decode entry. - #7990

Merged
Liang-jianhao97 merged 4 commits into
mainfrom
feat/gfx1250-kda-gating
Nov 25, 2026
Merged

Liang-jianhao97 merged 4 commits into
mainfrom
feat/gfx1250-kda-gating

Conversation

@Liang-jianhao97

@Liang-jianhao97 Liang-jianhao97 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

On gfx1250, KDA decode and speculative verify spend most of their time in the gating recurrence: the per-channel gate, then the delta-rule update of a 128x128 FP32 state for each (sequence, value head). This PR adds kda_gating_decode, a Gluon kernel for this update that is optimized for gfx1250, and supports, which a caller uses to select its route one time. ROCm/ATOM#3362 routes Kimi-K3's KDA gating to it.

fused_recurrent_kda runs the same recurrence, but it has no read-slot table apart from the write-slot table. A state fork reads its state from one slot and writes it to another slot in the same launch, so it needs that table. On the no-fork shapes that both ops take, kda_gating_decode is 1.10x to 2.44x faster than fused_recurrent_kda, from TP 8 (H = 12) to TP 1 (H = 96). It is also 1.16x to 1.91x faster than ATOM's Triton kernel on all 100 measured shapes. For an input that it does not take, the entry returns None without a launch and logs the reason at DEBUG.

Technical Details

  • New aiter/ops/triton/attention/kda_gating.py:
    • supports(*, lower_bound, state_dtype, head_k_dim, head_v_dim, act_dtype) -> bool is True for a lower-bounded gate, an FP32 state, K = V = 128, BF16 or FP16 activations and a gfx1250 GPU (arch_info.get_arch() == "gfx1250"). The config tables are keyed by the exact arch, and only gfx1250 has them, so it is False on gfx1250-strict.
    • kda_gating_decode(A_log, a, b, dt_bias, q, k, v, o=None, scale=None, initial_state=None, inplace_final_state=True, cu_seqlens=None, ssm_state_indices=None, num_accepted_tokens=None, use_qk_l2norm_in_kernel=False, ssm_state_indices_in=None, lower_bound=None) returns (o, initial_state). It calls supports(), then checks the shapes, dtypes, strides, devices and slot tables of the call. The checks read only tensor metadata, so they do not synchronize and work under CUDA graph capture. For an input that the kernel does not take, it returns None without a launch and logs the reason at DEBUG through AiterTritonLogger.
    • Slot rules: ssm_state_indices is the int32 write-slot table. ssm_state_indices_in is the read-slot table, with the same shape and strides; None reads from the write slots. The read slot is read[seq, num_accepted_tokens[seq] - 1] in speculative verify, else read[seq]. A read slot below 0, an empty sequence or an accepted count below 1 skips the sequence. A write slot below 0 still writes the output. Slot 0 is a real slot.
  • New kda_gating_kernel (aiter/ops/triton/_gluon_kernels/gfx1250/attention/kda_gating.py): in place, K = V = 128, HV a multiple of H, BF16 or FP16 activations, an FP32 V-first state. A 1D slot table gives each sequence 0 or 1 tokens. A 2D table gives each sequence up to one token for each column, for speculative verify and multi-token calls.
    • One program keeps BV rows of one (sequence, value head) 128x128 state tile in registers. It requests the whole tile with 8- or 16-byte loads before the math, so it waits for memory one time.
    • Above 180 sequence-heads, in-place calls and forks use different layouts and cache policies. The kernel selects one at run time from the read and write slots, so one captured CUDA graph serves both.
    • Above 96 sequence-heads, speculative verify precomputes the per-token column vectors in LDS, 8 tokens at a time.
    • The gate and beta use fast_sigmoid from _gluon_kernels/common/utils.py. The in-place path at 181 to 4596 sequence-heads keeps the IEEE divide (INPLACE_FAST_DIV in the config), because fast_sigmoid makes that path up to 14% slower.
  • Configs in configs/gfx1250/gluon/attention/kda_gating/DEFAULT.json: a one_token table for 1D slot tables and a multi_token table for 2D ones. They are keyed by sequences x value heads and loaded with resolve_config_dir, which takes the running arch as the other gfx1250 Gluon loaders do, and select_leq_config.
  • bench_kda.py:
    • gating_same, gating_split and gating_fork backends for each H: one table as the read and the write table; a copy of it as the read table; every read from a slot that no sequence writes. A gating_spec backend for speculative verify.
    • recurrent_same and recurrent_spec backends, which call fused_recurrent_kda on the inputs of gating_same and gating_spec.
    • --timing rotating (RotatingBufferBench), which gives each call a cold state, as in a decode step. The default cudagraph timing replays the same buffers, so the state stays in cache.

Test Plan

  • pytest op_tests/triton_tests/attention/test_kda_gating.py on gfx1250, 59 cases:
    • 18 cases against a PyTorch reference: each config bucket at H = 12; H = 24 and 48; FP16; HV = 2H; 2D slot tables with and without accepted counts; negative read and write slots; empty sequences.
    • The slot rules (same slots, a fork, negative slots, speculative verify from the accepted column, an accepted count of 0), a strided beta, o=None and a 4D o, CUDA graph replay after the slots and lengths change, and agreement with fused_recurrent_kda where both apply.
    • supports() with the Kimi-K3 setup and with each condition except the arch changed (6 cases), and on gfx1250-strict (1 case).
    • 22 inputs that the entry declines. Each must return None, log the reason at DEBUG and write nothing.
  • bench_kda.py --timing rotating at H = 12/24/48/96: kda_gating_decode and fused_recurrent_kda on the same no-fork shapes, and an A/B against ec44f53 in the same session.
  • ATOM's kernel vs this kernel on gfx1250, with the same inputs and the same cold-state CUDA graph timing: 100 shapes, H = 12/24/48/96, decode and fork with M = 1 to 512, speculative verify with T = 8 and M = 1 to 128; median of 3 runs. Also the 25 H = 12 shapes with Kimi-K3's fused in_proj beta, median of 3 runs.
  • AITER_TRITON_ONLY=1: the entry imports, and supports() is True on gfx1250.
  • [gfx1250] KDA Decode with AITER fused gating on GFX1250 ATOM#3362's dispatch and parity tests, with this tree on PYTHONPATH.

Test Result

  • test_kda_gating.py at 1c4ed7d: 59 passed.
  • bench_kda.py --timing rotating at 1c4ed7d, µs, median of 3 runs, mean of two rounds. fused_recurrent_kda gets the same inputs as gating_same and gating_spec:

Decode (T = 1). gating_split uses a copy of the slot table as the read table, and in gating_fork every sequence forks:

H B gating_same recurrent_same Speed-up gating_split gating_fork
12 1 2.27 2.50 1.10x 2.28 1.98
12 16 4.31 5.37 1.25x 4.24 3.24
12 72 10.50 16.23 1.55x 10.73 7.76
12 256 28.93 47.04 1.63x 29.24 24.47
12 512 61.83 85.36 1.38x 62.65 49.04
24 1 2.37 2.69 1.13x 2.40 2.15
24 16 6.04 8.58 1.42x 6.03 4.60
24 72 18.28 28.22 1.54x 18.26 13.39
24 256 61.75 84.77 1.37x 62.32 49.10
24 512 123.49 158.05 1.28x 124.05 99.33
48 1 2.52 3.03 1.20x 2.74 2.33
48 16 9.43 14.00 1.48x 9.50 7.42
48 72 33.47 51.22 1.53x 33.76 27.58
48 256 123.20 157.66 1.28x 123.36 99.62
48 512 246.02 307.76 1.25x 246.01 200.09
96 1 3.36 3.73 1.11x 3.35 2.72
96 16 15.86 25.40 1.60x 15.92 13.18
96 72 76.89 94.00 1.22x 77.03 55.05
96 256 246.90 307.03 1.24x 246.57 200.04
96 512 505.89 611.64 1.21x 505.22 411.00

Speculative verify (T = 8, no read table):

H B gating_spec recurrent_spec Speed-up
12 1 5.16 7.68 1.49x
12 16 9.07 22.14 2.44x
12 72 33.90 53.75 1.59x
24 1 5.20 7.99 1.54x
24 16 15.71 25.31 1.61x
24 72 67.99 97.90 1.44x
48 1 5.39 9.00 1.67x
48 16 30.05 45.26 1.51x
48 72 145.41 188.10 1.29x
96 1 7.59 14.68 1.93x
96 16 59.73 84.37 1.41x
96 72 297.14 363.23 1.22x

kda_gating_decode is faster than fused_recurrent_kda on all 32 shapes: 1.10x to 1.63x in decode and 1.22x to 2.44x in speculative verify. The smallest gains are at B = 1 in decode (1.10x to 1.20x), where both ops take 2 to 4 µs. Thus fused_recurrent_kda is not as fast on the no-fork shapes, and a read-slot table in it would add forks, but not this speed. In the same session, the 72 gating_* values are between 1.4% faster and 1.5% slower than at ec44f53, apart from gating_spec at H = 24, B = 16, where ec44f53 was 6% slower in both rounds. A re-check with the order reversed gives 0.3% there, and the multi-token code of the two heads is the same.

  • All 100 shapes match ATOM's outputs and states. Speed-up over ATOM's kernel (t_ATOM / t_aiter):
Mode H = 12 H = 24 H = 48 H = 96
decode 1.27-1.49x 1.28-1.60x 1.27-1.54x 1.25-1.55x
fork 1.23-1.59x 1.19-1.42x 1.18-1.41x 1.16-1.70x
spec verify (T = 8) 1.37-1.91x 1.26-1.90x 1.25-1.90x 1.24-1.72x

With Kimi-K3's fused beta at H = 12: 1.23x to 1.87x.

Detailed results

gfx1250, rocm/fw-bringup-mlperf:gfx1250-atom-20261106-dsv41 container, at 1c4ed7d. ATOM's fused_sigmoid_gating_delta_rule_update (atom/model_ops/fla_ops/fused_sigmoid_gating.py, the same at ROCm/ATOM 2684c6d and 8f2903b62) and this entry get the same inputs and the same timing: CUDA graph replay with RotatingBufferBench over input sets that span at least 196 MB, so each call reads a cold state; 100 calls per graph, 10 replays, median of 3 runs. These tables use a different timing harness from bench_kda.py, so their values are not equal to the bench_kda.py values.

  • BF16 activations with a contiguous beta, FP32 V-first state, K = V = 128, lower_bound = -5, q/k L2 normalization in the kernel.
  • Outputs and states match ATOM on all 100 shapes (outputs: atol 2e-3, rtol 2e-2; states: atol 1e-3, rtol 1e-3).
  • M is the number of sequences. H = 12 / 24 / 48 / 96 are Kimi-K3's 96 heads at TP 8 / 4 / 2 / 1.

Each cell: ATOM µs / this PR µs (ATOM time ÷ this PR time).

Decode (T = 1; the read table is a separate buffer that holds the write slots)

M H = 12 H = 24 H = 48 H = 96
1 3.11 / 2.27 (1.37x) 3.19 / 2.39 (1.33x) 3.48 / 2.75 (1.27x) 4.70 / 3.17 (1.48x)
8 4.23 / 3.33 (1.27x) 5.57 / 4.34 (1.28x) 9.21 / 6.06 (1.52x) 14.66 / 9.46 (1.55x)
16 5.73 / 4.37 (1.31x) 9.24 / 6.08 (1.52x) 14.82 / 10.15 (1.46x) 25.80 / 17.55 (1.47x)
32 9.19 / 6.26 (1.47x) 14.67 / 10.07 (1.46x) 25.98 / 18.27 (1.42x) 46.25 / 34.34 (1.35x)
64 14.78 / 10.13 (1.46x) 25.89 / 18.28 (1.42x) 46.62 / 34.49 (1.35x) 86.57 / 58.95 (1.47x)
72 16.07 / 10.75 (1.49x) 29.51 / 18.41 (1.60x) 51.97 / 33.69 (1.54x) 95.24 / 67.66 (1.41x)
128 26.19 / 18.36 (1.43x) 46.64 / 34.48 (1.35x) 85.72 / 62.21 (1.38x) 163.67 / 123.92 (1.32x)
256 46.87 / 34.51 (1.36x) 85.79 / 62.49 (1.37x) 163.66 / 124.05 (1.32x) 319.98 / 247.99 (1.29x)
512 87.02 / 59.53 (1.46x) 163.43 / 124.19 (1.32x) 320.17 / 247.53 (1.29x) 626.93 / 501.91 (1.25x)

Fork (T = 1; every sequence reads its state from a slot that no sequence writes)

Every row forks, which is the worst case. ATOM forks a sequence only for one forward, when it takes or resumes from a state checkpoint, and the other rows of the batch run as decode.

M H = 12 H = 24 H = 48 H = 96
1 3.01 / 1.89 (1.59x) 2.71 / 1.95 (1.39x) 2.98 / 2.12 (1.41x) 3.75 / 2.20 (1.70x)
8 3.31 / 2.47 (1.34x) 4.32 / 3.05 (1.42x) 5.57 / 4.39 (1.27x) 8.81 / 6.89 (1.28x)
16 4.33 / 3.07 (1.41x) 5.54 / 4.52 (1.23x) 8.77 / 6.90 (1.27x) 15.67 / 12.34 (1.27x)
32 5.50 / 4.29 (1.28x) 8.70 / 6.94 (1.25x) 15.43 / 12.29 (1.26x) 27.67 / 22.53 (1.23x)
64 8.74 / 6.91 (1.26x) 15.39 / 12.27 (1.25x) 27.83 / 22.48 (1.24x) 56.68 / 48.35 (1.17x)
72 8.89 / 7.22 (1.23x) 14.64 / 12.34 (1.19x) 31.83 / 25.79 (1.23x) 63.74 / 54.73 (1.16x)
128 16.00 / 12.32 (1.30x) 27.92 / 22.37 (1.25x) 58.34 / 48.37 (1.21x) 114.98 / 98.44 (1.17x)
256 28.33 / 22.44 (1.26x) 59.15 / 48.24 (1.23x) 115.47 / 98.21 (1.18x) 239.46 / 200.37 (1.20x)
512 61.97 / 48.10 (1.29x) 116.92 / 97.89 (1.19x) 239.22 / 198.87 (1.20x) 479.11 / 410.61 (1.17x)

Speculative verify (T = 8, --num-speculative-tokens 7; 2D write table, no read table, 1 to 8 accepted tokens)

M H = 12 H = 24 H = 48 H = 96
1 9.67 / 5.05 (1.91x) 9.89 / 5.20 (1.90x) 10.32 / 5.42 (1.90x) 11.39 / 6.63 (1.72x)
8 11.57 / 7.53 (1.54x) 14.87 / 8.96 (1.66x) 23.13 / 16.12 (1.43x) 43.86 / 33.05 (1.33x)
16 16.35 / 8.88 (1.84x) 23.19 / 15.86 (1.46x) 44.23 / 31.44 (1.41x) 82.29 / 61.54 (1.34x)
32 23.26 / 15.67 (1.48x) 44.01 / 30.97 (1.42x) 82.37 / 59.77 (1.38x) 162.26 / 128.71 (1.26x)
64 44.26 / 30.76 (1.44x) 82.38 / 59.24 (1.39x) 162.19 / 129.06 (1.26x) 329.35 / 263.63 (1.25x)
72 48.12 / 34.78 (1.38x) 92.27 / 69.38 (1.33x) 181.85 / 145.72 (1.25x) 371.27 / 296.21 (1.25x)
128 82.53 / 60.28 (1.37x) 162.07 / 128.79 (1.26x) 330.16 / 262.97 (1.26x) 660.52 / 534.36 (1.24x)
H = 12 with Kimi-K3's fused in_proj beta (median of 3 runs)

Beta is a view of the fused in_proj row [q | k | v | g | beta | f_a] with token stride 6284, as Kimi-K3 passes it. Each cell: ATOM µs / this PR µs (ATOM time ÷ this PR time).

M Decode Fork Spec verify (T = 8)
1 3.11 / 2.26 (1.38x) 2.69 / 1.88 (1.43x) 9.71 / 5.18 (1.87x)
8 4.24 / 3.42 (1.24x) 3.36 / 2.42 (1.39x) 11.56 / 7.58 (1.53x)
16 5.45 / 4.07 (1.34x) 4.30 / 3.04 (1.41x) 16.34 / 8.83 (1.85x)
32 9.23 / 5.67 (1.63x) 5.61 / 4.33 (1.30x) 21.52 / 15.63 (1.38x)
64 14.78 / 9.41 (1.57x) 8.84 / 6.87 (1.29x) 44.21 / 30.53 (1.45x)
72 16.11 / 10.63 (1.52x) 8.92 / 7.24 (1.23x) 48.25 / 34.05 (1.42x)
128 26.24 / 15.78 (1.66x) 15.88 / 12.32 (1.29x) 82.31 / 60.11 (1.37x)
256 47.27 / 29.10 (1.62x) 28.50 / 22.43 (1.27x) -
512 86.71 / 59.45 (1.46x) 61.79 / 48.15 (1.28x) -

PR Self-Review

Reviewed revision

1c4ed7d

Behavior and intent

This PR adds aiter.ops.triton.attention.kda_gating.kda_gating_decode and supports, and the gfx1250 Gluon kernel behind them, so that a model can run KDA gating decode, state forks and speculative verify on aiter. ROCm/ATOM#3362 is the first caller, for Kimi-K3. Existing behavior does not change: every file except bench_kda.py is new, and no existing kernel, wrapper or config is edited. fused_recurrent_kda has no separate read-slot table, which forks need, and on the shapes that both ops take, the new kernel is 1.10x to 2.44x faster. For an input that it does not take, the entry returns None without a launch and logs the reason at DEBUG, so the caller keeps its own kernel.

Validation and unverified scope

On gfx1250 in rocm/fw-bringup-mlperf:gfx1250-atom-20261106-dsv41 (ROCm 10.1.0, HIP 7.16, PyTorch 2.11.0, Triton 3.9.0.dev20261022):

  • pytest op_tests/triton_tests/attention/test_kda_gating.py -v at 1c4ed7d: 59 passed.
  • python -m op_tests.op_benchmarks.triton.bench_kda --timing rotating --metric time --num_heads 12 24 48 96 --runs 3, with --backends gating_same gating_split gating_fork recurrent_same --seq_lens 1 --batch_sizes 1 16 72 256 512 and with --backends gating_spec recurrent_spec --seq_lens 8 --batch_sizes 1 16 72, at 1c4ed7d, in two rounds that alternate with the same runs at ec44f53: the tables in Test Result.
  • ATOM's kernel vs this kernel at 1c4ed7d, median of 3 runs. On 100 shapes, the outputs and states match ATOM, and this kernel is 1.16x to 1.91x faster. On the 25 H = 12 shapes with Kimi-K3's fused beta, it is 1.23x to 1.87x faster.
  • [gfx1250] KDA Decode with AITER fused gating on GFX1250 ATOM#3362 at ROCm/ATOM@8f2903b62 with this tree: pytest tests/models/test_kimi_k3_kda_gating_dispatch.py tests/models/test_kimi_k3_kda_gating_parity.py: 22 passed (6 dispatch, 16 parity).
  • AITER_TRITON_ONLY=1: the entry imports and supports() is True on gfx1250.
  • black==26.5.1 --check, ruff==0.16.0 check and git diff --check pass on the changed files.

Unverified: architectures other than gfx1250, gfx1250-strict included (it has no config tree), where supports() is False, the entry returns None and the test module is skipped; end-to-end accuracy and throughput in a model; benchmarks for FP16 and HV ≠ H, which only the unit tests cover. Also not checked at run time: the per-sequence lengths and accepted counts, which the host cannot read without a device sync. With a 1D slot table, a sequence with more than one token gets only its first token. In speculative verify, a count above the table width reads past the row of the sequence. The host declines a 1D table with more tokens than sequences, and the docstring states both rules.

PR-specific question

Which exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?

The only configuration change is the new aiter/ops/triton/configs/gfx1250/gluon/attention/kda_gating/DEFAULT.json. Its only reader is get_kda_gating_config, and only kda_gating_decode calls that, after all of its checks pass. The table is one_token for a 1D slot table (decode, fork) and multi_token for a 2D one (speculative verify). select_leq_config(prefix="SEQ_HEADS_LEQ_") then picks the bucket from sequences x value heads:

Table Key Sequences at H = 12 / 24 / 48 / 96 (HV = H)
one_token SEQ_HEADS_LEQ_180 1-15 / 1-7 / 1-3 / 1
one_token SEQ_HEADS_LEQ_4596 16-383 / 8-191 / 4-95 / 2-47
one_token any 384+ / 192+ / 96+ / 48+
multi_token SEQ_HEADS_LEQ_96 1-8 / 1-4 / 1-2 / 1
multi_token any 9+ / 5+ / 3+ / 2+

No existing config file, kernel or wrapper changes, and nothing on main calls the new entry, so every other op and shape keeps its previous selection: git diff --stat e3931369c 1c4ed7d3b lists only the new kda_gating files, the new config and test, and bench_kda.py. test_gating_kernel_matches_reference runs all five buckets at H = 12 against a PyTorch reference: decode at 1, 16 and 384 sequences, fork at 15, 16 and 384, and speculative verify and 2D tables without accepted counts at 8 and 9, so each bucket boundary has a case on both sides.

Changed op tests

  • op_tests/triton_tests/attention/test_kda_gating.py (new, 59 cases): tests kda_gating_decode, supports and kda_gating_kernel against a PyTorch reference of the recurrence. It covers the slot rules (separate read and write slots, forks that leave the read slots unchanged, a negative read slot or an accepted count of 0 that skips the sequence, a negative write slot that still writes the output, slot 0, empty sequences, speculative verify that reads ssm_state_indices_in[seq, accepted - 1]), each config bucket, H = 24 and 48, FP16, HV = 2H, a strided beta, o=None and a 4D o, CUDA graph replay after the slots and lengths change, agreement with fused_recurrent_kda where both apply, supports() (also on gfx1250-strict), and 22 inputs that must return None, log the reason and write nothing. Not redundant: no existing test calls this entry or kernel, and test_kda.py tests fused_recurrent_kda, which has no read-slot table.
  • op_tests/op_benchmarks/triton/bench_kda.py (modified): adds the gating_same, gating_split, gating_fork and gating_spec backends, which time the new entry in Kimi-K3's layouts (beta as a view of the fused in_proj row, BF16 activations, FP32 V-first state); the recurrent_same and recurrent_spec backends, which time fused_recurrent_kda on the same inputs; and --timing rotating, which replays a CUDA graph over a RotatingBufferBench pool so that each call reads a cold state. Not redundant: the existing gluon and fla backends time fused_recurrent_kda and FLA on their own inputs, and the existing cudagraph timing replays the same buffers, which keeps the state in cache. The new backends raise if the entry declines their case, so they cannot time an empty graph.

Submission Checklist

@aiter-bot

aiter-bot commented Nov 15, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 1c4ed7d3bb29 · 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

This PR adds `aiter.ops.triton.attention.kda_gating.kda_gating_decode` and `supports`, and the gfx1250 Gluon kernel behind them, so that a model can run KDA gating decode, state forks and speculative verify on aiter. ROCm/ATOM#3362 is the first caller, for Kimi-K3. Existing behavior does not change: every file except `bench_kda.py` is new, and no existing kernel, wrapper or config is edited. `fused_recurrent_kda` has no separate read-slot table, which forks need, and on the shapes that both ops take, the new kernel is 1.10x to 2.44x faster. For an input that it does not take, the entry returns None without a launch and logs the reason at DEBUG, so the caller keeps its own kernel.

Validation and unverified scope

On gfx1250 in `rocm/fw-bringup-mlperf:gfx1250-atom-20261106-dsv41` (ROCm 10.1.0, HIP 7.16, PyTorch 2.11.0, Triton 3.9.0.dev20261022):

* `pytest op_tests/triton_tests/attention/test_kda_gating.py -v` at 1c4ed7d3b: 59 passed.
* `python -m op_tests.op_benchmarks.triton.bench_kda --timing rotating --metric time --num_heads 12 24 48 96 --runs 3`, with `--backends gating_same gating_split gating_fork recurrent_same --seq_lens 1 --batch_sizes 1 16 72 256 512` and with `--backends gating_spec recurrent_spec --seq_lens 8 --batch_sizes 1 16 72`, at 1c4ed7d3b, in two rounds that alternate with the same runs at ec44f5309: the tables in Test Result.
* ATOM's kernel vs this kernel at 1c4ed7d3b, median of 3 runs. On 100 shapes, the outputs and states match ATOM, and this kernel is 1.16x to 1.91x faster. On the 25 H = 12 shapes with Kimi-K3's fused beta, it is 1.23x to 1.87x faster.
* ROCm/ATOM#3362 at ROCm/ATOM@8f2903b62 with this tree: `pytest tests/models/test_kimi_k3_kda_gating_dispatch.py tests/models/test_kimi_k3_kda_gating_parity.py`: 22 passed (6 dispatch, 16 parity).
* `AITER_TRITON_ONLY=1`: the entry imports and `supports()` is True on gfx1250.
* `black==26.5.1 --check`, `ruff==0.16.0 check` and `git diff --check` pass on the changed files.

Unverified: architectures other than gfx1250, `gfx1250-strict` included (it has no config tree), where `supports()` is False, the entry returns None and the test module is skipped; end-to-end accuracy and throughput in a model; benchmarks for FP16 and HV ≠ H, which only the unit tests cover. Also not checked at run time: the per-sequence lengths and accepted counts, which the host cannot read without a device sync. With a 1D slot table, a sequence with more than one token gets only its first token. In speculative verify, a count above the table width reads past the row of the sequence. The host declines a 1D table with more tokens than sequences, and the docstring states both rules.

PR-specific question

*Which exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?*

The only configuration change is the new `aiter/ops/triton/configs/gfx1250/gluon/attention/kda_gating/DEFAULT.json`. Its only reader is `get_kda_gating_config`, and only `kda_gating_decode` calls that, after all of its checks pass. The table is `one_token` for a 1D slot table (decode, fork) and `multi_token` for a 2D one (speculative verify). `select_leq_config(prefix="SEQ_HEADS_LEQ_")` then picks the bucket from sequences x value heads:

| Table | Key | Sequences at H = 12 / 24 / 48 / 96 (HV = H) |
| --- | --- | --- |
| `one_token` | `SEQ_HEADS_LEQ_180` | 1-15 / 1-7 / 1-3 / 1 |
| `one_token` | `SEQ_HEADS_LEQ_4596` | 16-383 / 8-191 / 4-95 / 2-47 |
| `one_token` | `any` | 384+ / 192+ / 96+ / 48+ |
| `multi_token` | `SEQ_HEADS_LEQ_96` | 1-8 / 1-4 / 1-2 / 1 |
| `multi_token` | `any` | 9+ / 5+ / 3+ / 2+ |

No existing config file, kernel or wrapper changes, and nothing on main calls the new entry, so every other op and shape keeps its previous selection: `git diff --stat e3931369c 1c4ed7d3b` lists only the new `kda_gating` files, the new config and test, and `bench_kda.py`. `test_gating_kernel_matches_reference` runs all five buckets at H = 12 against a PyTorch reference: decode at 1, 16 and 384 sequences, fork at 15, 16 and 384, and speculative verify and 2D tables without accepted counts at 8 and 9, so each bucket boundary has a case on both sides.

Changed op tests

* `op_tests/triton_tests/attention/test_kda_gating.py` (new, 59 cases): tests `kda_gating_decode`, `supports` and `kda_gating_kernel` against a PyTorch reference of the recurrence. It covers the slot rules (separate read and write slots, forks that leave the read slots unchanged, a negative read slot or an accepted count of 0 that skips the sequence, a negative write slot that still writes the output, slot 0, empty sequences, speculative verify that reads `ssm_state_indices_in[seq, accepted - 1]`), each config bucket, H = 24 and 48, FP16, HV = 2H, a strided beta, `o=None` and a 4D `o`, CUDA graph replay after the slots and lengths change, agreement with `fused_recurrent_kda` where both apply, `supports()` (also on `gfx1250-strict`), and 22 inputs that must return None, log the reason and write nothing. Not redundant: no existing test calls this entry or kernel, and `test_kda.py` tests `fused_recurrent_kda`, which has no read-slot table.
* `op_tests/op_benchmarks/triton/bench_kda.py` (modified): adds the `gating_same`, `gating_split`, `gating_fork` and `gating_spec` backends, which time the new entry in Kimi-K3's layouts (beta as a view of the fused in_proj row, BF16 activations, FP32 V-first state); the `recurrent_same` and `recurrent_spec` backends, which time `fused_recurrent_kda` on the same inputs; and `--timing rotating`, which replays a CUDA graph over a RotatingBufferBench pool so that each call reads a cold state. Not redundant: the existing `gluon` and `fla` backends time `fused_recurrent_kda` and FLA on their own inputs, and the existing `cudagraph` timing replays the same buffers, which keeps the state in cache. The new backends raise if the entry declines their case, so they cannot time an empty graph.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • 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.

kda_atom.fused_sigmoid_gating_delta_rule_update takes the arguments of
ATOM's kernel of the same name and runs kda_gating_kernel for decode,
state fork and speculative verify: in place, K = V = 128, BF16 or FP16
activations, an FP32 V-first state and int32 slot tables. For any other
input it returns None without a launch, and ATOM runs its own kernel.

One program keeps BV rows of a 128x128 state tile in registers and loads
the whole tile before the math. In-place and fork calls use different
layouts and cache policies; the kernel selects them at run time from the
read and write slots. The configs are in
configs/gfx1250/gluon/attention/kda_gating/DEFAULT.json, keyed by the
number of sequences times value heads.

On gfx1250 with cold states, the entry is 1.12x to 1.93x faster than
ATOM's Triton kernel on 75 shapes (H = 12, 24, 48; decode, fork, and
speculative verify with T = 8).

bench_kda gets atom backends for each H, an atom_spec backend, and
--timing rotating, which reads a cold state on each call as in a decode
step.
@Liang-jianhao97
Liang-jianhao97 removed this pull request from stack #7991 November 16, 2026 07:18
@Liang-jianhao97
Liang-jianhao97 changed the base branch from feat/gfx1250-kda-packed-writeback to main November 16, 2026 07:21
@Liang-jianhao97
Liang-jianhao97 requested a review from a team November 16, 2026 07:21
@github-actions github-actions Bot changed the title [gfx1250] Add a gfx1250 Gluon KDA gating kernel for ATOM's decode entry. [Triton/Gluon] [gfx1250] Add a gfx1250 Gluon KDA gating kernel for ATOM's decode entry. Nov 16, 2026
@Boss2002n
Boss2002n requested a balanced review from Copilot November 16, 2026 14: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

Missing metadata capacity and device checks, along with unmasked empty-sequence loads, can cause out-of-bounds GPU reads or invalid launches.

5 open issues
What changed in this PR

This PR adds a gfx1250 Gluon KDA gating entry for ATOM’s Kimi-K3 decode, state forks, and speculative verification, with a None return path for unsupported inputs.

Changes:

  • Adds an ATOM-compatible entry, metadata checks, and a specialized Gluon kernel.
  • Adds configuration buckets for one-token and multi-token workloads.
  • Adds reference and graph-replay tests, plus ATOM benchmark modes with cold-state timing.
File Description
op_tests/​triton_tests/​attention/​test_kda_atom.py Tests recurrence results, slot handling, graph replay, and unsupported inputs.
op_tests/​op_benchmarks/​triton/​bench_kda.py Adds ATOM benchmark modes and rotating-buffer timing.
aiter/​ops/​triton/​configs/​gfx1250/​gluon/​attention/​kda_gating/​DEFAULT.json Defines workload-specific kernel configurations.
aiter/​ops/​triton/​attention/​kda_gating.py Checks input metadata and launches the kernel.
aiter/​ops/​triton/​attention/​kda_atom.py Exposes the ATOM-compatible entry and fallback behavior.
aiter/​ops/​triton/​_gluon_kernels/​gfx1250/​attention/​kda_gating.py Implements the gfx1250 recurrence kernel and configuration selection.

Review effort: Balanced

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Action required before merge (5)

  1. Expose a static support query and make the entry use it. ROCm/ATOM#3362 now copies the rule by hand (get_gfx() == "gfx1250" and lower_bound is not None and an fp32 state). That copy already disagrees with this entry: the entry checks the live Triton arch for gfx1250 or gfx1250-strict, but ATOM's get_gfx() follows GPU_ARCHS and returns gfx1250-strict on strict parts. Add one predicate, for example supports(*, lower_bound, state_dtype, head_k_dim, head_v_dim, act_dtype, ...) -> bool, that uses is_gfx1250_family(get_gfx_runtime()). fused_sigmoid_gating_delta_rule_update and try_kda_gating must call the same predicate, so there is one source of truth (kda_atom.py:64, kda_gating.py:56-121).
  2. Make the API generic, not named after one consumer. attention/kda_atom.py and the "ATOM's ..." docstrings put a caller into aiter's public path. Name the module and the entry for what they compute (KDA lower-bound gating decode with a separate read-slot table). Remove the softplus-only beta/threshold arguments that are always deleted. Change cu_seqlens: torch.LongTensor to an int32 tensor type, because int64 is declined. Rule 1 of aiter/ops/triton/README.md: fused_recurrent_kda (attention/kda.py plus _gluon_kernels/gfx1250/attention/kda_decode.py) already does this recurrence with lower_bound, a sigmoid beta, 2D slot tables and num_accepted_tokens on gfx1250. The only missing feature is the read-slot table. Add that table to the existing op, or time this kernel against fused_recurrent_kda on the same no-fork shapes. Your tests already run both on these shapes. The table now compares only against ATOM's Triton kernel.
  3. Decline inputs that give wrong results without a message. With a 1D slot table, only token bos of each sequence is computed. The other rows of o stay uninitialized when o is None (kda_gating.py:114,122; kernel :566). A host check without a sync is enough: decline when q.shape[1] > n_seq for a 1D table. In spec verify, the kernel loads accepted[seq] and read[seq, accepted-1] before it checks eos > bos. So accepted == 0 reads read[seq, -1] (kernel :479-487; Copilot found this too). Mask these loads, or state the [1, width] contract in the docstring. Log each decline reason at DEBUG with AiterTritonLogger.
  4. Show that the new test runs on gfx1250 CI. test_kda_atom.py is skipped on the MI35X/MI300X Triton runners. ffm-bringup.yaml replaces op_tests/triton_tests/ with its own branch, so this file does not run there either. Give a CI run, or a log at the current head. The red Standard Tests (MI35X) shard fails in op_tests/test_flydsl_hgemm.py, which this PR does not touch.
  5. Fix the small items. Use fast_sigmoid/sigmoid_log2 from _gluon_kernels/common/utils.py for beta (kernel :70-76,357). Add tests for o=None and for a 4D o (o.shape == v.shape). Fix Copilot's open bench_kda.py items: give an explicit dtype=torch.float32 to the state, A_log and dt_bias, and use --device in make_atom_case.

Reviewed at 7bf8076. The recurrence, gate, slot and MULTI_PRE math match ATOM's Triton kernel. The test reference is an independent loop that covers every config bucket, forks, negative slots, CUDA graph replay and declines.

try_kda_gating returns None, before it allocates o or launches, when a
slot table has fewer rows than sequences, a 2D table has no columns,
num_accepted_tokens has fewer entries than sequences, or a tensor is not
on q's CUDA device. Speculative verify no longer reads a slot for an
empty sequence, whose accepted count may be 0. The ATOM backends of
bench_kda.py create their tensors on --device with explicit dtypes, and
the benchmark runs in that device's context.

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Action required before merge (5)

  1. Expose a static support query and make the entry use it (still open). kda_atom.py:64 still compares get_arch() strings, and there is no predicate a caller can use. ROCm/ATOM#3362 at 3515e07 still copies the rule by hand (gfx == "gfx1250" and lower_bound is not None and state_dtype == "fp32"), so it routes gfx1250-strict parts to its own kernel, and it raises when this entry declines a routed call. Add one predicate, e.g. supports(*, lower_bound, state_dtype, head_k_dim, head_v_dim, act_dtype) -> bool built on is_gfx1250_family(get_gfx_runtime()) (aiter/jit/utils/build_targets.py:75, chip_info.py:112). Have both the entry and try_kda_gating call it, so #3362 can call it instead of keeping a copy.
  2. Make the API generic and reuse the existing op (still open). Rename attention/kda_atom.py and drop the "ATOM's ..." wording from the docstrings of all three files. Remove beta/threshold, which the entry always deletes (kda_atom.py:31-32,63). Type cu_seqlens as an int32 tensor, not torch.LongTensor (:36), because int64 is declined (kda_gating.py:100). Under rule 1 of aiter/ops/triton/README.md: fused_recurrent_kda / kda_decode.py already pick the read slot from num_accepted in spec verify, so the only missing piece is a separate read-slot table. Add that table to the existing op, or post timings of this kernel against fused_recurrent_kda on the same no-fork shapes.
  3. Decline inputs that give wrong results without a message (partly fixed). A 1D slot table still runs only token bos of each sequence, so with o=None the remaining rows of o stay torch.empty garbage (kda_gating.py:116,148; kernel :566-567). Decline not multi_token and q.shape[1] > n_seq on the host; this needs no device sync. In spec verify, a non-empty sequence with accepted == 0 still loads read[seq, -1] (kernel :480-482). Mask with (eos > bos) & (col >= 0), or state the [1, width] range in the docstring. Log each decline reason at DEBUG with AiterTritonLogger (README rule 20); none of the 14 return None paths logs anything.
  4. Show that the new test passes on gfx1250 at the current head. No gfx1250 job runs this file. It is skipped on the MI35X and MI300X Triton runners, and ffm-bringup.yaml takes op_tests/triton_tests from shared/reduced_tests_for_FFM_CI. The posted "35 passed" and the self-review revision are both at 7bf8076, but head adds 4 new decline cases and a kernel change. Post a pytest log at 5d138c4 and update the self-review revision; aiter-bot reports it as FAIL.
  5. Fix the small items. Use sigmoid_log2/fast_sigmoid from _gluon_kernels/common/utils.py instead of the hand-written sigmoid (kernel :69-76,356-357). Fold the two _one_token calls that differ only in constexprs (:569-641) into one call. Add tests for o=None, for a 4D o, and for the untested decline branches: K/V != 128, bad A_log/dt_bias/cu_seqlens, and bad o dtype, stride or shape. Fix the docstrings: in _gating_case (test_kda_atom.py:49) the odd rows fork, not "every second row" (:68). "Contiguous slots" (kda_gating.py:46) is not checked. The o rules and the rule that the read table must match the write table's shape and strides are missing. With o=None, rows of empty or negative-read sequences stay uninitialized.

Re-reviewed at 5d138c4. Already fixed: Copilot's capacity checks (table rows, 2D width, accepted length), device checks, the masked read-slot load for empty spec sequences, and the bench_kda.py fp32 dtypes and --device.

@Liang-jianhao97

Copy link
Copy Markdown
Contributor Author

@aiter-bot please review again

attention/kda_atom.py is merged into attention/kda_gating.py. The entry
is kda_gating_decode, without beta, threshold and is_kda, and cu_seqlens
is int32. supports() checks the gate, the state and activation dtypes,
the head sizes and is_gfx1250_family(get_gfx_runtime()), so that a
caller can select its route one time. kda_gating_decode calls it on each
call.

The entry now declines a 1D slot table with more tokens than sequences,
and speculative verify skips a sequence whose accepted count is below 1.
Each decline logs its reason at DEBUG through AiterTritonLogger.

The kernel uses fast_sigmoid from _gluon_kernels/common/utils.py. The
in-place path at up to 4596 sequence-heads keeps the IEEE divide that
its tuned config selects, because fast_sigmoid makes it up to 14%
slower.

The test is now test_kda_gating.py, with cases for o, supports() and
each decline path. bench_kda gets recurrent backends, which time
fused_recurrent_kda on the inputs of the gating backends.

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Action required before merge (3)

  1. Compare this kernel with fused_recurrent_kda, or add the read-slot table to it (still open). Rule 1 of aiter/ops/triton/README.md applies. bench_kda.py now has the recurrent_same / recurrent_spec backends, but the description gives no numbers from them. Post gating_same vs recurrent_same and gating_spec vs recurrent_spec at H = 12/24/48/96 with --timing rotating. If fused_recurrent_kda is as fast on the no-fork shapes, add the read-slot table to it instead of a second kernel.
  2. Re-measure and re-validate at ec44f53, then update the description. This head changes the kernel math. The non-in-place _one_token path now defaults to FAST_DIV=True (kernel :121), and _multi_token_pre now uses fast_sigmoid (:356-357). The non-in-place path runs every fork and every decode at ≤ 180 sequence-heads (INPLACE_VEC: 0). The speed-up tables, "35 passed" and the self-review revision are all from 7bf8076, and aiter-bot still reports FAIL. The description also names kda_atom.py, test_kda_atom.py and fused_sigmoid_gating_delta_rule_update, which this head removed. Post a pytest log of test_kda_gating.py and the perf table at head. No CI job runs this file on gfx1250: it is skipped on MI35X, and ffm-bringup.yaml uses its own test branch.
  3. Fix the small items. Fold the two _one_token calls that differ only in constexprs (kernel :571-643). The docstring "Both paths compute the same values" (:466) is now wrong: the in-place path can use the IEEE divide and the other path uses fast_dividef. resolve_config_dir(..., arch="gfx1250") (:659) is outside the two arch= fallbacks that configs/AGENTS.md allows. Add it to that rule, or resolve gfx1250-strict the way the other gfx1250 Gluon loaders do.

Re-reviewed at ec44f53. Already fixed: the supports() predicate, which the entry calls and which ROCm/ATOM#3362 now calls instead of its hand copy; the generic module and entry names; the beta/threshold removal and int32 cu_seqlens; the 1D T > n_seq decline; the masked accepted < 1 read with its test; DEBUG decline logs; fast_sigmoid; tests for o=None, a 4D o and the decline branches; the _gating_case docstring; all of Copilot's items.

- Fold the two _one_token calls into one call in a gl.static_range(2) loop.
  The in-place copy is first, so the LDS barrier that the compiler adds
  between the copies is on the fork path.
- Correct the kernel docstring: the INPLACE_* config can use the IEEE
  divide, and the other one-token programs use fast_dividef.
- Resolve the config directory by the running arch, as the other gfx1250
  Gluon loaders do. supports() is now True only on gfx1250, because
  gfx1250-strict has no config tree.
- Get the arch from arch_info, so that the entry imports with
  AITER_TRITON_ONLY=1.
- Test that supports() is False on gfx1250-strict, and run the test module
  only on gfx1250.
@Liang-jianhao97

Copy link
Copy Markdown
Contributor Author

⚠️ Action required before merge (3)

  1. Compare this kernel with fused_recurrent_kda, or add the read-slot table to it (still open). Rule 1 of aiter/ops/triton/README.md applies. bench_kda.py now has the recurrent_same / recurrent_spec backends, but the description gives no numbers from them. Post gating_same vs recurrent_same and gating_spec vs recurrent_spec at H = 12/24/48/96 with --timing rotating. If fused_recurrent_kda is as fast on the no-fork shapes, add the read-slot table to it instead of a second kernel.
  2. Re-measure and re-validate at ec44f53, then update the description. This head changes the kernel math. The non-in-place _one_token path now defaults to FAST_DIV=True (kernel :121), and _multi_token_pre now uses fast_sigmoid (:356-357). The non-in-place path runs every fork and every decode at ≤ 180 sequence-heads (INPLACE_VEC: 0). The speed-up tables, "35 passed" and the self-review revision are all from 7bf8076, and aiter-bot still reports FAIL. The description also names kda_atom.py, test_kda_atom.py and fused_sigmoid_gating_delta_rule_update, which this head removed. Post a pytest log of test_kda_gating.py and the perf table at head. No CI job runs this file on gfx1250: it is skipped on MI35X, and ffm-bringup.yaml uses its own test branch.
  3. Fix the small items. Fold the two _one_token calls that differ only in constexprs (kernel :571-643). The docstring "Both paths compute the same values" (:466) is now wrong: the in-place path can use the IEEE divide and the other path uses fast_dividef. resolve_config_dir(..., arch="gfx1250") (:659) is outside the two arch= fallbacks that configs/AGENTS.md allows. Add it to that rule, or resolve gfx1250-strict the way the other gfx1250 Gluon loaders do.

Re-reviewed at ec44f53. Already fixed: the supports() predicate, which the entry calls and which ROCm/ATOM#3362 now calls instead of its hand copy; the generic module and entry names; the beta/threshold removal and int32 cu_seqlens; the 1D T > n_seq decline; the masked accepted < 1 read with its test; DEBUG decline logs; fast_sigmoid; tests for o=None, a 4D o and the decline branches; the _gating_case docstring; all of Copilot's items.

Thanks. 1c4ed7d fixes the three items, and the description now gives the data at 1c4ed7d.

1. Comparison with fused_recurrent_kda: done.
bench_kda.py --timing rotating --metric time --runs 3 on gfx1250 at 1c4ed7d, µs, median of 3 runs, mean of two rounds. fused_recurrent_kda is the version at the merge base (e393136). Main has not changed its kernel or its configs since then: #8075 adds only the plugin route to kda.py.

Decode (T = 1):

H B gating_same recurrent_same Speed-up
12 1 2.27 2.50 1.10x
12 16 4.31 5.37 1.25x
12 72 10.50 16.23 1.55x
12 256 28.93 47.04 1.63x
12 512 61.83 85.36 1.38x
24 1 2.37 2.69 1.13x
24 16 6.04 8.58 1.42x
24 72 18.28 28.22 1.54x
24 256 61.75 84.77 1.37x
24 512 123.49 158.05 1.28x
48 1 2.52 3.03 1.20x
48 16 9.43 14.00 1.48x
48 72 33.47 51.22 1.53x
48 256 123.20 157.66 1.28x
48 512 246.02 307.76 1.25x
96 1 3.36 3.73 1.11x
96 16 15.86 25.40 1.60x
96 72 76.89 94.00 1.22x
96 256 246.90 307.03 1.24x
96 512 505.89 611.64 1.21x

Speculative verify (T = 8, no read table):

H B gating_spec recurrent_spec Speed-up
12 1 5.16 7.68 1.49x
12 16 9.07 22.14 2.44x
12 72 33.90 53.75 1.59x
24 1 5.20 7.99 1.54x
24 16 15.71 25.31 1.61x
24 72 67.99 97.90 1.44x
48 1 5.39 9.00 1.67x
48 16 30.05 45.26 1.51x
48 72 145.41 188.10 1.29x
96 1 7.59 14.68 1.93x
96 16 59.73 84.37 1.41x
96 72 297.14 363.23 1.22x

kda_gating_decode is faster than fused_recurrent_kda on all 32 shapes: 1.10x to 1.63x in decode and 1.22x to 2.44x in speculative verify. The smallest gains are at B = 1 in decode (1.10x to 1.20x), where both ops take 2 to 4 µs. Thus fused_recurrent_kda is not as fast on the no-fork shapes. A read-slot table in fused_recurrent_kda would add forks, but not this speed, so I keep the separate kernel.

2. Re-measure and re-validate at the head: done.

  • pytest op_tests/triton_tests/attention/test_kda_gating.py -v on gfx1250 at 1c4ed7d: 59 passed. The log is below.
  • ATOM's kernel vs this entry, measured again at 1c4ed7d: all 100 shapes match ATOM's outputs and states, and the entry is 1.16x to 1.91x faster (median of 3 runs). With Kimi-K3's fused beta at H = 12, it is 1.23x to 1.87x faster. The tables are in the description.
  • [gfx1250] KDA Decode with AITER fused gating on GFX1250 ATOM#3362 at ROCm/ATOM@8f2903b62 with this tree: 22 passed (6 dispatch, 16 parity).
  • The description is new for 1c4ed7d. It names kda_gating.py, kda_gating_decode and test_kda_gating.py, the reviewed revision is 1c4ed7d, and "Changed op tests" lists test_kda_gating.py.
pytest log
============================= test session starts ==============================
platform linux -- Python 3.12.3, pytest-9.0.3, pluggy-1.6.0 -- /usr/local/bin/python3
rootdir: /workspace/aiter_gating
configfile: pyproject.toml
plugins: dash-3.1.1, timeout-2.4.0, anyio-4.14.2
collecting ... collected 59 items

op_tests/triton_tests/attention/test_kda_gating.py::test_same_slots_match_single_index_kernel PASSED [  1%]
op_tests/triton_tests/attention/test_kda_gating.py::test_fork_reads_one_slot_and_writes_another PASSED [  3%]
op_tests/triton_tests/attention/test_kda_gating.py::test_negative_read_skips_and_negative_write_keeps_output PASSED [  5%]
op_tests/triton_tests/attention/test_kda_gating.py::test_speculative_verify_forks_from_the_accepted_column PASSED [  6%]
op_tests/triton_tests/attention/test_kda_gating.py::test_speculative_verify_without_fork_matches_single_index PASSED [  8%]
op_tests/triton_tests/attention/test_kda_gating.py::test_speculative_verify_skips_a_sequence_with_a_count_below_one PASSED [ 10%]
op_tests/triton_tests/attention/test_kda_gating.py::test_output_may_be_none_or_have_the_shape_of_v[none] PASSED [ 11%]
op_tests/triton_tests/attention/test_kda_gating.py::test_output_may_be_none_or_have_the_shape_of_v[4d] PASSED [ 13%]
op_tests/triton_tests/attention/test_kda_gating.py::test_supports_checks_the_model_setup[kimi-k3] PASSED [ 15%]
op_tests/triton_tests/attention/test_kda_gating.py::test_supports_checks_the_model_setup[no-lower-bound] PASSED [ 16%]
op_tests/triton_tests/attention/test_kda_gating.py::test_supports_checks_the_model_setup[bf16-state] PASSED [ 18%]
op_tests/triton_tests/attention/test_kda_gating.py::test_supports_checks_the_model_setup[k64] PASSED [ 20%]
op_tests/triton_tests/attention/test_kda_gating.py::test_supports_checks_the_model_setup[v64] PASSED [ 22%]
op_tests/triton_tests/attention/test_kda_gating.py::test_supports_checks_the_model_setup[fp32-activations] PASSED [ 23%]
op_tests/triton_tests/attention/test_kda_gating.py::test_supports_needs_gfx1250_config_tables PASSED [ 25%]
op_tests/triton_tests/attention/test_kda_gating.py::test_cuda_graph_replay_uses_updated_slots PASSED [ 27%]
op_tests/triton_tests/attention/test_kda_gating.py::test_gating_kernel_matches_reference[decode-1-12-12-dtype0] PASSED [ 28%]
op_tests/triton_tests/attention/test_kda_gating.py::test_gating_kernel_matches_reference[decode-16-12-12-dtype1] PASSED [ 30%]
op_tests/triton_tests/attention/test_kda_gating.py::test_gating_kernel_matches_reference[decode-384-12-12-dtype2] PASSED [ 32%]
op_tests/triton_tests/attention/test_kda_gating.py::test_gating_kernel_matches_reference[fork-15-12-12-dtype3] PASSED [ 33%]
op_tests/triton_tests/attention/test_kda_gating.py::test_gating_kernel_matches_reference[fork-16-12-12-dtype4] PASSED [ 35%]
op_tests/triton_tests/attention/test_kda_gating.py::test_gating_kernel_matches_reference[fork-384-12-12-dtype5] PASSED [ 37%]
op_tests/triton_tests/attention/test_kda_gating.py::test_gating_kernel_matches_reference[spec-8-12-12-dtype6] PASSED [ 38%]
op_tests/triton_tests/attention/test_kda_gating.py::test_gating_kernel_matches_reference[spec-9-12-12-dtype7] PASSED [ 40%]
op_tests/triton_tests/attention/test_kda_gating.py::test_gating_kernel_matches_reference[decode-8-24-24-dtype8] PASSED [ 42%]
op_tests/triton_tests/attention/test_kda_gating.py::test_gating_kernel_matches_reference[fork-4-48-48-dtype9] PASSED [ 44%]
op_tests/triton_tests/attention/test_kda_gating.py::test_gating_kernel_matches_reference[spec-9-24-24-dtype10] PASSED [ 45%]
op_tests/triton_tests/attention/test_kda_gating.py::test_gating_kernel_matches_reference[spec-2-48-48-dtype11] PASSED [ 47%]
op_tests/triton_tests/attention/test_kda_gating.py::test_gating_kernel_matches_reference[decode-16-12-12-dtype12] PASSED [ 49%]
op_tests/triton_tests/attention/test_kda_gating.py::test_gating_kernel_matches_reference[spec-9-12-12-dtype13] PASSED [ 50%]
op_tests/triton_tests/attention/test_kda_gating.py::test_gating_kernel_matches_reference[fork-16-12-24-dtype14] PASSED [ 52%]
op_tests/triton_tests/attention/test_kda_gating.py::test_gating_kernel_matches_reference[spec-9-12-24-dtype15] PASSED [ 54%]
op_tests/triton_tests/attention/test_kda_gating.py::test_gating_kernel_matches_reference[multi-8-12-12-dtype16] PASSED [ 55%]
op_tests/triton_tests/attention/test_kda_gating.py::test_gating_kernel_matches_reference[multi-9-12-12-dtype17] PASSED [ 57%]
op_tests/triton_tests/attention/test_kda_gating.py::test_cuda_graph_replay_follows_new_slots_and_lengths[decode-16] PASSED [ 59%]
op_tests/triton_tests/attention/test_kda_gating.py::test_cuda_graph_replay_follows_new_slots_and_lengths[spec-9] PASSED [ 61%]
op_tests/triton_tests/attention/test_kda_gating.py::test_strided_beta_is_read_with_its_token_stride PASSED [ 62%]
op_tests/triton_tests/attention/test_kda_gating.py::test_unsupported_inputs_return_none_without_writes[not_in_place] PASSED [ 64%]
op_tests/triton_tests/attention/test_kda_gating.py::test_unsupported_inputs_return_none_without_writes[no_l2norm] PASSED [ 66%]
op_tests/triton_tests/attention/test_kda_gating.py::test_unsupported_inputs_return_none_without_writes[no_lower_bound] PASSED [ 67%]
op_tests/triton_tests/attention/test_kda_gating.py::test_unsupported_inputs_return_none_without_writes[bf16_state] PASSED [ 69%]
op_tests/triton_tests/attention/test_kda_gating.py::test_unsupported_inputs_return_none_without_writes[k_dim_64] PASSED [ 71%]
op_tests/triton_tests/attention/test_kda_gating.py::test_unsupported_inputs_return_none_without_writes[v_dim_64] PASSED [ 72%]
op_tests/triton_tests/attention/test_kda_gating.py::test_unsupported_inputs_return_none_without_writes[fp32_activations] PASSED [ 74%]
op_tests/triton_tests/attention/test_kda_gating.py::test_unsupported_inputs_return_none_without_writes[value_heads_not_a_multiple] PASSED [ 76%]
op_tests/triton_tests/attention/test_kda_gating.py::test_unsupported_inputs_return_none_without_writes[short_A_log] PASSED [ 77%]
op_tests/triton_tests/attention/test_kda_gating.py::test_unsupported_inputs_return_none_without_writes[strided_dt_bias] PASSED [ 79%]
op_tests/triton_tests/attention/test_kda_gating.py::test_unsupported_inputs_return_none_without_writes[int64_cu_seqlens] PASSED [ 81%]
op_tests/triton_tests/attention/test_kda_gating.py::test_unsupported_inputs_return_none_without_writes[tokens_past_1d_table] PASSED [ 83%]
op_tests/triton_tests/attention/test_kda_gating.py::test_unsupported_inputs_return_none_without_writes[fp32_output] PASSED [ 84%]
op_tests/triton_tests/attention/test_kda_gating.py::test_unsupported_inputs_return_none_without_writes[strided_output] PASSED [ 86%]
op_tests/triton_tests/attention/test_kda_gating.py::test_unsupported_inputs_return_none_without_writes[short_output] PASSED [ 88%]
op_tests/triton_tests/attention/test_kda_gating.py::test_unsupported_inputs_return_none_without_writes[int64_slots] PASSED [ 89%]
op_tests/triton_tests/attention/test_kda_gating.py::test_unsupported_inputs_return_none_without_writes[read_table_shape] PASSED [ 91%]
op_tests/triton_tests/attention/test_kda_gating.py::test_unsupported_inputs_return_none_without_writes[accepted_with_1d_slots] PASSED [ 93%]
op_tests/triton_tests/attention/test_kda_gating.py::test_unsupported_inputs_return_none_without_writes[short_slot_table] PASSED [ 94%]
op_tests/triton_tests/attention/test_kda_gating.py::test_unsupported_inputs_return_none_without_writes[zero_width_slot_table] PASSED [ 96%]
op_tests/triton_tests/attention/test_kda_gating.py::test_unsupported_inputs_return_none_without_writes[short_accepted] PASSED [ 98%]
op_tests/triton_tests/attention/test_kda_gating.py::test_unsupported_inputs_return_none_without_writes[cpu_slot_table] PASSED [100%]

============================== 59 passed in 6.79s ==============================

3. Small items: done.

  • Fold: there is now one _one_token call. It is in a gl.static_range(2) loop, and each iteration gives the call one constexpr set (USE_FORK selects TK, VEC, the cache policies, the gate distribution, the store burst and the divide). The run-time test slot_out == slot_in selects the iteration that runs. With INPLACE_VEC = 0 (up to 180 sequence-heads) the test is a constexpr False, so the in-place iteration is not compiled.
    I compiled the 7 kernel variants of DEFAULT.json for gfx1250 at ec44f53 and at 1c4ed7d (each bucket, and multi-token with and without speculative verify). 6 of 7 have the same instructions and register counts. In one_token any (more than 4596 sequence-heads), the in-place code is the same, and the fork code has one more LDS barrier: the compiler cannot see that only one iteration runs. The in-place iteration is first, so the barrier is on the fork path, and a comment in the kernel gives this rule. On the 8 gating_fork shapes above 4596 sequence-heads, the head is within 0.5% of ec44f53 (0.996 to 1.005).
  • Docstring at :466: it now says that the other one-token programs, and all of them when INPLACE_VEC is 0, compute the sigmoids with fast_sigmoid (fast_dividef). The INPLACE_* config uses the IEEE divide when INPLACE_FAST_DIV is False, so the two configs can give results that are different in the last bits.
  • Config dir: arch="gfx1250" is removed. The loader now resolves by the running arch, as the other gfx1250 Gluon loaders do (kda_decode.py:1000, chunk_kda/prepare.py:15, chunk_kda/walk.py:14). configs/AGENTS.md lists no gfx1250-strict tree, keeps arch fallbacks to MHC and fused_clamp_act_mul, and says not to copy the MHC fallback to other families, so I did not add a third one. Thus supports() is now True only on gfx1250. On gfx1250-strict, the entry declines with a DEBUG log, and the caller keeps its own kernel. It does not get to the config load, which looks for configs/gfx1250-strict/ and raises FileNotFoundError (the loader of fused_recurrent_kda reads the same kind of path there). The test module now runs only on gfx1250, and the new test_supports_needs_gfx1250_config_tables sets the arch to gfx1250-strict and checks that supports() is False. When tuned configs for gfx1250-strict are in configs/gfx1250-strict/, supports() can accept that arch again.
  • The wrapper now gets the arch from arch_info.get_arch(), as kda.py does. This removes the chip_info import, so the module imports with AITER_TRITON_ONLY=1. At ec44f53, the import raised ModuleNotFoundError: No module named 'build_targets'.

@Liang-jianhao97

Copy link
Copy Markdown
Contributor Author

@aiter-bot re-review

gbyu-amd added a commit that referenced this pull request Nov 24, 2026
…26-11-24T05:30:11Z)

bench_kda.py keeps this branch's version: it predates #7990's bench changes
that #8538's --state_dtype option builds on.
@Liang-jianhao97
Liang-jianhao97 merged commit 935ede7 into main Nov 25, 2026
68 checks passed
@Liang-jianhao97
Liang-jianhao97 deleted the feat/gfx1250-kda-gating branch November 25, 2026 05:33
sumin-hong added a commit to moreh-dev/rocm-aiter that referenced this pull request Dec 1, 2026
Merge upstream main b2bca5d and retain both the gate-fold imports and
ROCm#7990's kda_gating benchmark imports. Keep the existing review history.
Preserve the upstream benchmark/test updates and unrelated plugin contracts.
The gate-fold kernel, public wrapper and the two provider v2 contracts
are unchanged from the previous review head.

KDA CPU guards (2), upstream plugin-contract tests (18), source/AST,
Black 26.10.1, Ruff 0.16.0 and feature diff checks passed.
No new local GPU, ISA, model, benchmark or E2E run was performed.

Co-authored-by: OpenAI Codex <[email protected]>
Signed-off-by: Sumin Hong <[email protected]>
gbyu-amd pushed a commit that referenced this pull request Dec 3, 2026
…7916 @ 7e2f22e, head 2026-11-16T05:44:05Z)

Applied as the diff 8bbce0d..7e2f22e (8 files) onto the rebased 1116 tree; PR state: open, author Liang-jianhao97, base main.

(cherry picked from commit becedb0)

Rebase onto main 12-03: main #8061 moved fast_launch from _triton_kernels/kimi_delta_attn/ to utils/fast_launch.py and already takes the ordinary path while a launch hook is set (this PR's _launch_hooks_idle). The old file stays deleted; this PR's other fast_launch change, falling back to the ordinary launch when CompiledKernel.run raises TypeError (launcher ABI changed), is ported into utils/fast_launch.py as a per-wrapper disable. kda_one_token.py and test_kda_one_token.py import utils.fast_launch. bench_kda.py keeps main's gating / recurrent case backends (#7990) and adds this PR's one_token / generic backends, --padded, and a shape check per family; --timing rotating takes both families.
gbyu-amd added a commit that referenced this pull request Dec 3, 2026
…26-11-24T05:30:11Z)

bench_kda.py keeps this branch's version: it predates #7990's bench changes
that #8538's --state_dtype option builds on.

(cherry picked from commit 1c16538)
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