Skip to content

[FlyDSL] [Build] Add gfx950 Kimi Delta Attention prefill kernel - #4741

Open
amd-wsung102 wants to merge 6 commits into
ROCm:mainfrom
amd-wsung102:flydsl_kda_kernel
Open

amd-wsung102 wants to merge 6 commits into
ROCm:mainfrom
amd-wsung102:flydsl_kda_kernel

Conversation

@amd-wsung102

@amd-wsung102 amd-wsung102 commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Reviewed revision

47171887472381328b7771677279bf72ff3f84ff

Behavior and intent

This PR adds a FlyDSL chunkwise Kimi Delta Attention (KDA) prefill path for gfx950, exposed as flydsl_chunk_kda (plus flydsl_kda_supported and kda_chunk_fwd) in aiter.ops.flydsl. It is a drop-in replacement for fla.ops.kda.chunk_kda / chunk_kimi_delta_attn for bf16, 128-wide K/V heads.

Existing behavior: KDA prefill runs through FLA's multi-kernel Triton stack. That is about 9 launches per layer call: two l2norm calls, gate cumsum, beta sigmoid, two intra-chunk kernels, the w/u recompute, the state scan and the output matmul. That costs 364.5 µs per layer call in the Kimi-K3 serving profile.

New behavior: one fused Triton pack, two FlyDSL kernels (prep and scan) and one Triton unpack, totaling 269.1 µs per layer call (1.35x on the KDA block).

Nothing changes for callers that don't opt in. flydsl_kda_supported and the dispatch guard return None, so callers fall back to the existing path, in these cases:

  • non-gfx950 hardware, non-bf16 dtypes or non-128 heads;
  • lopsided batches where padding would dominate;
  • memory pressure;
  • sequences past the measured crossover with Triton (2048 tokens per sequence for batches of 4 or more sequences, 1024 for smaller batches).

The fused single-kernel variant (kda_kernel.py) is included for reference but is not dispatched. At Kimi's gate_lower_bound = -5, it overflows fp32 and produces NaNs. The split path stays exact out to 640 nats of decay.

The latest revision only merges main, and the KDA kernels, wrapper and pack/unpack code are byte-identical to the pre-merge branch. The merge makes three adaptations:

  • __init__.py: the KDA exports are registered in main's new _LAZY_IMPORTS table.
  • pyproject.toml: the two [tool.black] tables (main's and this PR's) are folded into one, because declaring the table twice is invalid TOML.
  • test_flydsl_kda.py: the test no longer imports the is_flydsl_available helper removed in [Triton/Gluon] [HIP] [CK] Remove obsolete availability helpers #5116.

Validation and unverified scope

Validated on this revision (MI355X / gfx950, ROCm 7.2.3, torch 2.10.0+rocm7.2.3, FLA 0.6.0):

  • pytest op_tests/flydsl_tests/test_flydsl_kda.py gives 32 passed, with FlyDSL 0.4.2 (the version main pins).
  • Kernel time measured with the torch profiler (GPU kernel time per call, median of 20 calls, H=12, 4 shapes: 10x1024, 4x1024, 5x2048 and ragged), comparing the pre-merge branch on FlyDSL 0.3.2 with this revision on FlyDSL 0.3.2 and 0.4.2:
    • The FlyDSL path is faster than FLA chunk_kda in every run, by 1.12x to 1.77x.
    • Pre-merge and post-merge times overlap for every shape, with no consistent regression from the merge or from FlyDSL 0.4.2.
  • ruff check and black --check pass on the changed files. pyproject.toml parses with tomllib.

Validated on an earlier, pre-merge revision of this branch (ATOM, MI355X, TP=8, Kimi-K3, rocm/atom-dev:latest):

  • End-to-end serving profile: 1.35x on the KDA block.
  • Needle-in-haystack: 100% at 1k/1k, 8k/1k and 1k/8k, matching the baseline.
  • GSM8K 5-shot: 95.98% vs 95.68% baseline (strict-match).

Unverified:

  • ATOM end-to-end serving, needle-in-haystack and GSM8K have not been rerun on this merged revision.
  • The microbenchmarks ran on a shared node where other jobs were using the GPUs, so run-to-run noise was about ±20%. They rule out a large regression, but not a small one of a few percent.
  • Only gfx950 was tested. Other architectures are expected to take the fallback path via flydsl_kda_supported; that was covered by the dispatch-guard unit tests but not run on other hardware.

PR-specific question

What changes in dependency, cache or compilation behavior, and how did you verify both a clean build and an existing-cache path?

Dependencies: none added. FlyDSL is already a required dependency on main (pinned at flydsl==0.4.2 there), and this PR doesn't change the pin. FLA is used only as the test reference and is optional: the test calls pytest.importorskip("fla.ops.kda"). pyproject.toml only adds Ruff and Black excludes for the two vendored FlyDSL kernel files, so they stay byte-identical to their FlyDSL source.

Compilation and caching: there is no change to aiter's C++/HIP JIT build. The KDA kernels compile at runtime in three layers:

  • FlyDSL builds the prep and scan modules on first use for each shape (about 35 ms each). An in-process functools.lru_cache(maxsize=256) holds them, so the 69 KDA layers that share a shape within a step reuse one build.
  • FlyDSL's on-disk runtime cache (FLYDSL_RUNTIME_CACHE_DIR) persists the compiled kernels across processes.
  • The pack and unpack kernels are ordinary Triton kernels and use Triton's standard cache.

Verification (FlyDSL 0.4.2, MI355X):

export FLYDSL_RUNTIME_CACHE_DIR=/tmp/kda_fly_cache   # starts empty
pytest op_tests/flydsl_tests/test_flydsl_kda.py      # clean cache:  32 passed in 19.8 s, writes 48 cache files (328 KB)
pytest op_tests/flydsl_tests/test_flydsl_kda.py      # warm cache:   32 passed in 7.5 s, reuses the same 48 files and writes no new ones

Not verified: a clean Triton cache for the pack/unpack kernels. Those runs used the existing default Triton cache.

Changed op tests

  • op_tests/flydsl_tests/test_flydsl_kda.py (new; 32 tests): it covers the new flydsl_chunk_kda op, which no existing test exercises.
    • Coverage: it checks output and final state against fla.ops.kda.chunk_kda at bf16 tolerance (relative error < 2e-2). Cases include multi-sequence packed prefills, ragged and non-chunk-aligned lengths, runs with and without an initial state, and saturated worst-case gates (the decay regime where the fused variant produces NaNs). It also covers raw-bf16 vs fp32 beta, the single-chunk and single-token edge cases, out= aliasing, and the dispatch-guard fallback cases.
    • Why it's not redundant: no other test exercises this op, the pack/unpack kernels, or the dispatch guard. The existing KDA tests cover the Triton/FLA path, not this one.
    • Change in this revision: it no longer imports the is_flydsl_available helper that [Triton/Gluon] [HIP] [CK] Remove obsolete availability helpers #5116 removed (FlyDSL is now a hard dependency), matching how the other FlyDSL tests were updated in [Triton/Gluon] [HIP] [CK] Remove obsolete availability helpers #5116. The test cases themselves are unchanged.

@amd-wsung102
amd-wsung102 requested a review from a team August 13, 2026 21:09
@github-actions

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; main branch always runs both MI35X and MI300X
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 4741 --add-label <label>

@amd-wsung102 amd-wsung102 changed the title [FlyDSL] Add gfx950 Kimi Delta Attention Prefill Kernel [FlyDSL] Add gfx950 Kimi Delta Attention prefill kernel Aug 13, 2026
Format the FlyDSL KDA wrapper and test, sort imports and __all__, rewrite the
test's dict() calls as literals, and simplify a boolean return.

Exclude the two vendored FlyDSL kernels (kda_kernel.py, kda_split.py) from
Black and Ruff so they stay byte-identical to their FlyDSL source rather than
reformatting a vendored copy.
@zufayu
zufayu requested a review from coderfeli August 14, 2026 01:31
@github-actions github-actions Bot changed the title [FlyDSL] Add gfx950 Kimi Delta Attention prefill kernel [FlyDSL] [Build] Add gfx950 Kimi Delta Attention prefill kernel Aug 24, 2026
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

No activity for 15 days, so this is now labelled stale. A push or a comment clears it; keep-open exempts it.

@github-actions github-actions Bot added the stale The PR hasn't been updated in 2 weeks label Oct 7, 2026
@zufayu
zufayu requested a review from xytpai October 29, 2026 09:32
@github-actions github-actions Bot removed the stale The PR hasn't been updated in 2 weeks label Oct 30, 2026
Resolve the aiter/ops/flydsl/__init__.py conflict: main replaced the eager
imports with the _LAZY_IMPORTS table, so register flydsl_chunk_kda,
flydsl_kda_supported and kda_chunk_fwd there and in __all__.

Also fix two breaks the merge left without a textual conflict:
- pyproject.toml had [tool.black] declared twice (main's .claude exclude and
  this branch's force-exclude of the vendored KDA kernels), which is invalid
  TOML; fold them into one table.
- main removed aiter.ops.flydsl.utils.is_flydsl_available (ROCm#5116); drop the
  check from test_flydsl_kda.py, matching the other FlyDSL tests.
@aiter-bot

aiter-bot commented Nov 5, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision 471718874723 · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

This PR adds a FlyDSL chunkwise Kimi Delta Attention (KDA) prefill path for gfx950, exposed as `flydsl_chunk_kda` (plus `flydsl_kda_supported` and `kda_chunk_fwd`) in `aiter.ops.flydsl`. It is a drop-in replacement for `fla.ops.kda.chunk_kda` / `chunk_kimi_delta_attn` for bf16, 128-wide K/V heads.

Existing behavior: KDA prefill runs through FLA's multi-kernel Triton stack. That is about 9 launches per layer call: two l2norm calls, gate cumsum, beta sigmoid, two intra-chunk kernels, the w/u recompute, the state scan and the output matmul. That costs 364.5 µs per layer call in the Kimi-K3 serving profile.

New behavior: one fused Triton pack, two FlyDSL kernels (prep and scan) and one Triton unpack, totaling 269.1 µs per layer call (1.35x on the KDA block).

Nothing changes for callers that don't opt in. `flydsl_kda_supported` and the dispatch guard return `None`, so callers fall back to the existing path, in these cases:
- non-gfx950 hardware, non-bf16 dtypes or non-128 heads;
- lopsided batches where padding would dominate;
- memory pressure;
- sequences past the measured crossover with Triton (2048 tokens per sequence for batches of 4 or more sequences, 1024 for smaller batches).

The fused single-kernel variant (`kda_kernel.py`) is included for reference but is not dispatched. At Kimi's `gate_lower_bound = -5`, it overflows fp32 and produces NaNs. The split path stays exact out to 640 nats of decay.

The latest revision only merges `main`, and the KDA kernels, wrapper and pack/unpack code are byte-identical to the pre-merge branch. The merge makes three adaptations:
- `__init__.py`: the KDA exports are registered in `main`'s new `_LAZY_IMPORTS` table.
- `pyproject.toml`: the two `[tool.black]` tables (`main`'s and this PR's) are folded into one, because declaring the table twice is invalid TOML.
- `test_flydsl_kda.py`: the test no longer imports the `is_flydsl_available` helper removed in #5116.

Validation and unverified scope

Validated on this revision (MI355X / gfx950, ROCm 7.2.3, torch 2.10.0+rocm7.2.3, FLA 0.6.0):
- `pytest op_tests/flydsl_tests/test_flydsl_kda.py` gives **32 passed**, with FlyDSL 0.4.2 (the version `main` pins).
- Kernel time measured with the torch profiler (GPU kernel time per call, median of 20 calls, H=12, 4 shapes: 10x1024, 4x1024, 5x2048 and ragged), comparing the pre-merge branch on FlyDSL 0.3.2 with this revision on FlyDSL 0.3.2 and 0.4.2:
  - The FlyDSL path is faster than FLA `chunk_kda` in every run, by 1.12x to 1.77x.
  - Pre-merge and post-merge times overlap for every shape, with no consistent regression from the merge or from FlyDSL 0.4.2.
- `ruff check` and `black --check` pass on the changed files. `pyproject.toml` parses with `tomllib`.

Validated on an earlier, pre-merge revision of this branch (ATOM, MI355X, TP=8, Kimi-K3, `rocm/atom-dev:latest`):
- End-to-end serving profile: 1.35x on the KDA block.
- Needle-in-haystack: 100% at 1k/1k, 8k/1k and 1k/8k, matching the baseline.
- GSM8K 5-shot: 95.98% vs 95.68% baseline (strict-match).

Unverified:
- ATOM end-to-end serving, needle-in-haystack and GSM8K have not been rerun on this merged revision.
- The microbenchmarks ran on a shared node where other jobs were using the GPUs, so run-to-run noise was about ±20%. They rule out a large regression, but not a small one of a few percent.
- Only gfx950 was tested. Other architectures are expected to take the fallback path via `flydsl_kda_supported`; that was covered by the dispatch-guard unit tests but not run on other hardware.

PR-specific question

**What changes in dependency, cache or compilation behavior, and how did you verify both a clean build and an existing-cache path?**

Dependencies: none added. FlyDSL is already a required dependency on `main` (pinned at `flydsl==0.4.2` there), and this PR doesn't change the pin. FLA is used only as the test reference and is optional: the test calls `pytest.importorskip("fla.ops.kda")`. `pyproject.toml` only adds Ruff and Black excludes for the two vendored FlyDSL kernel files, so they stay byte-identical to their FlyDSL source.

Compilation and caching: there is no change to aiter's C++/HIP JIT build. The KDA kernels compile at runtime in three layers:
- FlyDSL builds the prep and scan modules on first use for each shape (about 35 ms each). An in-process `functools.lru_cache(maxsize=256)` holds them, so the 69 KDA layers that share a shape within a step reuse one build.
- FlyDSL's on-disk runtime cache (`FLYDSL_RUNTIME_CACHE_DIR`) persists the compiled kernels across processes.
- The pack and unpack kernels are ordinary Triton kernels and use Triton's standard cache.

Verification (FlyDSL 0.4.2, MI355X):
```
export FLYDSL_RUNTIME_CACHE_DIR=/tmp/kda_fly_cache   # starts empty
pytest op_tests/flydsl_tests/test_flydsl_kda.py      # clean cache:  32 passed in 19.8 s, writes 48 cache files (328 KB)
pytest op_tests/flydsl_tests/test_flydsl_kda.py      # warm cache:   32 passed in 7.5 s, reuses the same 48 files and writes no new ones
```
Not verified: a clean Triton cache for the pack/unpack kernels. Those runs used the existing default Triton cache.

Changed op tests

- `op_tests/flydsl_tests/test_flydsl_kda.py` (new; 32 tests): it covers the new `flydsl_chunk_kda` op, which no existing test exercises.
  - Coverage: it checks output and final state against `fla.ops.kda.chunk_kda` at bf16 tolerance (relative error < 2e-2). Cases include multi-sequence packed prefills, ragged and non-chunk-aligned lengths, runs with and without an initial state, and saturated worst-case gates (the decay regime where the fused variant produces NaNs). It also covers raw-bf16 vs fp32 beta, the single-chunk and single-token edge cases, `out=` aliasing, and the dispatch-guard fallback cases.
  - Why it's not redundant: no other test exercises this op, the pack/unpack kernels, or the dispatch guard. The existing KDA tests cover the Triton/FLA path, not this one.
  - Change in this revision: it no longer imports the `is_flydsl_available` helper that #5116 removed (FlyDSL is now a hard dependency), matching how the other FlyDSL tests were updated in #5116. The test cases themselves are unchanged.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • FAIL — Aiter Test Gate: failed
  • Required CI failed; fix it before requesting human review.

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

@github-actions

Copy link
Copy Markdown
Contributor

No activity for 15 days, so this is now labelled stale. A push or a comment clears it; keep-open exempts it. Nothing is closed automatically.

@github-actions github-actions Bot added the stale The PR hasn't been updated in 2 weeks label Nov 21, 2026

This branch has not been deployed

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

Labels

Build FlyDSL stale The PR hasn't been updated in 2 weeks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants