Skip to content

[FlyDSL] [CI] [Kernel] Add fused KDA decode kernels on gfx942 and gfx950 - #6026

Closed
yuychang wants to merge 33 commits into
ROCm:mainfrom
yuychang:feat/kimi-k3-kda-decode-flydsl
Closed

yuychang wants to merge 33 commits into
ROCm:mainfrom
yuychang:feat/kimi-k3-kda-decode-flydsl

Conversation

@yuychang

@yuychang yuychang commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Motivation

  • Kimi-K3 KDA decode runs as Triton fused_kda_decode plus a separate BF16 linear for the f_b projection.
  • The projection is its own launch and writes raw_g to HBM for the decode kernel to read back.
  • _with_f_b drops that launch and the raw_g round trip.
  • In-tree sweep on MI355X (table below): FlyDSL decode is 1.4-3.1x faster than Triton decode at batch 1-256.

Changes

  • kernels/gdr_decode.py: create_kda_decode_kernel
    • One launch fuses the width-4 causal conv, the FP32 state update with per-channel decay and RMSNorm/sigmoid gating.
    • fuse_f_b also computes f_b in FP32 and keeps it in LDS.
    • Specializations are keyed by device_index and cached like the GDR caches (maxsize=1024).
    • Numerics differ slightly from Triton: the convolved Q/K/V are rounded to BF16, where Triton keeps them in FP32.
  • linear_attention_kernels.py: wrappers with input validation
    • Shapes, dtypes, devices, dense non-overlapping cache slots, int32 addressing;
      • rejects a conv_weight with no unit-stride axis before compiling.
  • __init__.py: lazy exports of the three APIs.
  • op_tests/test_flydsl_linear_attention.py: 217 KDA cases
    • Plus a gfx942/gfx950 benchmark table with a Triton baseline
  • .github/scripts/aiter_test.sh: runs this file via pytest and then the script sweep; fails if either fails.
  • Contract
    • Negative or out-of-range state_indices: zero output, caches untouched.
    • Slot 0 is live, as in Triton fused_kda_decode.
    • Caches > 4 GiB are supported (slot rebase in int64).
    • conv_state: channel-major, or SGLang's width-major view.
    • Duplicate live slots are undefined; SGLang guarantees uniqueness.
    • A caller-supplied out that overlaps an input or cache raises ValueError (host arithmetic, no sync).
    • A state or conv_state that shares a byte with the other cache or a read-only input raises ValueError too.
    • Overlap is decided from spans first, then exactly on dense byte runs, so interleaved per-head buffers are accepted.
    • Host cost of all validation: about 46 us per eager call (25 us of it the cache checks); none under graph replay.
    • Tests now bound mismatches per token/head and per slot/head and start from a NaN-filled output.
    • The KDA sweep gates on is_flydsl_kda_decode_supported() and records get_gfx_runtime().
  • Opt-in slot check: keyword-only validate_slots=False and padding_slot=None on both decode APIs
    • validate_slots=True raises ValueError on duplicate live slots (host sync; skipped during graph capture).
    • It also flags SGLang's eager DP padding rows, which share slot 0; padding_slot=0 lets that slot repeat.
    • Keyword arguments, not environment variables, so no new permanent env knob is added.

Performance (if applicable)

  • New op, so there is no base-vs-head timing; the Triton fused_kda_decode path is the baseline.
  • Reproduce, then read the FlyDSL KDA decode summary table:
python op_tests/test_flydsl_linear_attention.py -b 1 16 32 64 128 256 --state-dtype fp32 bf16 --conv-layout width_major
  • Run on MI355X (gfx950, 256 CU), ROCm 10.0.0, torch 2.11.0+rocm10.0.0, triton 3.8.0, FlyDSL 0.5.0, one GPU.
    • Run on the code of e460a0f55 (the later head only edits a docstring); single run, us.
    • In-tree run_perftest: GPU time, not CUDA-graph replay.
    • These are GPU times: host validation (about 46 us per eager call, none under graph replay) is not included.
  • Columns
    • triton and flydsl are the decode alone; the Triton side has no projection in this table.
    • flydsl_proj is a BF16 F.linear into raw_g followed by flydsl_kda_decode (two launches).
    • flydsl_f_b is flydsl_kda_decode_with_f_b, which fuses the projection.
State Batch Triton FlyDSL FlyDSL proj + decode FlyDSL f_b fused Triton / FlyDSL Fused / proj + decode
FP32 1 16.14 8.32 13.70 9.29 1.94x 0.68
FP32 16 19.62 13.61 17.31 14.85 1.44x 0.86
FP32 32 35.74 20.27 23.74 21.85 1.76x 0.92
FP32 64 55.89 28.97 32.79 34.88 1.93x 1.06
FP32 128 102.68 51.29 54.90 59.70 2.00x 1.09
FP32 256 193.29 92.33 95.84 103.94 2.09x 1.08
BF16 1 14.65 8.45 12.23 9.36 1.73x 0.77
BF16 16 17.99 11.70 15.49 12.55 1.54x 0.81
BF16 32 33.00 14.48 18.95 18.37 2.28x 0.97
BF16 64 49.25 18.64 23.46 24.77 2.64x 1.06
BF16 128 94.13 33.72 37.81 45.14 2.79x 1.19
BF16 256 181.23 58.30 62.15 76.72 3.11x 1.23
  • FlyDSL decode is 1.4-3.1x faster than Triton decode here.
  • The fused projection wins by about 1-4 us up to batch 32 and loses by 6-23% from batch 64; the docstring says so.
    • The wrapper does not route by batch.
  • The earlier graph-replay table (2.1-2.4x at batch 1-128) is dropped: its script and versions were not recorded.
  • MI300X (gfx942) timing was last taken at f562a48f8
    • 4-7x over Triton, see Validation; not re-measured at this head

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X (unsupported; tests skip)
  • Tested on MI300X

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

  • None
    • The KDA APIs are new and opt-in; the GDR decode APIs are unchanged

PR Self-Review

Reviewed revision

f786d8d37284ce2767d8db1ec347015c0a120001

  • f786d8d37: the exact overlap check budgets merged runs and builds them on the CPU (review fix)
    • Before, the run budget multiplied unmerged dimension products, so head-interleaved buffers failed from batch 171.
    • Before, a CUDA default device made the check launch GPU kernels, which breaks graph capture.
    • 4 new cases (batch 256 accept, graph capture, both APIs) fail on the old check.
  • 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,
    • and the projection crossover is measured in-tree (review follow-up)
    • Overlap is decided exactly on dense byte runs once the span check suspects one; 2 accept cases per API.
    • The sweep gains a flydsl_proj column; the docstring's crossover and host-cost statements cite it.
    • The graph-replay test captures with validate_slots=True (skipped during capture).
  • e76275d0d: the slot check is now validate_slots / padding_slot keyword arguments (HK9: no new env knobs)
    • Replaces AITER_KDA_DECODE_SLOT_CHECK[_PADDING_SLOT] (and 118109b3a's import-time parsing guard with it).
    • Caches are alias-checked against each other and every read-only input; 8 reject cases fail without the check.
    • The padding-slot tests pass a NaN-filled out, so a row the kernel never zeroes fails them.
  • 626fa266d keys create_kda_decode_kernel by device_index, so each GPU gets its own launcher (Copilot review)
    • Before, a launch on cuda:1 after cuda:0 failed with hipErrorInvalidDevice.
    • Covered by test_flydsl_kda_decode_runs_on_a_second_gpu.
  • 43565d87b..5bed9325d (review follow-up, tests and docstring only; no kernel change)
    • Per-region mismatch bound (token/head output row, slot/head state block), measured worst 7.3e-3, bound 0.03.
    • The correctness call starts from a NaN-filled output; the sweep gate and gfx column use the runtime helpers.
    • flydsl_kda_decode docstring: the row-stride rule.
  • ef425dfaf reverts the 0.25 Triton bound that 5bed9325d added; both kernels use 0.03 again
  • Root cause of the Triton baseline's 9.4% region in the script sweep (not a bug; no bound was loosened)
    • Triton keeps the convolved Q/K/V in FP32; _kda_reference rounds them to BF16, as the model and FlyDSL do.
    • Against that reference, 6-15% of one token/head row sits one BF16 ULP away (0.0156 at |x| in [2, 4)).
    • Measured on MI355X, FP32 state, batch 1/16/64/96/128/160/256, worst region over the output rows:
      • Triton vs the BF16-Q/K/V reference: 0.008, 0.063, 0.078, 0.094, 0.094, 0.141, 0.086; 6-9% of rows > 3%.
      • Triton vs a reference without the Q/K/V rounding: 0 at every batch, state exact; BF16 state 0 too.
      • FlyDSL is the mirror image: about 0 vs the BF16 reference, 0.06-0.14 vs the FP32 one.
      • Batch 128 is not special: seeds 1-3 give 0.086, 0.070, 0.148; the worst row moves across heads and tokens.
    • The sweep now checks Triton against _kda_reference(round_qkv=False) with the same 0.03 bound as FlyDSL.
      • Its worst region there is 0.0078 (one element) over batches 1-256 and 4 seeds.
  • ee2c3d460 host check that a caller-supplied out does not overlap an input or cache
    • Covers flydsl_kda_decode and flydsl_kda_decode_with_f_b; no sync, none in a graph.
    • _slot_blocks splits on the largest-stride axis
      • So an out interleaved with output_gate or raw_g is accepted
    • 11 reject cases fail without the check; 3 accept cases cover interleaved layouts.
  • 6d3d0c67c merges main 5c1489c24; the only conflict, .github/scripts/aiter_test.sh, keeps both sides.

Behavior and intent

  • Adds an opt-in fused FlyDSL KDA decode path, gated by is_flydsl_kda_decode_supported(device).
    • gfx942 and gfx950; the GPU must also match FlyDSL's build target.
  • No existing op changes behavior.

Validation and unverified scope

  • MI355X (gfx950)
    • At 118109b3a: pytest -k kda op_tests/test_flydsl_linear_attention.py: 185 passed, 2 skipped (need 2 GPUs)
    • At 626fa266d, 2 GPUs: pytest op_tests/test_flydsl_linear_attention.py: 225 passed
    • At 6d3d0c67c: the same file, 223 passed
    • validate-kernel-pr at cc96f6ff5: PASS, 209/209 repo tests, 225/225 batch grid incl. 3/33/256, perf 1.0014
    • At c401182ab (torch 2.11.0+rocm7.2, FlyDSL 0.4.0): 197 passed; the merge base fails with ImportError
  • MI300X (gfx942, 304 CU), FlyDSL 0.4.2, at f562a48f8
    • pytest -q op_tests/test_flydsl_linear_attention.py: 202 passed (all 184 KDA), 21 skipped (gfx950-only GDN)
    • validate-kernel-pr at 50f48e709: PASS; 182-case grid; existing GDR decode perf 1.002x of base
    • KDA sweep vs Triton (width-major, us): b1 fp32 9.7 vs 71.4; b128 fp32 80.6 vs 331.5; b1 bf16 10.5 vs 65.3;
      • b128 bf16 60.9 vs 284.3 (4-7x)
  • Head f786d8d37 (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)
    • With the old overlap check, the 4 new cases fail (done in the worktree, then restored).
  • Head 258cb0915 (docstring-only over e460a0f55); tests re-run on e460a0f55 code
    • MI355X gfx950, ROCm 10.0.0, torch 2.11.0+rocm10.0.0, one GPU
    • pytest -q op_tests/test_flydsl_linear_attention.py: 247 passed, 2 skipped (need 2 GPUs)
    • Script sweep -b 1 16 32 64 128 256, both state dtypes: exit 0 (table under Performance)
    • Removing the cache alias check fails its 8 reject cases.
    • Removing the exact run comparison fails the 2 interleaved accept cases.
  • Head e76275d0d (same machine)
    • pytest -q op_tests/test_flydsl_linear_attention.py: 245 passed, 2 skipped
    • With the cache alias check removed, the 8 new reject cases fail (done in the worktree, then restored)
    • Script sweep -b 1 32 128 256, both state dtypes: exit 0
  • Head ee2c3d460 (same machine): 238 passed, 2 skipped; with the out alias check disabled, its 11 reject cases fail
    • Script sweep -b 1 16 128: exit 0, the Triton rows pass under the 0.03 bound
  • Review follow-up, head 5bed9325d (same machine)
    • pytest -q op_tests/test_flydsl_linear_attention.py: 224 passed, 2 skipped (need 2 GPUs)
    • Zeroing one token/head of the output, or one slot/head of the state,
      • at batch 128 fails the new bound (done on a scratch copy; the pool-wide ratio alone passes it)
    • Script sweep python op_tests/test_flydsl_linear_attention.py: exit 0, the KDA table prints with gfx950
  • Head 118109b3a (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)
    • Repeated on GPU 0 at 118109b3a: 224 passed, 2 skipped
    • validate-kernel-pr on flydsl_kda_decode, --no-perf, over main 4ba20eba9b: INCONCLUSIVE
      • Passed: merge sim, runtime compat, test policy, baseline control, repo tests, execution receipt
      • Skipped: the S1 grid (no shape-grid hook for this target) and perf (--no-perf)
      • The index-width scan is informational: 16 index/stride candidates without 64-bit widening, not triaged
  • Kimi-K3 accuracy: no run of this decode kernel (a TP8 run needs 8 GPUs)
  • Unverified
    • Model-level accuracy of the decode kernel itself
    • Slot uniqueness is unchecked by default; gfx942 runs the gfx950 tuning; owner sign-off is pending
    • MI300X and the 2-GPU cases at the current head e460a0f55
      • Last MI300X run f562a48f8, last 2-GPU run 626fa266d

PR-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,

    • alias rejection and the slot check.
  • 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 GPUs
    • Cache alias rejection and the validate_slots / padding_slot slot check
    • Each state/output comparison also bounds the worst token/head or slot/head region
    • The Triton baseline is checked against a reference that does not round Q/K/V to BF16
    • Out-overlap rejection and interleaved-layout accept cases
    • The GDR/GDN cases that share the kernel file are unchanged.

🤖 Generated with Claude Code

@yuychang
yuychang requested review from a team and a balanced review from Copilot October 1, 2026 00:16
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
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
multigpu 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: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 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-actions github-actions Bot 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
@github-actions github-actions Bot added the FlyDSL label Oct 1, 2026
@yuychang yuychang changed the title [FlyDSL] feat(flydsl): add fused KDA decode kernels on gfx950 [FlyDSL] Add fused KDA decode kernels on gfx950 Oct 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The linked consumer targets incompatible names, and cache-index bounds and uniqueness remain unsafe.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity · 1 Low severity

Open (3)
What changed in this PR

Adds gfx950 FlyDSL kernels for fused KDA decoding in the fixed Kimi-K3 TP8 layout.

Changes:

  • Adds fused decode and optional head-local f_b projection kernels.
  • Exposes validated public APIs and hardware support detection.
  • Adds correctness, cache, validation, and export tests.
File Description
aiter/​ops/​flydsl/​kda_decode.py Implements public launch and validation APIs.
aiter/​ops/​flydsl/​kernels/​kda_decode_gfx950.py Adds the fused decode kernel.
aiter/​ops/​flydsl/​kernels/​kda_decode_fused_projection_gfx950.py Adds fused projection and decode.
aiter/​ops/​flydsl/​kernels/​vector.py Adds vendored vector wrappers.
aiter/​ops/​flydsl/​__init__.py Exports the new APIs lazily.
op_tests/​flydsl_tests/​test_kda_decode.py Tests correctness, caches, validation, and exports.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread aiter/ops/flydsl/kda_decode.py Resolved
Comment thread aiter/ops/flydsl/kda_decode.py Resolved
Comment thread aiter/ops/flydsl/kernels/vector.py Resolved
Copilot AI balanced review requested due to automatic review settings October 1, 2026 00:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Out-of-range positive state indices can cause GPU memory access beyond either cache.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity · 1 Low severity

Open (3)

@zufayu
zufayu requested a review from yadaish October 1, 2026 00:33
yuychang added a commit to yuychang/sglang that referenced this pull request 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
@yuychang
yuychang requested a balanced review from Copilot October 1, 2026 04:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The kernels use 32-bit cache-offset arithmetic that can wrap and access memory out of bounds for large state pools.

Review effort: Balanced
Findings: 3 High severity · 1 Medium severity · 1 Low severity

Open (5)

Copilot AI balanced review requested due to automatic review settings October 1, 2026 06:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Caller-provided scalar values create unbounded JIT cache entries in both kernel variants.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity

Open (2)
Resolved since last review (3)
Previously missed (2)

In code that hasn't changed since last review

Medium severity Projection cache grows without bound for distinct float parameters

aiter/​ops/​flydsl/​kernels/​kda_decode_fused_projection_gfx950.py:40

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.

Medium severity Unbounded specialization cache leaks memory for varying float parameters

aiter/​ops/​flydsl/​kernels/​kda_decode_gfx950.py:38

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.

Copilot AI balanced review requested due to automatic review settings October 1, 2026 06:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

The low-level GPU kernels require human review and a current gfx950 run covering all 17 collected tests.

Review effort: Balanced
Findings: 1 Medium severity · 1 Low severity

Open (2)
Resolved since last review (1)

Copilot AI balanced review requested due to automatic review settings October 5, 2026 02:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Unchecked 32-bit stride and byte-span limits can cause wrapped, out-of-bounds kernel addressing.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity

Open (2)
Resolved since last review (1)

Comment thread aiter/ops/flydsl/kda_decode.py Resolved
Copilot AI balanced review requested due to automatic review settings October 7, 2026 10:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Overlapping cache and output strides can cause concurrent writes, and the reported test result is not from the current test revision.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity · 1 Low severity

Open (3)
Resolved since last review (1)

Comment thread aiter/ops/flydsl/kda_decode.py Resolved
@yuychang

yuychang commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Hi team, could you please review this PR when you have time? Thank you!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

No open issues 🎉

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Missing head-matched gfx942/gfx950 validation evidence leaves fused-kernel correctness, CUDA-graph replay, and paired performance results requiring human verification.

No open issues 🎉

Review effort: Balanced

- Resolve the .github/scripts/aiter_test.sh conflict: keep this PR's KDA pytest+script case and main's pytest-only file list

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

1 open issue

Review effort: Balanced

Comment thread aiter/ops/flydsl/kernels/gdr_decode.py Resolved
- 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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

1 open issue

Review effort: Balanced

- 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

… 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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

BF16 Q/K/V rounding and in-place recurrent updates lack model-level decode accuracy and current-head runtime validation, requiring GPU-owner numerical and architecture sign-off.

No open issues 🎉

Review effort: Balanced

…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)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

1 open issue

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)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

1 open issue

Review effort: Balanced

…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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

1 open issue
1 resolved since last review

Review effort: Balanced

…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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

1 open issue

Review effort: Balanced

…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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because an omitted moderate finding indicates that the benchmark’s performance metrics undercount projection work.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

- 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

1 open issue

Review effort: Balanced

region_dims=2,
)
assert torch.equal(reference_inputs.conv_state, actual_inputs.conv_state)
flops, nbytes = _kda_decode_work(batch, fuse_f_b, base_inputs.state)
@yuychang

Copy link
Copy Markdown
Contributor Author

Closing: the Kimi-K3/K3.1 DSpark servers verify and never run target KDA decode, so these decode kernels are not reached.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants