Repository navigation
Conversation
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.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 withATOM_GDN_SSM_DTYPE=fp16orbf16, which halves the state pool. At FP16 that fallback (ATOM'sfused_sigmoid_gating_delta_rule_update) is already faster than this kernel at FP32, because it moves half the state bytes.Technical Details
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.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 newone_token_16bit_stateandmulti_token_16bit_statetables in the gfx1250DEFAULT.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.supports()and unsupported-input cases now treat BF16 as supported and FP64 as the unsupported state dtype.bench_kda.pytakes--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_updateon an FP16 pool, i.e. the fallback this PR replaces.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
op_tests/triton_tests/attention/test_kda_gating.py: 87 passed on gfx1250. The five changed files were run on an aiter build that includes [Triton/Gluon] [gfx1250] Add a gfx1250 Gluon KDA gating kernel for ATOM's decode entry. #7990.black26.10.1 andruff0.16.0 are clean on the changed files.