You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FlyDSL] [CI] [Kernel] Add fused KDA decode kernels on gfx942 and gfx950 - #6026
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 6026 --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.
github-actionsBot
changed the title
feat(flydsl): add fused KDA decode kernels on gfx950
[FlyDSL] feat(flydsl): add fused KDA decode kernels on gfx950
Oct 1, 2026
…decode
- Match ROCm/aiter#6026, which upstreams the kernels as aiter.ops.flydsl.kda_decode
- Load the AITER source from aiter.ops.flydsl.kda_decode and its flydsl_kda_decode* entry points
- Rename the vendored module to kda_flydsl/kda_decode.py so both sources expose one API
- Rename the kernel builders to kda_decode_gfx950.py and kda_decode_fused_projection_gfx950.py
- Rename the public functions, builders, compiled kernel names and registry op ids to the AITER spelling
- Rename the FlyDSL KDA decode test, its test cases and benchmark to the operation-based names
- Keep the vendored batch-2 fused-projection tuning as optional builder keywords
This projection variant has the same unbounded specialization cache keyed by caller-provided floats. Distinct norm_eps/lower_bound pairs permanently retain JIT launchers and compiled modules, allowing memory to grow with workload diversity. Please make the scalars runtime arguments or cap this cache with a workload-appropriate LRU size.
Unbounded specialization cache leaks memory for varying float parameters
This unbounded cache is keyed by the public norm_eps and lower_bound floats, so every distinct pair retains another JIT launcher/compiled module for the process lifetime. A caller serving models with varying scalar values can therefore grow host/code-object memory without limit. Please either pass these scalars as runtime kernel arguments or use a deliberately bounded LRU cache.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The accuracy-sensitive fused recurrent kernels require GPU-owner review of head-matched gfx942/gfx950 numerical and performance evidence that cannot be independently verified in this source-only snapshot.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The KDA wrappers reuse device-bound cached launchers across GPUs, allowing second-device calls to return unwritten output without updating caches because launch failures are printed rather than raised.
- Key create_kda_decode_kernel by device_index; a compiled handle reused on another GPU fails with hipErrorInvalidDevice
- Pass the input device from flydsl_kda_decode and flydsl_kda_decode_with_f_b
- Add test_flydsl_kda_decode_runs_on_a_second_gpu: cuda:1 must match cuda:0 bit for bit after cuda:0 warms the cache
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The fused recurrent GPU kernels need owner review and current-head correctness/performance validation on gfx942/gfx950 with FlyDSL 0.5.0, as supplied results cover older revisions and GPU checks are unavailable here.
- A malformed AITER_KDA_DECODE_SLOT_CHECK_PADDING_SLOT raised ValueError at import even with the check off.
- That broke importing linear_attention_kernels, which also hosts flydsl_gdr_decode and flydsl_gdr_mtp.
- Valid values and the enabled check behave as before; add a subprocess import regression test.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The fused recurrent kernels lack exact-head correctness and performance validation on gfx942/gfx950 with pinned FlyDSL 0.5.0, requiring model-owner confirmation of numerical and graph-replay behavior.
… output
- _assert_kda_close also bounds the worst region (token/head row, or slot/head 128x128 state block) mismatch fraction
- Measured worst region over the pytest cases on MI355X is 7.3e-3 (a state slot/head at batch 129); the bound is 0.03
- A lost token/head is 0.065% of a batch-128 pool, so it passed the pool-wide 1e-3 ratio before
- Zeroing one token/head of the output or one slot/head of the state at batch 128 fails it (checked on a /tmp copy)
- The correctness call now gets a NaN-filled output, so a row the kernel never writes fails
- The KDA table records get_gfx_runtime() and the sweep gates on is_flydsl_kda_decode_supported() alone
- flydsl_kda_decode: out must not share memory with any input or cache, and the kernel does not check this
- State the row-stride rule the layout checker applies: each row dimension must step past what the other spans
… sweep
- The Triton candidate keeps Q/K/V in FP32 and its worst token/head region mismatches 9.4% at batch 128 on MI355X
- The FlyDSL bound of 0.03 tripped on it in the script sweep (the pytest cases do not run Triton)
- The baseline gets the 0.25 cap instead; a lost token/head or slot/head is still 1.0
…not a looser bound
- Revert the 0.25 region bound the Triton baseline got in 5bed932; it and FlyDSL share the 0.03 bound again
- Root cause of the 9.4% region: not a bug; Triton keeps the convolved Q/K/V in FP32, the reference rounds them to BF16
- Vs the BF16-rounding reference Triton has 6-15% of a token/head one BF16 ULP off at every batch from 16 (9.4% at 128)
- Vs a reference without that rounding (round_qkv=False) Triton's worst region is 7.8e-3 and its state matches exactly
- FlyDSL is the mirror image: exact vs the BF16-rounding reference, 7-15% off vs the FP32 one (MI355X, batch 1-256)
- _kda_reference takes round_qkv; the sweep checks Triton against round_qkv=False and FlyDSL against the default
- A caller-supplied out sharing bytes with x, a weight, either cache, raw_g (or f_a, f_b_weight) now raises ValueError
- Host arithmetic on shapes, strides and base pointers: no sync, about 14 us per eager call, none under graph replay
- _slot_blocks splits on the largest-stride axis, so out with a leading singleton dim can interleave with an input
- Overall-span test rejects most operands first; count 0 and merged touching blocks are handled in the helpers
- raw_g is validated before the shared validator so a malformed one cannot break the check
- The docstrings state the rule; 11 tests fail without the check and 3 accept interleaved layouts (NaN-filled out)
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The alias check treats padding between heads as occupied memory, incorrectly rejecting valid disjoint input/output views in an interleaved BF16 layout.
…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)
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Owner and hardware review is needed because the fused recurrent kernels change BF16 Q/K/V rounding, while model-level decode accuracy and current-head gfx942/two-GPU behavior remain unverified.
…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
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The fallback tensor factories can allocate on CUDA under the default-device setting, causing host synchronization and CUDA graph capture failure for a legal interleaved layout; explicit CPU allocation and graph-replay coverage are needed.
…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
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Alias validation inherits the CUDA default device, causing host synchronization and breaking CUDA graph capture for legal interleaved layouts; both address-tensor factories need explicit CPU allocation.
…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.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The flydsl_proj benchmark omits projection work from its TFLOPS and bandwidth accounting despite timing both projection and decode, making those reported metrics inaccurate.
Closing: the Kimi-K3/K3.1 DSpark servers verify and never run target KDA decode, so these decode kernels are not reached.
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
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.
Summary
aiter.ops.flydsl:flydsl_kda_decode,flydsl_kda_decode_with_f_b,is_flydsl_kda_decode_supported._with_f_balso computes the head-localf_bprojection.flydsl_kda_decode_with_f_b.Motivation
fused_kda_decodeplus a separate BF16 linear for thef_bprojection.raw_gto HBM for the decode kernel to read back._with_f_bdrops that launch and theraw_ground trip.Changes
kernels/gdr_decode.py:create_kda_decode_kernelfuse_f_balso computesf_bin FP32 and keeps it in LDS.device_indexand cached like the GDR caches (maxsize=1024).linear_attention_kernels.py: wrappers with input validationconv_weightwith no unit-stride axis before compiling.__init__.py: lazy exports of the three APIs.op_tests/test_flydsl_linear_attention.py: 217 KDA cases.github/scripts/aiter_test.sh: runs this file via pytest and then the script sweep; fails if either fails.state_indices: zero output, caches untouched.fused_kda_decode.conv_state: channel-major, or SGLang's width-major view.outthat overlaps an input or cache raisesValueError(host arithmetic, no sync).stateorconv_statethat shares a byte with the other cache or a read-only input raisesValueErrortoo.is_flydsl_kda_decode_supported()and recordsget_gfx_runtime().validate_slots=Falseandpadding_slot=Noneon both decode APIsvalidate_slots=TrueraisesValueErroron duplicate live slots (host sync; skipped during graph capture).padding_slot=0lets that slot repeat.Performance (if applicable)
fused_kda_decodepath is the baseline.FlyDSL KDA decode summarytable:e460a0f55(the later head only edits a docstring); single run, us.run_perftest: GPU time, not CUDA-graph replay.tritonandflydslare the decode alone; the Triton side has no projection in this table.flydsl_projis a BF16F.linearintoraw_gfollowed byflydsl_kda_decode(two launches).flydsl_f_bisflydsl_kda_decode_with_f_b, which fuses the projection.f_bfusedf562a48f8Testing
Documentation
Dependencies
Breaking Changes
PR Self-Review
Reviewed revision
f786d8d37284ce2767d8db1ec347015c0a120001f786d8d37: the exact overlap check budgets merged runs and builds them on the CPU (review fix)258cb0915: the docstring's crossover figures follow a re-run of the sweep (tables re-taken on a fixed test harness)e460a0f55: head-interleaved buffers are accepted,flydsl_projcolumn; the docstring's crossover and host-cost statements cite it.validate_slots=True(skipped during capture).e76275d0d: the slot check is nowvalidate_slots/padding_slotkeyword arguments (HK9: no new env knobs)AITER_KDA_DECODE_SLOT_CHECK[_PADDING_SLOT](and118109b3a's import-time parsing guard with it).out, so a row the kernel never zeroes fails them.626fa266dkeyscreate_kda_decode_kernelbydevice_index, so each GPU gets its own launcher (Copilot review)cuda:1aftercuda:0failed withhipErrorInvalidDevice.test_flydsl_kda_decode_runs_on_a_second_gpu.43565d87b..5bed9325d(review follow-up, tests and docstring only; no kernel change)flydsl_kda_decodedocstring: the row-stride rule.ef425dfafreverts the 0.25 Triton bound that5bed9325dadded; both kernels use 0.03 again_kda_referencerounds them to BF16, as the model and FlyDSL do._kda_reference(round_qkv=False)with the same 0.03 bound as FlyDSL.ee2c3d460host check that a caller-suppliedoutdoes not overlap an input or cacheflydsl_kda_decodeandflydsl_kda_decode_with_f_b; no sync, none in a graph._slot_blockssplits on the largest-stride axisoutinterleaved withoutput_gateorraw_gis accepted6d3d0c67cmerges main5c1489c24; the only conflict,.github/scripts/aiter_test.sh, keeps both sides.Behavior and intent
is_flydsl_kda_decode_supported(device).Validation and unverified scope
118109b3a:pytest -k kda op_tests/test_flydsl_linear_attention.py: 185 passed, 2 skipped (need 2 GPUs)626fa266d, 2 GPUs:pytest op_tests/test_flydsl_linear_attention.py: 225 passed6d3d0c67c: the same file, 223 passedvalidate-kernel-pratcc96f6ff5: PASS, 209/209 repo tests, 225/225 batch grid incl. 3/33/256, perf 1.0014c401182ab(torch 2.11.0+rocm7.2, FlyDSL 0.4.0): 197 passed; the merge base fails withImportErrorf562a48f8pytest -q op_tests/test_flydsl_linear_attention.py: 202 passed (all 184 KDA), 21 skipped (gfx950-only GDN)validate-kernel-prat50f48e709: PASS; 182-case grid; existing GDR decode perf 1.002x of basef786d8d37(MI355X gfx950, ROCm 10.0.0, torch 2.11.0+rocm10.0.0, one GPU)pytest -q op_tests/test_flydsl_linear_attention.py: 254 passed, 2 skipped (need 2 GPUs)258cb0915(docstring-only overe460a0f55); tests re-run one460a0f55codepytest -q op_tests/test_flydsl_linear_attention.py: 247 passed, 2 skipped (need 2 GPUs)-b 1 16 32 64 128 256, both state dtypes: exit 0 (table under Performance)e76275d0d(same machine)pytest -q op_tests/test_flydsl_linear_attention.py: 245 passed, 2 skipped-b 1 32 128 256, both state dtypes: exit 0ee2c3d460(same machine): 238 passed, 2 skipped; with theoutalias check disabled, its 11 reject cases fail-b 1 16 128: exit 0, the Triton rows pass under the 0.03 bound5bed9325d(same machine)pytest -q op_tests/test_flydsl_linear_attention.py: 224 passed, 2 skipped (need 2 GPUs)python op_tests/test_flydsl_linear_attention.py: exit 0, the KDA table prints withgfx950118109b3a(MI355X gfx950, ROCm 10.0.0, torch 2.11.0+rocm10.0.0, GPU 0)pytest -q op_tests/test_flydsl_linear_attention.py: 224 passed, 2 skipped (need 2 GPUs)118109b3a: 224 passed, 2 skippedvalidate-kernel-pronflydsl_kda_decode,--no-perf, over main4ba20eba9b: INCONCLUSIVE--no-perf)01514b730cwith [FlyDSL] [CI] [Kernel] Add a fused Kimi-K3 KDA target-verify kernel on gfx942 and gfx950 #7529 atc4f41fbce: ring off/on 0.980 / 0.980, snapshot off/on 0.985 / 0.980e460a0f55f562a48f8, last 2-GPU run626fa266dPR-specific question
_What behavior would each changed op test fail on before this PR,
and why is that coverage not already provided by an existing canonical test?_
Before this PR the file fails at collection: the KDA APIs do not exist on
main.KDA cases check numerics vs an FP32 reference, padded/out-of-range slot safety, input rejection,
Canonical KDA tests (
test_fused_kda_decode*.py) run only Triton; this file's other tests cover only GDR/GDN.Changed op tests
op_tests/test_flydsl_linear_attention.py: 217 KDA cases and a benchmark table on gfx942/gfx950 GPUsvalidate_slots/padding_slotslot check🤖 Generated with Claude Code