Skip to content

[Triton/Gluon] [gfx1250] KDA gating: take an FP16 or BF16 state pool - #8538

Draft
gbyu-amd wants to merge 5 commits into
mainfrom
gyu/gfx1250-kda-gating-fp16-state
Draft

gbyu-amd wants to merge 5 commits into
mainfrom
gyu/gfx1250-kda-gating-fp16-state

Conversation

@gbyu-amd

@gbyu-amd gbyu-amd commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #7990: the base is its branch, feat/gfx1250-kda-gating.

Motivation

kda_gating_decode (#7990) takes an FP32 state pool only. A model that keeps its KDA state in 16 bits falls back to the caller's Triton kernel. Examples are ATOM with ATOM_GDN_SSM_DTYPE=fp16 or bf16, which halves the state pool. At FP16 that fallback (ATOM's fused_sigmoid_gating_delta_rule_update) is already faster than this kernel at FP32, because it moves half the state bytes.

Technical Details

  • Kernel. Each state load is cast to FP32, and each state store casts to the pool dtype (state_ptr.dtype.element_ty). The recurrence stays in FP32 across the tokens of a sequence; only the stored states are rounded, as in ATOM's kernel and the test reference. For an FP32 pool the casts are no-ops.
  • supports() takes an FP32, FP16 or BF16 state.
  • Configs. get_kda_gating_config(num_seq_heads, multi_token, state_bytes) picks the table by the pool's element size. A 2-byte pool reads the new one_token_16bit_state and multi_token_16bit_state tables in the gfx1250 DEFAULT.json. They were tuned for an FP16 pool on in-place decode, fork and spec verify, with 12 and 96 value heads and 1-512 sequences. Each bucket is within 4% of the per-shape best (10% for the fork keys of one bucket). The FP32 tables are unchanged.
  • Tests.
    • FP16 and BF16 pools in decode, fork, spec verify, 2D tables without accepted counts and grouped value heads, plus CUDA graph replay.
    • The supports() and unsupported-input cases now treat BF16 as supported and FP64 as the unsupported state dtype.
    • The state tolerance follows the pool dtype.
  • bench_kda.py takes --state_dtype fp16, and the gating cases honor it.

Performance

MI455X (gfx1250), one GPU, us per call (median of CUDA-graph replays of 20 calls). K = V = 128, BF16 activations, beta a strided view of the fused projection. "Triton FP16" is ATOM's fused_sigmoid_gating_delta_rule_update on an FP16 pool, i.e. the fallback this PR replaces.

case value heads sequences Triton FP16 this kernel FP32 this kernel FP16 FP16 vs Triton FP16 FP16 vs FP32
decode, in place 12 1 3.43 2.57 2.22 1.55x 1.16x
12 8 3.92 3.57 2.39 1.64x 1.49x
12 32 5.87 9.34 3.09 1.90x 3.02x
12 64 9.91 16.68 3.80 2.61x 4.39x
12 128 15.20 23.84 6.71 2.27x 3.55x
12 256 25.62 30.93 13.22 1.94x 2.34x
96 1 3.87 3.54 2.42 1.60x 1.46x
96 8 9.88 16.52 3.87 2.55x 4.27x
96 32 25.44 30.29 13.12 1.94x 2.31x
96 64 45.50 62.24 37.40 1.22x 1.66x
96 128 86.18 124.35 72.90 1.18x 1.71x
96 256 173.18 243.23 142.80 1.21x 1.70x
spec verify, 5 tokens 12 1 7.61 4.43 3.88 1.96x 1.14x
12 8 8.40 6.02 5.16 1.63x 1.17x
12 32 12.98 11.67 8.26 1.57x 1.41x
12 64 21.72 21.41 12.54 1.73x 1.71x
12 128 37.71 42.38 26.51 1.42x 1.60x
96 1 8.45 6.27 5.28 1.60x 1.19x
96 8 21.40 22.15 13.77 1.55x 1.61x
96 32 70.17 91.71 52.79 1.33x 1.74x
96 64 144.98 185.69 105.01 1.38x 1.77x
96 128 312.28 392.87 205.31 1.52x 1.91x

FP32 pool, #7990's head vs this commit, same cases: every case is within run-to-run noise. 21 of 22 are within -2% to +3%; the outlier is the 1-sequence decode at 12 heads, which is 10% faster.

Testing

Liang-jianhao97 and others added 5 commits November 16, 2026 05:44
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.
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.
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.
- 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.
kda_gating_decode took an FP32 state pool only, so a model that keeps its
KDA state in 16 bits fell back to the caller's own kernel.

The kernel now loads the state tile to FP32, keeps the recurrence in FP32
across tokens and rounds each stored state to the pool dtype. supports()
takes FP32, FP16 and BF16 pools. A 2-byte pool reads its configs from the
new one_token_16bit_state and multi_token_16bit_state tables, tuned for an
FP16 pool on gfx1250; get_kda_gating_config takes the pool's element size.
An FP32 pool keeps its tables and its code (the FP32 load casts fold away).

The tests cover FP16 and BF16 pools in decode, fork, spec verify, 2D tables
without accepted counts and a CUDA graph replay. bench_kda.py takes
--state_dtype fp16.
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.
Base automatically changed from feat/gfx1250-kda-gating to main November 25, 2026 05:33
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)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants