Repository navigation
[FlyDSL] [Build] Add gfx950 Kimi Delta Attention prefill kernel - #4741
Open
amd-wsung102 wants to merge 6 commits into
Open
amd-wsung102 wants to merge 6 commits into
amd-wsung102 wants to merge 6 commits into
Conversation
Contributor
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
5 tasks done
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.
1 task done
Contributor
|
No activity for 15 days, so this is now labelled |
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.
NOT READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
Contributor
|
No activity for 15 days, so this is now labelled |
12 of 19 tasks
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Reviewed revision
47171887472381328b7771677279bf72ff3f84ffBehavior and intent
This PR adds a FlyDSL chunkwise Kimi Delta Attention (KDA) prefill path for gfx950, exposed as
flydsl_chunk_kda(plusflydsl_kda_supportedandkda_chunk_fwd) inaiter.ops.flydsl. It is a drop-in replacement forfla.ops.kda.chunk_kda/chunk_kimi_delta_attnfor 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_supportedand the dispatch guard returnNone, so callers fall back to the existing path, in these cases:The fused single-kernel variant (
kda_kernel.py) is included for reference but is not dispatched. At Kimi'sgate_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 inmain's new_LAZY_IMPORTStable.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 theis_flydsl_availablehelper 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.pygives 32 passed, with FlyDSL 0.4.2 (the versionmainpins).chunk_kdain every run, by 1.12x to 1.77x.ruff checkandblack --checkpass on the changed files.pyproject.tomlparses withtomllib.Validated on an earlier, pre-merge revision of this branch (ATOM, MI355X, TP=8, Kimi-K3,
rocm/atom-dev:latest):Unverified:
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 atflydsl==0.4.2there), and this PR doesn't change the pin. FLA is used only as the test reference and is optional: the test callspytest.importorskip("fla.ops.kda").pyproject.tomlonly 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:
functools.lru_cache(maxsize=256)holds them, so the 69 KDA layers that share a shape within a step reuse one build.FLYDSL_RUNTIME_CACHE_DIR) persists the compiled kernels across processes.Verification (FlyDSL 0.4.2, MI355X):
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 newflydsl_chunk_kdaop, which no existing test exercises.fla.ops.kda.chunk_kdaat 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.is_flydsl_availablehelper 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.