Repository navigation
Conversation
- Add create_kda_decode_kernel to kernels/gdr_decode.py: KDA is the gated delta rule with a per-channel decay - Fixed to the Kimi-K3 TP8 layout on gfx950: 12 local heads, 128-dim state, 256-thread blocks - One launch fuses the width-4 Q/K/V causal conv, L2 norm, FP32 recurrent-state update and gated RMSNorm output - fuse_f_b selects a variant that computes the head-local f_b projection in FP32 and keeps the BF16 gate in LDS - The two variants share one kernel body; they differ in gate source, LDS layout and waves-per-EU (3 vs 2) - state_dtype "f32" or "bf16": BF16 state is widened on load, updated in FP32 and rounded back on store - State moves in 16-byte transactions (f32x4 or bf16x8); the FP32 kernels keep names without a dtype suffix - Negative or out-of-range state indices zero the output and leave both caches untouched; slot 0 is live - Cache slots are rebased with 64-bit byte offsets, so state and conv caches larger than 4 GiB work - Specializations are cached per (norm_eps, lower_bound, fuse_f_b, state_dtype) and reuse the module's _LOG2E
…ps.flydsl - Add flydsl_kda_decode and flydsl_kda_decode_with_f_b to linear_attention_kernels.py, next to flydsl_gdr_decode - Add is_flydsl_kda_decode_supported(device): true for a visible device index when get_gfx_runtime() reports gfx950 - conv_state may be channel-major [cache, 4608, 3] or SGLang's width-major [cache, 3, 4608] seen via transpose(-1, -2) - Validate shapes, dtypes, devices, dense non-overlapping cache slots, out row layout and int32 buffer addressing - Cache slot strides are passed as int64; slots beyond min(state, conv_state) capacity are treated as padding - Accept an FP32 or BF16 state and advertise it as state_dtypes; set zeroes_invalid_output = True on both APIs - Accept a preallocated out buffer, as SGLang's KDA backend passes out= - AITER_KDA_DECODE_SLOT_CHECK=1 rejects duplicate live state_indices; read once at import, skipped in graph capture - Document that live slots must be unique and that the fused f_b projection pays off only at decode batch sizes - Export the three APIs lazily from aiter.ops.flydsl
…n baseline - Extend op_tests/test_flydsl_linear_attention.py next to the GDR tests; KDA tests skip unless the device is gfx950 - Check both APIs against an FP32 torch reference for both conv layouts at batch 1/8/16/64/128, FP32 and BF16 state - Check BF16 state at batch 1/2/8/64/128 with dense or padded slots and over recurrent sequences; reject fp16/fp64 - Cover negative, out-of-range and slot-0 indices, the opt-in duplicate-slot check and >4 GiB cache slot offsets - Cover input validation, unsafe and padded out layouts, int32 address overflow bounds and the public exports - test_flydsl_kda_decode times flydsl, flydsl_f_b and Triton fused_kda_decode (width-major only) into a preallocated out - Batches above 16 allow a 1e-3 mismatch ratio for one-ULP BF16 state rounding ties; conv state must match exactly - main() adds --conv-layout and --state-dtype axes and a KDA summary table, run only when get_gfx() is gfx950
… broadcasts - Check AITER_KDA_DECODE_SLOT_CHECK's capture state on the input's device, not the current one. - Document that the debug slot check also flags SGLang's eager DP padding rows sharing scratch slot 0. - Reject a conv_weight with no unit-stride axis before compiling; FlyDSL's tensor argument needs one. - Size the KDA specialization cache like the GDR caches (1024), so captured graphs never outlive their module. - Drop three shuffle_idx broadcasts: the xor butterfly already leaves the K-group sum in all eight lanes. - MI355X graph replay, batch 1/32/128 with FP32 and BF16 state: within +-2% of the previous kernel. - Add a test for the conv_weight stride check; 197 tests pass with FLYDSL_RUNTIME_ENABLE_CACHE=0.
…ion sweep - aiter_test.sh ran op_tests/test_flydsl_linear_attention.py only as a script, which runs the benchmark sweep. - Run pytest and the sweep for that file and fail the step if either fails.
…it for bit - Capture both APIs (plain and fused f_b) with FP32 and BF16 state, rewrite inputs in place, replay three steps. - Output, recurrent state and conv state must equal an eager run exactly; a stale captured f_a fails the fused cases.
# Conflicts: # .github/scripts/aiter_test.sh
… cover odd batches - An independent grid failed batch 3: a BF16 rounding tie moved 23 of 983040 FP32 state elements by <= 4.9e-6. - Ties occur at any batch (worst 6.9e-5 over batch 1-256 on MI355X), so use _TOL_ERR_RATIO for every batch. - Parametrize batch 3 and 33; the pytest check skips the Triton baseline, which stays in the benchmark sweep.
- is_flydsl_kda_decode_supported(device) range-checked device but returned the cached first-GPU arch. - Read gcnArchName of the device asked about, and require FlyDSL's build target (GDR_GPU_ARCH) to be gfx950 too. - Memoize the answer per device index, so eager calls skip the get_device_properties query. - Test a mocked gfx942 device, a non-gfx950 build target, the per-device memo and an out-of-range index.
…s-outer - The out check required stride(1) >= 11 * stride(2) + 128, so it rejected valid heads-outer [H, B, D] storage. - Add _check_disjoint_rows: by increasing stride, each row dim must step past what the narrower dims span. - Batch-outer layouts, padded rows and batch 1 keep their previous answer. - Test padded heads-outer outputs against the reference, plus two overlapping heads-outer rejects.
…padding - SGLang's eager DP-attention padding rows all map to its reserved mamba slot 0, so the opt-in check always fired there. - AITER_KDA_DECODE_SLOT_CHECK_PADDING_SLOT=<slot> lets that slot repeat like a negative index; unset keeps it live. - Mask the slot at the decode call site, so _check_unique_live_slots and its signature stay unchanged. - The kernel still decodes the slot; only the debug check changes. A non-integer value fails at import. - Test the default, the opt-in, a repeated live slot alongside it, and the env parsing.
- conv_weight, A_log and dt_bias must be FP32, norm_weight and activations BF16; the validation already enforces it. - Note that the Triton fused_kda_decode also takes BF16 conv_weight and FP32 norm_weight, so callers cast once at load.
- _kda_reference skipped only negative slots; the kernel also pads slots >= min(state, conv_state) slot counts. - Skip those too, so the reference states the documented contract instead of indexing past the cache. - The out-of-range test now mixes in a live row and checks output and both caches against the reference.
- Seven KDA tests bound the generated KdaInputs to `seed`, next to helpers whose `seed` is the RNG integer. - Rename them to `base_inputs`; no behaviour change.
- flydsl_kda_verify_with_f_b runs f_b, Q/K/V conv, decay gate, delta rule and gated RMSNorm for T tokens in one launch - Verify semantics: conv_state and state stay read-only; writes conv windows and state snapshots or ReplaySSM rings - FP32 or BF16 recurrent state, 1 to 8 tokens; 8 waves up to batch 16 and 4 waves above, measured on MI355X - Token 0 matches flydsl_kda_decode_with_f_b bit for bit; op test covers snapshot/ring, padding rows and SGLang layouts
…ted 16-wave build - Reject overlapping intermediate_conv_window, intermediate_states and replay_ring layouts with dense-slot checks - Keep the channel-major and SGLang transposed conv windows and pool slices whose slot stride exceeds one slot - Require a unit-stride conv_weight axis, as the decode wrapper does - Slot check: query capture on the launch device and also reject repeated live intermediate_indices - Treat a sequence as live only when both indices are in range, as the kernel does - KDA_VERIFY_NUM_WARPS is (4, 8); tag flydsl_kda_verify_with_f_b.num_warps so callers can pre-build before capture - Size the specialization cache to 1024 so graph-captured kernels are not evicted - Fix stale wave-count comments and record the measured 4- vs 8-wave crossover - Drop the unused _KDA_PROJECTION_ITERS import and apply black
- Parametrize the reference matrix over flydsl_kda_verify_with_f_b.num_warps so both wave counts are checked - Add CUDA-graph replay (bit-exact vs eager) and 4 GiB slot offsets via strided views of one shared buffer - Add rejection tests for unsafe write layouts, int32 addressing overflow, conv_weight stride and num_warps=16 - Cover AITER_KDA_DECODE_SLOT_CHECK for duplicate live cache and intermediate indices, and padded pool slices - Make the script sweep assert on numeric mismatches instead of only logging them - Rename the state dtype flag to the standard -d/--dtype and use a dict literal for C408
- Dispatch op_tests/test_flydsl_kda_verify.py like test_flydsl_linear_attention.py: pytest, then the script sweep
…decode padding slot - Reuse _check_disjoint_rows for the verify out check, so heads-outer layouts pass as they do for decode - Mask the reserved padding slot (AITER_KDA_DECODE_SLOT_CHECK_PADDING_SLOT) in the verify slot check, as decode does
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
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 |
There was a problem hiding this comment.
🟡 Changes recommended
Unchecked overlap between scratch buffers and committed caches can cause verification to overwrite read-only caches and prematurely commit speculative state.
2 open issues
What changed in this PR
Builds on #6026’s fused KDA decode to add an opt-in gfx950 kernel that verifies multiple draft tokens in one launch while keeping committed caches read-only.
Changes:
- Fuses projection, convolution, recurrence, and gated normalization for 1–8 tokens, with snapshot or replay-ring output.
- Adds a validated public wrapper, lazy export, and configurable wave counts.
- Adds correctness, graph-replay, layout-safety, and performance checks, integrated into CI.
| File | Description |
|---|---|
op_tests/test_flydsl_linear_attention.py |
Decode regression tests and benchmarks inherited from #6026. |
op_tests/test_flydsl_kda_verify.py |
New verify correctness tests and benchmark sweep. |
aiter/ops/flydsl/linear_attention_kernels.py |
Verify wrapper, input validation, and specialization selection. |
aiter/ops/flydsl/kernels/kda_verify.py |
Fused multi-token verify kernel with snapshot and ring modes. |
aiter/ops/flydsl/kernels/gdr_decode.py |
Decode implementation and shared KDA helpers inherited from #6026. |
aiter/ops/flydsl/__init__.py |
Lazy exports for the KDA APIs. |
.github/scripts/aiter_test.sh |
Runs KDA pytest cases and benchmark sweeps in CI. |
Review effort: Balanced
…lidation - Slot check: rows on AITER_KDA_DECODE_SLOT_CHECK_PADDING_SLOT are padding for both the cache and intermediate checks - Snapshot verify only reads conv_state/state, so live sequences may share a cache slot; ring mode still rejects it - Reject a non-int num_warps (8.0, numpy ints) before the KDA_VERIFY_NUM_WARPS membership check - Take the base slot count from _num_cache_slots and fold the ring minimum into it, keeping one int32 clamp - Test reference decides padding like the kernel: min slot count over state, conv_state and every ring tensor - Add tests for padding-slot masking, a shared snapshot cache slot, a repeated ring slot and num_warps=8.0
- Brings in the FP32-reference Triton check and the decode out-alias check from sweep/pr-6026 - Conflict in _check_no_alias and its helpers: the decode branch now defines them, so its text is kept - The docstring keeps the verify early-commit rationale
There was a problem hiding this comment.
🔵 Needs a closer look
Missing head-matched GPU validation for the fused speculative recurrence and ReplaySSM commit contract leaves numerical accuracy and graph-replay behavior on gfx942 and gfx950 unverified, requiring kernel-maintainer review.
No open issues 🎉
Review effort: Balanced
…s and reject aliased caches - Drop AITER_KDA_DECODE_SLOT_CHECK[_PADDING_SLOT]; add keyword-only validate_slots and padding_slot to both decode APIs - Reject a state or conv_state that shares a byte with the other cache or a read-only operand, before compilation - Pass a NaN-filled out in the padding-slot tests so a row the kernel never zeroes fails them - Add rejection tests for aliased caches (8 cases; all fail with the check removed)
…ot check to keyword arguments - Take ROCm#6026's validate_slots / padding_slot keyword arguments; flydsl_kda_verify_with_f_b gets the same two - The verify slot-check tests pass the arguments instead of patching the removed env flags - Gate the verify sweep on the per-region bounds of the pytest cases, so one corrupted token/head fails it - Pass a NaN-filled out in the verify padding-row test so an unzeroed padding row fails it - Add a test for the lazy export and the state_dtypes / max_tokens / zeroes_invalid_output tags
…on crossover reproducible in-tree - Compare dense byte runs exactly once the span check suspects an overlap, so per-head interleaved buffers pass - Add a flydsl_proj candidate (BF16 F.linear, then the decode) to the KDA sweep; the docstring cites its crossover - State that the sweep times are GPU-only and give the host validation cost per eager call - Add head-interleaved accept cases for both APIs, and capture a graph with validate_slots=True
…e in-tree sweep - Re-ran the sweep for the docstring's numbers; they moved slightly within run-to-run noise - Fused f_b is faster than F.linear plus decode by about 1-4 us up to batch 32 and slower by 6-23% from batch 64
…erlap check - The run budget multiplied unmerged dimension products, so head-interleaved buffers at batch 171 and up were rejected - Budget the merged runs of both tensors instead of their product - Build the run starts on the CPU, so a CUDA default device neither launches kernels nor breaks graph capture - Add a batch 256 head-interleaved accept case and a graph-capture case; the 4 new cases fail on the old check
- Preserve the PR behavior while integrating upstream changes. - Fix reviewed regressions and pass the repository pre-commit checks. - Verify the final candidate with Gemini 4 Argon; GPU validation remains pending.
There was a problem hiding this comment.
🔵 Needs a closer look
The new GPU recurrence and scratch/ring commit contract require human review and head-matched gfx942/gfx950 validation on FlyDSL 0.5.3, which neither the reported runs nor this GPU-unavailable environment establish.
No open issues 🎉
Review effort: Balanced
|
Closing: its only consumer, sgl-project/sglang#48701, is closed. With sgl-amd-mono serving verify steps, only 1-2 of 69 KDA layers still used this kernel. |


2eb80d629on that are not in [FlyDSL] [CI] [Kernel] Add fused KDA decode kernels on gfx942 and gfx950 #6026kda_verify.py,flydsl_kda_verify_with_f_b,test_flydsl_kda_verify.pyand theaiter_test.shcaseSummary
flydsl_kda_verify_with_f_b: Kimi-K3 KDA target verify of T draft tokens per sequence in one FlyDSL launch.f_bprojection, Q/K/V short conv, decay gate, gated delta rule, gated RMSNorm.conv_stateandstateare read-only.Motivation
f_bGEMM,causal_conv1d_update, Triton target verify,rms_norm_gated.Changes
kernels/kda_verify.py(new):create_kda_verify_kernel(...)device_indexkeys the cache,maxsize=1024, graph-safe).linear_attention_kernels.py: theflydsl_kda_verify_with_f_bwrapperValueError).output_gatestorage asout..state_dtypes,.max_tokensand.num_warps == (4, 8)let callers pre-build before graph capture.aiter/ops/flydsl/__init__.py: lazy exports.op_tests/test_flydsl_kda_verify.py(new): 211 pytest cases plus a timing sweep (-b/-t/-d/-m).out.is_flydsl_kda_decode_supported()and on the per-region bounds of the pytest cases..github/scripts/aiter_test.sh: runs pytest and then the script sweep for the two KDA test files.bowns rowsb*T .. b*T+T-1.cache_indices[b]selects the state/conv slot andintermediate_indices[b]the snapshot/window line.intermediate_statesandreplay_ring((raw_v, raw_k, g, beta),L >= T).flydsl_kda_decode_with_f_bat zero tolerance: output and snapshot state, FP32 and BF16.validate_slots=False,padding_slot=None; same arguments as [FlyDSL] [CI] [Kernel] Add fused KDA decode kernels on gfx942 and gfx950 #6026's decode)validate_slots=True: host sync, skipped during graph capture.padding_slot=<slot>: the check treats a row on that slot as paddingPerformance (if applicable)
rms_norm_gated) is not in this tree,python op_tests/test_flydsl_kda_verify.py -b 1 2 16 60 -t 5 6 89dd0b1a54(the later head edits a docstring only), single run.run_perftest, single run.Testing
Documentation
Docstrings updated
User guide updated
Performance guide updated
No documentation change is needed, with the reason stated below
New op with a full docstring; no user-guide page covers the FlyDSL linear-attention ops.
Dependencies
Breaking Changes
None. New API; #6026's decode is unchanged.
PR Self-Review
Reviewed revision
888b8f974a025110f6505f7d08cbf82648070c7d888b8f974merges [FlyDSL] [CI] [Kernel] Add fused KDA decode kernels on gfx942 and gfx950 #6026 headf786d8d37(exact overlap check fix: merged-run budget, CPU-only)3392c8a5fmerges [FlyDSL] [CI] [Kernel] Add fused KDA decode kernels on gfx942 and gfx950 #6026 head258cb0915(docstring-only change)9dd0b1a54merges [FlyDSL] [CI] [Kernel] Add fused KDA decode kernels on gfx942 and gfx950 #6026 heade460a0f55b75e612e3merges [FlyDSL] [CI] [Kernel] Add fused KDA decode kernels on gfx942 and gfx950 #6026 heade76275d0dand moves the verify slot check to keyword argumentsAITER_KDA_DECODE_SLOT_CHECK[_PADDING_SLOT]are gone (HK9);flydsl_kda_verify_with_f_btakesvalidate_slots/padding_slotlike the decode ops.out; a new test covers the lazy export and the op's tags.ee2c3d460too: decodeoutoverlap check and the FP32-Q/K/V Triton reference._check_no_aliashelpers now live in [FlyDSL] [CI] [Kernel] Add fused KDA decode kernels on gfx942 and gfx950 #6026; the merge keeps that text and this branch's early-commit note._slot_blockssplits on the largest-stride axis; verify's rejections are unchanged._kda_referencerounds them to BF16, as the model and FlyDSL do._kda_reference(round_qkv=False)with the same 0.03 bound as FlyDSL.21606a719and its parents (review follow-up)5bed9325d): per-region decode bounds, NaN-filled output,outdocstring.f_a,x,raw_beta,output_gateor an index tensor.f60fb7e11merges [FlyDSL] [CI] [Kernel] Add fused KDA decode kernels on gfx942 and gfx950 #6026 head118109b3ainto this branch (its import-time env parsing is gone since the head above)b93176f40);AITER_KDA_DECODE_SLOT_CHECK_PADDING_SLOTonly when the slot check is on.github/scripts/aiter_test.sh, keeps both PRs' cases.847d2619eandb93176f40follow the Copilot reviewdevice_index, so each GPU gets its own launchertest_kda_verify_runs_on_a_second_gpufails before the fix and passes after it_assert_closeusescheckAllcloseand allows at most 1% mismatches per token/head and snapshot headget_gfx_runtime().f756f7d70merges main5c1489c24; the only conflict,.github/scripts/aiter_test.sh, keeps both sides.Behavior and intent
aiter(--linear-attn-verify-backend, [Perf] [AMD] kimi-k3: Run KDA target verify through AITER's fused FlyDSL kernel sgl-project/sglang#48701).Validation and unverified scope
888b8f974(MI355X gfx950, ROCm 10.0.0, torch 2.11.0+rocm10.0.0, FlyDSL 0.5.0, one GPU)pytest -q op_tests/test_flydsl_kda_verify.py op_tests/test_flydsl_linear_attention.py: 463 passed, 4 skipped3392c8a5f(docstring-only over9dd0b1a54); tests re-run on9dd0b1a54codepytest -q op_tests/test_flydsl_kda_verify.py op_tests/test_flydsl_linear_attention.py:b75e612e3(same machine)pytest -q op_tests/test_flydsl_kda_verify.py op_tests/test_flydsl_linear_attention.py:python op_tests/test_flydsl_kda_verify.py -b 1 2 16 60 -t 5 6 8:55b04411c(same machine): 446 passed, 4 skipped; sweep-b 1 16 -t 5exit 0, all errors 021606a719(same machine)pytest -q op_tests/test_flydsl_kda_verify.py op_tests/test_flydsl_linear_attention.py:_check_no_aliasin-process)python op_tests/test_flydsl_kda_verify.py -b 1 16 -t 5: exit 0, 4 rows ongfx950, all errors 0f60fb7e11(MI355X gfx950, ROCm 10.0.0, torch 2.11.0+rocm10.0.0, GPU 0)pytest -q op_tests/test_flydsl_kda_verify.py op_tests/test_flydsl_linear_attention.py:f60fb7e11: the same command, 429 passed, 4 skipped (need 2 GPUs)validate-kernel-prwas not run at this head847d2619e, 2 GPUs:pytest op_tests/test_flydsl_kda_verify.py op_tests/test_flydsl_linear_attention.py:f756f7d70: the same command, 428 passedpytest -q op_tests/test_flydsl_kda_verify.py189 passed;pytest -q op_tests/test_flydsl_linear_attention.py -k kda184 passed0057b5211pytest -q op_tests/test_flydsl_kda_verify.py: 205 passedtest_flydsl_linear_attention.py: 407 passed, 21 skipped (existing gfx950-only GDN varlen)validate-kernel-pr(pre-push local head) PASS on both filesc4f41fbcewith SGLang #48701 head3a9117f078: 98.0% in both modes vs 98.0-98.5%;888b8f974(the last MI300X run is at0057b5211), and the 2-GPU cases at this headPR-specific question
aiter_test.shonly adds acasearm that runspytestand then the script for twoop_tests/files.$1tobash -c.Changed op tests
op_tests/test_flydsl_kda_verify.py(new): the only coverage of the verify opoutin the padding test.op_tests/test_flydsl_linear_attention.py: the KDA decode tests and sweep from [FlyDSL] [CI] [Kernel] Add fused KDA decode kernels on gfx942 and gfx950 #6026🤖 Generated with Claude Code