Skip to content

gfx1250: HIP kernel for the KDA ReplaySSM decode / verify step - #7951

Draft
gbyu-amd wants to merge 4 commits into
mainfrom
gyu/gfx1250-kda-replayssm-decode
Draft

gbyu-amd wants to merge 4 commits into
mainfrom
gyu/gfx1250-kda-replayssm-decode

Conversation

@gbyu-amd

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

Copy link
Copy Markdown
Contributor

Problem

The decode / speculative-verify step of KDA (Kimi Delta Attention) under ReplaySSM — ATOM's Triton replayssm_sigmoid_gating_delta_rule (fla_ops/replayssm.py) — is latency-bound on MI455X (gfx1250). Per (request, value head) it:

  • rebuilds the state from an fp32 checkpoint and up to cache_len - window (k, u, g) records;
  • runs the gated delta rule over the step's tokens;
  • appends their records, and rewrites the checkpoint when the buffer is about to fill.

At Kimi-K3's shape (12 value heads per TP8 rank, K = V = 128, a 5-token verify window, cache_len 16) it moves 118 MB in 49 µs at 110 requests, i.e. 2.5 TB/s. It is also only 1.2x faster than the same kernel on MI355X. Two things hold it back on gfx1250:

  • Cross-lane reductions per token. The state tile spreads K across the 32 lanes of a wave. Each token's two K-reductions are therefore 5-step butterflies at one ~400-VGPR wave per SIMD.
  • Memory ops under divergent control flow. gfx1250 makes a wave wait for its outstanding memory transactions (s_wait_xcnt) before EXEC changes. A load or store under a divergent branch therefore costs a full memory round trip.

Change

A torch-free JIT module module_kda_replayssm_decode:

  • aiter.ops.kda_replayssm.kda_replayssm_decode(...) has the same arguments, layouts and in-place updates of the checkpoint and the record buffers as the Triton function.
  • kda_replayssm_decode_supported(...) says when it applies:
    • K = V = 128;
    • a window of ≤ 8 tokens and cache_len ≤ 16;
    • bf16 q/k/v/gate/beta, an fp32 checkpoint, bf16 k/u records and fp32 or bf16 g records;
    • HV a multiple of H.
  • Both gates are supported (lower-bounded sigmoid, -exp(A_log)·softplus), and the q/k L2 norm is optional.
  • a (gate input) and b (beta) may be column views of a wider buffer, as Kimi-K3 passes beta. They are read by token stride with no copy, as long as each token's row is dense; any other layout is copied.

One block per (request, value head) runs three phases separated by barriers:

  1. Staging. 16 threads per 256-byte row load the step's q/k/v/gate rows and the record rows.
    • Loads are 16 bytes wide, with branch-free clamped row indices, so every load is in flight at once.
    • The record rows are clamped to the buffer, not to write_pos, so their loads do not wait for it.
    • The gates, all exponentials and the q/k norms (a DPP row reduction) are computed once per element and parked in LDS.
    • The 64 KB checkpoint tile is loaded behind them into registers.
  2. Compute.
    • A group of 4 adjacent lanes owns 4 V-rows of the 128 × 128 fp32 state (2 rows on wave64 parts).
    • Lane kq owns the 16-byte column chunks kq, kq+4, ….
    • Each K-reduction is therefore 32 in-lane FMAs plus two DPP quad_perm adds.
    • The records are replayed two at a time.
    • Per-token outputs and u go to LDS.
  3. Write-back. All global stores of the step (o and the u/k/g records), coalesced, under block-uniform conditions.
    • Nothing touches memory inside divergent control flow.

The staging barrier also orders every record read of the replay before the record writes of a flush. A flush rewrites the records from position 0, and in the Triton kernel the programs of one head can race on it.

Files:

  • new: csrc/kernels/kda_replayssm_decode.cu, csrc/include/kda_replayssm_decode.h, csrc/pybind/kda_replayssm_decode_pybind.cu, aiter/ops/kda_replayssm.py, op_tests/test_kda_replayssm_decode.py;
  • changed: the KDA_REPLAYSSM_DECODE_PYBIND macro in rocm_ops.hpp and the module entry in optCompilerConfig.json.

Nothing existing changes behaviour. Callers opt in, e.g. ATOM behind ATOM_REPLAYSSM_KDA_HIP=1.

Fused short convolution: kda_replayssm_decode_conv

On the speculative-decoding path q, k and v come from a width-4 causal convolution + SiLU over the mixed q | k | v projection (causal_conv1d_update with num_accepted_tokens), a separate kernel launched right before the recurrence. kda_replayssm_decode_conv(x, conv_state, conv_weight, conv_state_indices, num_accepted_tokens, ...) runs both in one kernel:

  • In the staging phase three waves load the step's inputs and the state window, read at num_accepted − 1 (from conv_state_indices_in when a forked state is resumed). Each lane owns 4 adjacent channels of one of q, k, v (2 on wave64 parts).
  • They convolve in fp32 in the conv kernel's order, round to bf16 as the unfused path stores q/k/v, and put the result in LDS. They also write the new window [hist₁, hist₂, x₀ … x_{T−1}] in place.
  • After one more barrier q and k are normalised from LDS as above. q, k and v never go through global memory.
  • The conv state may be any [lines, dim, len] view. A unit channel stride (the token-major layout ATOM and vLLM allocate) takes one 8-byte access per lane and token; other strides take per-channel accesses.
  • The index tensors may be strided views (Kimi-K3 passes column 0 of its [batch, window] slot table).
  • It needs H == HV, so each block owns its head's q, k and v channels. kda_replayssm_decode_conv_supported(...) says when it applies.

Results

MI455X, one GPU, profiler kernel time (median of 30 calls). Inputs are rotated so they are not cache-resident, and pre-touched. Shape: 12 value heads, 5-token window, cache_len 16, record cursors uniform over the buffer (so about 40% of the requests flush), fp32 checkpoint and g records — the layout ATOM allocates.

requests Triton µs this PR µs speedup
8 13.8 9.7 1.42x
32 19.7 13.7 1.43x
110 49.9 28.2 1.77x
  • At 8 requests about 2 µs of each call is fixed launch/drain. The rest is set by the slowest block (11 records plus a flush), and its staging is two dependent memory latencies.
  • The kernel also builds for gfx950 (wave64, 2 V-rows per lane). There the gain is smaller: 16.2 → 14.7, 24.6 → 23.3 and 60.9 → 49.7 µs.

Decode chain, conv + ReplaySSM. Same method, on the serving layouts: mixed q|k|v and beta are column views of the fused in-projection output, the conv state is token-major (seen transposed), and the conv slots are a column view of the slot table. Time is every kernel the chain launches; the Triton chain includes the beta copy its wrapper makes.

requests Triton conv + Triton ReplaySSM µs Triton conv + kda_replayssm_decode µs kda_replayssm_decode_conv µs vs Triton chain
8 23.3 14.7 12.1 1.93x
32 31.6 19.6 16.5 1.92x
110 61.3 35.9 33.2 1.85x

On gfx950 the fused kernel takes the Triton chain from 24.0 / 35.5 / 75.1 µs to 16.4 / 25.8 / 56.0 µs.

Correctness

python -m pytest op_tests/test_kda_replayssm_decode.py: 197 passed (gfx1250 and gfx950). The reference is an fp32 PyTorch ReplaySSM step, and the grid covers:

  • 1/3/8/32 requests and windows of 1/2/5/8 tokens;
  • H = HV and GQA (HV = 2H);
  • fp32 and bf16 g records, and both gates;
  • an empty sequence, a shorter sequence, a padded slot_idx of −1, and the write_pos −1 sentinel;
  • flushing and non-flushing requests.

It checks the output, the checkpoint (rewritten only on a flush) and every record row (appended at base + t, the rest untouched).

Two more cases pass gate and beta as column views of a fused buffer (head steps 1 and 2). Their results are bitwise equal to contiguous inputs.

The fused op is checked against a PyTorch conv reference feeding the ReplaySSM reference, over the same request/window grid, both g record dtypes, and both a dim-major and a token-major (transposed) conv state. It compares the output, the checkpoint, the records and the rewritten conv state (bitwise). One more case passes strided index views and a forked read slot; its results are bitwise equal to contiguous indices.

Against the Triton kernel itself, through ATOM's replayssm_sigmoid_gating_delta_rule:

  • max |Δo| is 6e-5;
  • k and g records are equal (g to 5e-7);
  • u records differ by at most one bf16 ulp;
  • checkpoints agree to 7e-7.

Testing

  • Build. The new module built by aiter's JIT (hipcc, --offload-arch=gfx1250, and gfx950) on aiter trees from 2026-11-13.
    • The module only uses aiter_tensor.h, aiter_stream.h and aiter_hip_common.h.
    • The rocm_ops.hpp / optCompilerConfig.json changes are additions.
  • Decode chain. The fused op matches Triton conv + Triton ReplaySSM on the serving layouts: output within bf16 rounding, conv state bitwise, checkpoints and records within 2e-2 (one bf16 ulp).
  • Lint. black 26.10.1 and ruff 0.16.0 are clean.

New torch-free JIT module module_kda_replayssm_decode (aiter.ops.kda_replayssm): the KDA (Kimi Delta Attention) ReplaySSM decode / speculative-verify step with the semantics of the Triton replayssm_sigmoid_gating_delta_rule, for K = V = 128, windows <= 8 tokens, cache_len <= 16. No memory access under divergent control flow (gfx1250 s_wait_xcnt), DPP reductions, 16-byte staging; one block per (request, head) also orders replay reads before flush writes. MI455X: 1.42x / 1.43x / 1.77x vs the Triton kernel at 8 / 32 / 110 requests (Kimi-K3 shape). op test: 130 passed.
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter standard tests on MI35X
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
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 Radeon R9700 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 7951 --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.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

…s of a fused buffer, no copy)

Kimi-K3 passes beta as a column view of its fused input projection; the op now reads a and b by token stride when each token's row is dense (16-byte aligned for a), and copies only other layouts. Test: two strided cases, bitwise equal to contiguous inputs (132 passed).
…eplayssm_decode_conv)

On the verify path q, k and v come from a width-4 causal conv + SiLU over the mixed q|k|v projection
(causal_conv1d_update with num_accepted_tokens). kda_replayssm_decode_conv runs it in the staging phase of the
ReplaySSM kernel: three waves load the inputs and the state window (each lane 4 adjacent channels, 2 on wave64),
convolve in fp32, round to bf16 into LDS and rewrite the window in place, so q/k/v never go through global memory.
Unit-channel-stride conv states (token-major, as ATOM/vLLM allocate) use one 8-byte access per lane and token,
other strides per-channel accesses; index tensors may be strided views. Requires H == HV.

Tests: fused op vs a torch conv reference feeding the ReplaySSM reference (dim- and token-major conv state, conv
state bitwise), strided index views and a forked read slot (bitwise vs contiguous). 197 passed on gfx1250 and gfx950.
gbyu-amd added a commit that referenced this pull request Dec 3, 2026
9276671, head 2026-11-13T22:51:38Z)

Applied as the diff 5c2b75c..9276671 (7 files) onto the rebased 1116 tree; PR state: draft, author gbyu-amd, base main.

(cherry picked from commit 31b1b87)

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.

1 participant