Repository navigation
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
60a6a73 to
378b480
Compare
2a8bfe8 to
66bec98
Compare
… when it takes them Co-authored-by: Sealeen Zhang <[email protected]>
fd1db51 to
c801cdd
Compare
…ton) register_fwd_prepare(name, fn) installs a forward-intermediate recompute with the Triton chunk_delta_attn_fwd_prepare signature and 10-tuple result (e.g. #8744's FlyDSL prepare). It runs only when selected with prepare=name (also on chunk_kda_bwd_flydsl) or AITER_KDA_BWD_PREPARE=name; unknown names raise rather than silently falling back. Test: test_flydsl_fwd_prepare_hook. Co-authored-by: Sealeen Zhang <[email protected]>
f4a3452 to
d4a37e2
Compare
#8744's FlyDSL prepare returns fp32 Aqk/Akk from torch.empty, so Akk's upper triangle need not be zero as Triton's (zero-filled) one is. wy_dqkg (MFMA and FMA) staged the full Akk tile into its products; it now keeps only s <= t, as dav already does for Aqk. fp32 Aqk/Akk are otherwise handled per dtype (16- byte loads, bf16 MFMA operands); all fp32 variants compile. Tests: test_flydsl_fp32_prepare_outputs registers a prepare that returns fp32 Aqk/Akk with NaN upper triangles (dense and varlen) and must match the Triton prepare; test_backward_flydsl_prepare_flydsl checks prepare="flydsl" against the Triton backward (runs where #8744's kda_chunk_fwd is present). Co-authored-by: Sealeen Zhang <[email protected]>
06c87fc to
fb0cd43
Compare
76bd85e to
cb10900
Compare
) into kda-integration Conflicts: the chunk-fwd files (add/add against the older #8744 copy) take cb10900's version. chunk_delta_attn.py also takes it: the auto-merge kept fwd_backend from both #8739's and #8744's parameter order (a duplicate argument, SyntaxError); the two versions differ only in that order. Co-authored-by: Sealeen Zhang <[email protected]>
…s chunk fwd files and chunk_delta_attn.py) Co-authored-by: Sealeen Zhang <[email protected]>
…ith a shape check, falling back to Triton with the reason in LAST_PIECES and the log; note the save_fwd Triton-intermediates override Co-authored-by: Sealeen Zhang <[email protected]>
…ve_fwd intermediates) Co-authored-by: Sealeen Zhang <[email protected]>
13275a2 to
d591912
Compare
…/Akk) when selected, Triton disable_recompute otherwise; save_fwd self-check graded vs an fp32 reference, self-checks no longer abort main; stub plumbing test Co-authored-by: Sealeen Zhang <[email protected]>
…raded self-check, non-aborting self-checks; #8744 13275a2) into kda-integration Conflicts in op_tests/test_kda_fused_layer_bwd.py: - test_kda_save_fwd_matches_recompute takes #8739's new signature (chunk_bwd=); #8754's config_name_of and #8757's MXFP8 tests are kept - main(): #8739's non-aborting self-checks; #8757's test_kda_mxfp8_weight_cache joins them the same way (logged and recorded in SELF_CHECK_FAILURES instead of raising) Co-authored-by: Sealeen Zhang <[email protected]>
…s files) Co-authored-by: Sealeen Zhang <[email protected]>
c632635 to
f4f84cd
Compare
| from aiter.ops.flydsl.kda_chunk_bwd import chunk_kda_bwd_flydsl | ||
| from aiter.ops.flydsl import kda_chunk_fwd as fwd_mod | ||
| from aiter.ops.flydsl.kda_chunk_fwd import chunk_kda_fwd_flydsl | ||
| from aiter.ops.triton._triton_kernels.kimi_delta_attn import chunk_delta_attn_fwd | ||
|
|
There was a problem hiding this comment.
Import block is un-sorted or un-formatted
| from aiter.ops.flydsl.kda_chunk_bwd import chunk_kda_bwd_flydsl | |
| from aiter.ops.flydsl import kda_chunk_fwd as fwd_mod | |
| from aiter.ops.flydsl.kda_chunk_fwd import chunk_kda_fwd_flydsl | |
| from aiter.ops.triton._triton_kernels.kimi_delta_attn import chunk_delta_attn_fwd | |
| from aiter.ops.flydsl import kda_chunk_fwd as fwd_mod | |
| from aiter.ops.flydsl.kda_chunk_bwd import chunk_kda_bwd_flydsl | |
| from aiter.ops.flydsl.kda_chunk_fwd import chunk_kda_fwd_flydsl | |
| from aiter.ops.triton._triton_kernels.kimi_delta_attn import chunk_delta_attn_fwd | |
There was a problem hiding this comment.
Fixed in ee0e03f: imports sorted, and the file is black-formatted. Test-only change.
…e 3) compile_intra16 forms only the diagonal 16x16 blocks (head-major mx / Aqk) and compile_recurrence16 advances the state every 16 tokens, applying (I + L_II)^-1 per tile. Default AITER_KDA_FWD_RSOLVE=3 on the fused route with the lower_bound gate; elsewhere, or with AITER_KDA_FWD_INTRA16=0, it runs as rsolve 1.
| if rv: | ||
| if l4 == 0: | ||
| stg( | ||
| _flat(bt, fx.Int64(i_bh) * fx.Int64(T + BT) + fx.Int64(t0)), | ||
| r, | ||
| beta_r, | ||
| F32, | ||
| ) |
There was a problem hiding this comment.
Use a single if statement instead of nested if statements
| if rv: | |
| if l4 == 0: | |
| stg( | |
| _flat(bt, fx.Int64(i_bh) * fx.Int64(T + BT) + fx.Int64(t0)), | |
| r, | |
| beta_r, | |
| F32, | |
| ) | |
| if rv and l4 == 0: | |
| stg( | |
| _flat(bt, fx.Int64(i_bh) * fx.Int64(T + BT) + fx.Int64(t0)), | |
| r, | |
| beta_r, | |
| F32, | |
| ) |
There was a problem hiding this comment.
Kept the nested if as written and added # noqa: SIM102 in 84169a8 (formatting only; the AST is unchanged and the fwd bit-exact gate passed on every route).
| for mt in range_constexpr(MT): | ||
| acc_h = fx.Vector.filled(4, 0.0, fx.Float32) | ||
| for ks in range_constexpr(NS): | ||
| a_op = lload4(buf + QG_OFF + a_w + (mt * 16 * LQ + ks * 16) * 2) |
There was a problem hiding this comment.
out_part is traced inside this iteration of the loop body, so the late binding is intended. Added # noqa: B023 on each use in 84169a8 (formatting only; the AST is unchanged and the fwd bit-exact gate passed on every route).
| a_op = lload4(buf + QG_OFF + a_w + (mt * 16 * LQ + ks * 16) * 2) | ||
| acc_h = fx.Vector( | ||
| rocdl.mfma_f32_16x16x16bf16_1k( | ||
| TT.f32x4, [a_op, sb[ks].bitcast(I16), acc_h, 0, 0, 0] |
There was a problem hiding this comment.
out_part is traced inside this iteration of the loop body, so the late binding is intended. Added # noqa: B023 on each use in 84169a8 (formatting only; the AST is unchanged and the fwd bit-exact gate passed on every route).
| ) | ||
| acc_v = fx.Vector.filled(4, 0.0, fx.Float32) | ||
| for js in range_constexpr(MT): | ||
| a_op = lload4(buf + a_a + (mt * 16 * LT + js * 16) * 2) |
There was a problem hiding this comment.
out_part is traced inside this iteration of the loop body, so the late binding is intended. Added # noqa: B023 on each use in 84169a8 (formatting only; the AST is unchanged and the fwd bit-exact gate passed on every route).
| a_op = lload4(buf + a_a + (mt * 16 * LT + js * 16) * 2) | ||
| acc_v = fx.Vector( | ||
| rocdl.mfma_f32_16x16x16bf16_1k( | ||
| TT.f32x4, [a_op, gated[js], acc_v, 0, 0, 0] |
There was a problem hiding this comment.
out_part is traced inside this iteration of the loop body, so the late binding is intended. Added # noqa: B023 on each use in 84169a8 (formatting only; the AST is unchanged and the fwd bit-exact gate passed on every route).
| fx.ptr_store( | ||
| (acc_h[p] * scale + acc_v[p]).to(BF), | ||
| lptr( | ||
| buf + OS_OFF + ((mt * 16 + l4 * 4 + p) * LV + cl) * 2, |
There was a problem hiding this comment.
out_part is traced inside this iteration of the loop body, so the late binding is intended. Added # noqa: B023 on each use in 84169a8 (formatting only; the AST is unchanged and the fwd bit-exact gate passed on every route).
… exceeds the CUs compile_recurrence16 takes nbuf (1 / 2 LDS stages of a chunk's tiles). With one stage the next chunk's tiles are written after the chunk's barrier, so a workgroup holds half the LDS and two fit per CU. The host picks nbuf=1 when (V / bv) * N * H workgroups exceed the CU count (AITER_KDA_FWD_R16_NBUF forces 1 / 2). Outputs are bit-identical to nbuf=2. Tested on GPU (gfx950): bit-exact vs the previous commit on 8 shapes with nbuf auto / 1 / 2; graph equivalence checks pass. Full gate (op_tests, pytest, timing): untested on GPU.
compile_affine_scan(use_h0, store_fs, bv, nm) splits a state's V columns into
16-column waves and its rows into nm groups; each step stages the segment's A
and the bf16 entry state in LDS and runs the row MFMAs from there, so a scan
step costs about a third of the old one. Default AITER_KDA_FWD_SCAN=16x4
("<bv>x<nm>"); 64x1 is the previous layout and gives identical outputs.
Tested on GPU (gfx950): bit-exact vs the previous commit on 8 shapes, default
and 64x1.
Full gate (op_tests, pytest, timing): untested on GPU.
With the lower_bound gate and one dense sequence, the affine route now runs on the rsolve=3 intra's outputs: compile_recurrence16(ab=True) builds the segment maps per 16-token tile, compile_affine_scan chains them, and compile_recurrence16 replays the segments from their entry states with the fused output. AITER_KDA_FWD_AFFINE16=0 returns to the rsolve 0 affine route. Tested on GPU (gfx950): bit-exact vs the previous commit on 8 shapes; AFFINE16=0 is bit-exact vs the commit before affine16. Full gate (op_tests, pytest, timing): untested on GPU.
…airs fp32x4 -> bf16 operands of the per-tile solve go through two v_cvt_pk_bf16_f32 instead of four element conversions and repacks (_pk_bf16x4). Same rounding (RNE), bit-identical outputs. Tested on GPU (gfx950): bit-exact vs the previous commit on 8 shapes; graph equivalence checks pass. Full gate (op_tests, pytest, timing): untested on GPU.
_affine_fused passed the entry states as a 5-D view for B > 1 and 3-D for B = 1. _run_compiled reuses a launcher's first compiled callable, which fixes the rank of every tensor argument, so a B = 1 call after a B > 1 one failed in the argument fill (IndexError). Reshape to [B * n_seg * H, V, K] (same rows, [b][seg][h]) in both cases. Status: untested on GPU (the GPU host was unreachable when this was committed).
…ds early compile_recurrence16(lds_pf=True) reads a 16-token tile's LDS operands (w, beta, factors, kg^T, decay, qg, Aqk) during the previous tile's MFMA chain. AITER_KDA_FWD_R16_PF=0 restores the in-order loads. Bit-identical outputs. Status: untested on GPU as committed. An equivalent build (same rec16 code, with the next commit's intra16 change) was bit-exact on 8 shapes; graph kernel totals (us), previous commit -> this: H12 T4K 112 -> 110, T16K 318 -> 307, varlen 16x1K 220 -> 218, H96 T8192 851 -> 791, H96 varlen 8x2048 1385 -> 1383.
Each wave reads its L_II into registers before writing (I + L_II)^-1, so the inverse reuses the L_II buffer: 52 KB of LDS per workgroup instead of 56 KB. Bit-identical outputs; same speed at the current 242 VGPRs (2 waves/SIMD). Status: untested on GPU as committed. An equivalent build (plus an unused waves_per_eu knob, removed here) was bit-exact on 8 shapes.
Drop the precomputed gt/gm/qg/kg/kb register lists: each output is formed 8 columns at a time and written to LDS right away, and the tile total and split (rows 15 / 7) are re-read with DPP where used. Only q, k and the cumsum stay live, so intra16 goes from 242 to 155 VGPRs with no spills (2 -> 3 waves/SIMD with the 52KB LDS). Output is bit-identical. intra16 kernel time drops 4-8% (H96 T8192 331 -> 310us, H96 varlen 8x2048 698 -> 661us, H12 T16K 92 -> 85us).
Each wave of intra16 only touches its own LDS (its staged rows and its L_II), and a wave sees its own LDS accesses in order, so the two workgroup barriers only made the waves wait for each other. Drop them and stage qg / kg / w one after another in one buffer per wave (LDS 52KB -> 20KB). Output is bit-identical; intra16 is 2-6% faster (H96 varlen 8x2048 657 -> 628us). AITER_KDA_FWD_I16_WAVE_LOCAL=0 restores the barriers.
compile_intra16(lean=True), the new default (AITER_KDA_FWD_I16_LEAN=0 restores the previous code): - The DPP moves of the tile cumsum and the row broadcasts use bound_ctrl with a poison old operand instead of a zero old, which LLVM materialized with a v_mov before each of the 192 moves. - Rows past the end of the chunk load row 0 and skip the per-element zeroing of q / k / g / dt_bias. Their outputs are never stored, a valid row's Aqk / L entries and solve read only valid rows, and their gate is still zeroed, so the tile's total stays exact. intra16 drops from 2848 to 2554 instructions (166 -> 161 VGPRs); the outputs are bit-identical to the previous code.
The intra16 solve is a serial 16-step chain, and each step's 4-lane row sum used two ds_swizzle_b32 (LDS cross-lane moves). Use DPP quad permutes (xor 1, xor 2) instead: the same values added in the same order, without the LDS round trips. ISA: 2554 -> 2515 instructions, ds_swizzle 32 -> 0, VGPR unchanged; outputs bit-identical. AITER_KDA_FWD_I16_DPPSUM=0 restores the swizzle path.
Test-only formatting: no change to what the test runs or checks.
There was a problem hiding this comment.
🟡 Changes recommended
Unchecked tensor shapes and beta prefetch bounds permit out-of-bounds reads, while unsafe MFMA gate handling can produce incorrect results.
7 open issues
Restrict MFMA paths to safe lower-bound ranges · New Guard beta prefetches at the sequence tail · New Validate full tensor shapes in the direct entry point · New Rebuild cached schedule after sequence-boundary mutation · New Key compiled launchers by device and tensor contract · New Re-raise Triton errors when no FlyDSL candidate will run · New Use checkAllclose with per-tensor tolerances · New
What changed in this PR
Adds an opt-in FlyDSL KDA chunk-forward backend for Kimi-K3 on gfx950, while keeping Triton as the default. It complements the related backward and fused-layer work.
Changes:
- Adds forward dispatch, variable-length scheduling, saved intermediates, and affine recurrence.
- Adds tuning infrastructure and Kimi-K3 configuration tables.
- Adds correctness tests and backend benchmarks.
| File | Description |
|---|---|
op_tests/tuning_tests/test_config_shape_collision.py |
Registers configuration collision checks. |
op_tests/test_kda_chunk_fwd.py |
Tests outputs, states, intermediates, and empty sequences. |
op_tests/op_benchmarks/flydsl/bench_kda_chunk_fwd.py |
Compares backend timings. |
csrc/kda_chunk_fwd/kda_chunk_fwd_flydsl_tune.py |
Tunes forward configurations per shape. |
aiter/ops/triton/kimi_delta_attn/chunk_delta_attn.py |
Adds forward backend selection. |
aiter/ops/flydsl/kernels/kda_fwd_affine.py |
Adds affine recurrence kernels. |
aiter/ops/flydsl/kda_chunk_fwd.py |
Implements forward orchestration and scheduling. |
aiter/jit/core.py |
Registers the tuning configuration family. |
aiter/configs/model_configs/kda_chunk_fwd_flydsl_untuned_kimi_k3.csv |
Lists Kimi-K3 tuning shapes. |
aiter/configs/model_configs/kda_chunk_fwd_flydsl_untuned_kimi_k3.1.csv |
Lists Kimi-K3.1 tuning shapes. |
aiter/configs/model_configs/kda_chunk_fwd_flydsl_tuned_kimi_k3.csv |
Stores Kimi-K3 tuned settings. |
aiter/configs/model_configs/kda_chunk_fwd_flydsl_tuned_kimi_k3.1.csv |
Stores Kimi-K3.1 tuned settings. |
aiter/configs/kda_chunk_fwd_flydsl_untuned.csv |
Defines the untuned table schema. |
aiter/configs/kda_chunk_fwd_flydsl_tuned.csv |
Defines the tuned table schema. |
Review effort: Balanced
| diag = bool( | ||
| use_gate_in_kernel | ||
| and lower_bound is not None | ||
| and (diag_mfma is None or bool(diag_mfma)) |
There was a problem hiding this comment.
Confirmed: with lower_bound=-10, the FlyDSL output had relL2 0.23–0.66 against the fp32 recurrence (0.51–0.83 at -20), while Triton (safe_gate=False) stays at about 4e-3. Fixed in 7416f7e: the MFMA diagonal tiles (and the 16-row intra) are used only for lower_bound in [-5, 0); any other gate takes the fp32 path. With the fix, -10 and -20 give 3.7e-3 to 4.1e-3, the same as Triton. The default lower_bound=-5 path is unchanged: outputs are bit-identical to the previous head.
| mx = bt = None | ||
| if rsolve: | ||
| mx = torch.empty(a_shape, device=dev, dtype=bf) | ||
| bt = torch.empty(B * H, T + BT, **f32) |
There was a problem hiding this comment.
Confirmed by reading the indexing: the prepare kernel prefetches two chunks of beta without clamping, so with T = 1000 it reads up to index 1151 of a T + BT = 1064-entry row, which runs past the end of the buffer on the last (b, h) row. Fixed in 7416f7e: bt keeps its T + BT row pitch but is carved out of an allocation with 2 * BT extra floats at the end, so the prefetch stays inside the allocation. The kernel is unchanged and the prefetched tail rows are never used, so outputs are bit-identical to the previous head.
| V=v.shape[-1], | ||
| chunk_size=chunk_size, | ||
| dtype=q.dtype, | ||
| ) or not (k.dtype == v.dtype == q.dtype): |
There was a problem hiding this comment.
Fixed in 7416f7e: chunk_kda_fwd_flydsl now checks k / v / g against [B, T, H, 128], beta against [B, T, H], the sizes of A_log (H) and dt_bias (H * 128), and initial_state against [N, H, 128, 128], and raises ValueError before any launch. A test script feeding each wrong shape gets the ValueError.
| if cached is not None and cached[0] == T: | ||
| self.__dict__.update(cached[1]) | ||
| return |
There was a problem hiding this comment.
Confirmed: after changing cu_seqlens in place from [0, 64, 128] to [0, 32, 128], the next FlyDSL call reuses the varlen schedule cached on the tensor, and its output differs from a call with a new tensor (relL2 7.7e-1). We are keeping the contract of the Triton forward, whose tensor_cache also caches per tensor object: when the sequence lengths change, callers pass a new cu_seqlens tensor. The PR description now states this. Keying the cache on cu_seqlens._version would catch in-place edits at little cost, but it changes _resolve_prologue, which the GDN K5 path shares, so it is left for a separate PR.
| _run_compiled( | ||
| kernel, |
There was a problem hiding this comment.
Confirmed on the previous head: in one process, a varlen rec="fused" call with a 4-D initial_state, followed by a dense rec="affine" call, failed in the affine16 replay with IndexError: tuple index out of range (FlyDSL's argument fill in _run_compiled). The replay reused the launch handle compiled for 4-D states, but it passes 3-D states. Fixed in 7416f7e: every KDA launch now keys its compiled handle by device index, and the launchers that take states of both ranks also key by the state's rank. The K5 call (_get_or_compile_opt) is GDN's AOT-bound launcher and is keyed the same way as on main. After the fix, the sequence fused → affine → fused runs, the last output is bit-identical to the first, and both match Triton (relL2 4.6e-3). Outputs on the default shapes are bit-identical to the previous head.
| if name != "triton": | ||
| raise |
There was a problem hiding this comment.
Fixed in 7416f7e: an exception from the Triton backend is now only skipped when a FlyDSL candidate is also being tested; otherwise it is re-raised.
| rel = ((a - r).abs().max() / r.abs().max().clamp_min(1e-6)).item() | ||
| assert rel < 2e-2, f"{n}: max rel err {rel:.3g}" |
There was a problem hiding this comment.
Fixed in 7416f7e: the intermediate and gradient comparisons now use checkAllclose (rtol = atol = 2e-2, error ratio at most 1e-3; Aqk / Akk compared on the lower triangle), and the error ratios are recorded in the summary table.
Formatting only (identical AST): black on kda_chunk_fwd.py, kernels/kda_chunk_fwd.py and kernels/kda_fwd_affine.py. The B023 closure is traced within its loop iteration and the nested if is kept as written, so both get noqa.
WAITING ON AUTHORPR Self-ReviewRevision Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision. Questions to answer in the PR description
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
- Key compiled FlyDSL handles by device index, and by the state's rank where a launcher is shared by 3-D (affine) and 4-D states. - Check k / v / g / beta / A_log / dt_bias / initial_state shapes in chunk_kda_fwd_flydsl before any launch. - Use the MFMA diagonal tiles only for lower_bound in [-5, 0); other gates keep the fp32 path. - Give the rsolve beta buffer two spare rows for the unclamped two-chunk prefetch. - Test: skip a Triton failure only when a FlyDSL candidate is tested; compare intermediates and gradients with checkAllclose.


This adds a FlyDSL backend for the
chunk_kimi_delta_attnforward at Kimi-K3 shapes (H=96×128, bf16, chunk 64, gfx950). Triton stays the default and the reference.Changes
aiter/ops/flydsl/kernels/kda_chunk_fwd.pyandkernels/kda_fwd_affine.pyadd the FlyDSL forward kernels. The contractions run on MFMA (bf16 operands, fp32 accumulation).intra16works on 16-token tiles. It computes:-exp(A_log)·softplus(g+dt_bias), orlower_bound·sigmoid(exp(A_log)·(g+dt_bias))whenlower_boundis set;AqkandAkk, and the inverse of each 16x16 diagonal block of(I+L);w/u/qg/kg.h/v_new/final-state recurrence takes one of three routes, chosen per call:rec16keeps the state in registers, advances it every 16 tokens and computes the output in the same kernel;affine16(dense calls with few states) builds per-segment state maps in parallel and scans them;chunk_gated_delta_h, per-channel gk), the same call [Triton/Gluon] [HIP] [FlyDSL] [gfx950] Kimi-K3 KDA chunk backward (96 heads) #8740 makes, followed by a separateoutputkernel (o = scale·qg·h + Aqk·v_new).aiter/ops/flydsl/kda_chunk_fwd.pyhas the entry points:chunk_kda_fwd_flydsl(q,k,v,g,beta,scale,chunk_size,*,use_qk_l2norm_in_kernel,use_gate_in_kernel,A_log,dt_bias,use_beta_sigmoid_in_kernel,lower_bound,initial_state,output_final_state,state_v_first,cu_seqlens,config,return_intermediates,max_seqlen) -> (o, final_state). The flag names are the ones in [FlyDSL] [gfx950] Kimi-K3 KDA fused layer backward #8739'sregister_chunk_bwdcontract.return_intermediates=Truealso returns the 10-tuple that the FlyDSL backward takes insave_fwdmode.chunk_kda_fwd_prepare_flydsl(...)returns(q, k, beta, g_cumsum, w, u, qg, kg, Aqk, Akk), the same tuple as thechunk_delta_attn_fwd_preparethat [Triton/Gluon] [HIP] [FlyDSL] [gfx950] Kimi-K3 KDA chunk backward (96 heads) #8740 recomputes with, and accepts its keywords. Aqk and Akk are fp32; Triton's are bf16. It is registered as an opt-in forward-prepare backend of the FlyDSL backward.[B,T,H,D].cu_seqlens, B=1) is supported. Varlen calls are CUDA / HIP graph capturable: under capture the chunk schedule is built on the device, so a captured graph replays correctly for anycu_seqlenscontents with the same N and total T.AITER_CONFIG_KDA_CHUNK_FWD_FLYDSL, gfx950, Kimi-K3 / K3.1 shapes), with a default config for other shapes. A tuner is included.chunk_kimi_delta_attn(..., fwd_backend="flydsl"). Calls outside the supported set raiseValueErrorinstead of silently falling back to Triton.op_tests/test_kda_chunk_fwd.pychecksoand the final state against an fp32 token-by-token recurrence, and reports the FlyDSL vs Triton difference. It covers dense and varlen (including empty sequences and partial chunks at sequence boundaries), the Lumen#35 shapes up to 1×32768, H=96/48/32/16/12, token- and channel-major layouts, and three modes:kimi(fused gate with lower_bound=-5, L2 norm and beta sigmoid in kernel),kimi_state(adds a V-first h0 and the final state) andplain. It also checks the intermediates against Triton's.Limits
intrastages about 128 KB of LDS; gfx950 has 160 KB), bf16 q/k/v, K=V=128, chunk 64, H==HV, B=1 with varlen, nooutorstate_cache. The final state is fp32.safe_gateis accepted and has no effect. The decay is computed exactly, or split per 16-token block, in fp32, so there is no sub-chunk reference point.chunk_kda_fwd_flydsldirectly.Validation
On gfx950 (MI355X), bf16, K=V=128. The gates and the unverified scope are listed in the Self-Review below.
op_tests/test_kda_chunk_fwd.pyexits 0 on the default route and with each recurrence route forced.test_chunk_delta_attn_fwd.py: 29 passed.test_chunk_delta_attn_bwd.py -k flydsl: 39 passed.ovs Triton is 3.3e-3 to 3.7e-3 (FlashKDA vs Triton: 5.4e-3 to 5.6e-3).b221d11f(later commits are formatting only). Graph end to end, the three backends measured in the same session, median of 6, in us:GPU commands (single MI350X/MI355X):
PR Self-Review
Reviewed revision
7416f7ebaa990824434ced850a0728caaec63bddBehavior and intent
chunk_kimi_delta_attnat Kimi-K3 shapes. It is opt-in withfwd_backend="flydsl"; Triton stays the default and the reference.intra16(gate cumsum, in-kernel q/k L2 norm and beta sigmoid, Aqk / Akk, the (I+L)^-1 solve, w/u/qg/kg on 16-token tiles).rec16with the output fused in, chunk-parallelaffine16for few states, or the GDN K5 kernel.cu_seqlens, B = 1). Varlen calls are CUDA / HIP graph capturable.chunk_kda_fwd_prepare_flydslreturns the same 10-tuple as Triton'schunk_delta_attn_fwd_prepare. It is registered as an opt-in forward-prepare backend of the FlyDSL backward in [Triton/Gluon] [HIP] [FlyDSL] [gfx950] Kimi-K3 KDA chunk backward (96 heads) #8740.cursor/kimi-k3-kda-chunk-bwd-7e9c).Validation and unverified scope
Validated on gfx950 (MI355X), bf16, K = V = 128. The numbers are from
b221d11f.ee0e03faand84169a83are formatting only:ee0e03fareorders two imports and reformats one assert inop_tests/test_kda_chunk_fwd.py, and84169a83runs black and addsnoqa(B023, SIM102) in the three FlyDSL forward files, with an unchanged AST.84169a83was rerun on GPU againstb221d11f:o, the final state and the intermediates tuple aretorch.equalon every route (default, affine, K5, register, fused; 12 cases each), 102 graph replay cases are bit-identical to eager, and the op test exits 0.7416f7ebaddresses the Copilot review (bullet below).op_tests/test_kda_chunk_fwd.py: exit 0 on the default route, including 40 empty-sequence rows. Forcing each recurrence route (affine, K5, register, fused) also exits 0.test_chunk_delta_attn_fwd.py: 29 passed.test_chunk_delta_attn_bwd.py -k flydsl: 39 passed, including the FlyDSL backward fed with FlyDSL forward intermediates.ovs Triton is 3.3e-3 to 3.7e-3 on H8 / H96 / H12, dense and varlen (FlashKDA vs Triton: 5.4e-3 to 5.6e-3). maxabs ≤ 7.3e-4.7416f7eb(Copilot review): launch handles keyed by device, and by the state's rank where affine (3-D) and other routes (4-D) share a launcher; shape checks on every operand ofchunk_kda_fwd_flydsl; the MFMA diagonal tiles only forlower_boundin [-5, 0); two spare rows in the rsolve beta buffer for the unclamped prefetch; and test fixes (checkAllclosefor intermediates and gradients). Against84169a83:o, the final state and the intermediates tuple aretorch.equalon every route (12 cases each), 102 graph replay cases are bit-identical to eager, and the op test passes on all 7 default shapes × 3 modes (after the beta-buffer change, rerun on 1x1000, 3x1000v and 8x2048v). A varlen fused call followed by an affine call, which failed withIndexErroron84169a83, now runs and matches Triton.lower_bound= -10 / -20 now gives relL2 3.7e-3 to 4.1e-3 against the fp32 recurrence (Triton about 4e-3;84169a83: 0.23–0.83). Eager time against84169a83(medians of 6 interleaved rounds): T1000 H12 69.4 vs 68.4 us (the new shape checks, about 1 us on the host), other shapes within ±0.7%.cu_seqlensin place between calls: the varlen schedule cached on the tensor is reused, as with the Triton forward's cache, so callers must pass a new tensor when the lengths change.7b40ccb7, which mergesmain). Combined with it,fwd_backend="flydsl"would not yet reject [Triton/Gluon] [gfx950/1250] FlashKDA updates #8043'sout_gate/norm_weight/ checkpoint arguments; that needs a follow-up once the base is merged in.PR-specific question
Which arch / dtype / shape selects the new kernels, and what keeps unsupported inputs out?
fwd_backend="flydsl".chunk_kimi_delta_attnrejectsoutandstate_cachewithValueError.chunk_kda_fwd_flydslraisesValueErrorunlesskda_fwd_flydsl_supportedholds:get_gfx_runtime() == "gfx950",K == V == 128,chunk_sizeNone or 64,H == HV(no GVA), bf16 q/k/v of one dtype.B != 1, a missingA_logwithuse_gate_in_kernel=True, and any operand whose shape does not match q's[B, T, H]and K = V = 128 (includinginitial_state[N, H, 128, 128]) also raise.intrastages about 128 KB of LDS (gfx950 has 160 KB), and K5 bakes in BT = 64 and K = 128.chunk_kda_fwd_prepare_flydslonly when it is selected (prepare="flydsl"orAITER_KDA_BWD_PREPARE=flydsl).Changed op tests
op_tests/test_kda_chunk_fwd.py: the op test.test_kda_chunk_fwd:oand the final state vs an fp32 token-by-token recurrence, and FlyDSL vs Triton, over H, T, dense / varlen, plain / kimi / kimi_state modes and token- / channel-major layouts.test_kda_chunk_fwd_intermediates: the prepare tuple vs Triton's intermediates, and the FlyDSL backward fed with them vs its own recompute.test_kda_chunk_fwd_empty_seq: varlen with empty sequences, per route, with and without an initial state.op_tests/op_benchmarks/flydsl/bench_kda_chunk_fwd.py: a benchmark with no assertions. It times FlyDSL against Triton per shape, reports their max |diff|, and can print per-stage FlyDSL times (intra / k5 / output).op_tests/tuning_tests/test_config_shape_collision.py: one entry,AITER_CONFIG_KDA_CHUNK_FWD_FLYDSL/kda_chunk_fwd_flydsl_tuned. The new tuned CSV gets the same duplicate-shape check as the other config families.