Repository navigation
[Triton] Optimize chunk_delta_attn performance. - #4683
Merged
Merged
Conversation
Contributor
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
Liang-jianhao97
force-pushed
the
feature/chunk_delta_attn_flashkda
branch
from
August 12, 2026 02:47
33c333d to
d9f9d6d
Compare
Liang-jianhao97
force-pushed
the
feature/chunk_delta_attn_flashkda
branch
2 times, most recently
from
August 12, 2026 07:03
ef06e6e to
8545855
Compare
Liang-jianhao97
force-pushed
the
feature/chunk_delta_attn_flashkda
branch
from
August 12, 2026 07:59
8545855 to
0b2d380
Compare
1. Add the fused two-kernel forward path, on by default for the varlen prefill shapes flash_kda_supported() admits and falling back to the default pipeline for every other shape or flag combination 2. Cache the cu_seqlens readback and the chunk index tensor on argument identity, and add the segment count to K2's autotune key so the segmented and unsegmented schedules stop sharing one tuned config Co-authored-by: Cursor <[email protected]>
Liang-jianhao97
force-pushed
the
feature/chunk_delta_attn_flashkda
branch
from
August 13, 2026 01:05
ed0cbc7 to
c072a4a
Compare
The WY inverse was built by Neumann doubling across the whole 32-wide chunk. That is exact in exact arithmetic, but L^k counts paths down the chunk, so once the keys correlate and the gate stops damping L its entries reach 5e7 while the inverse they sum to stays bounded by 1. Nothing survives that cancellation: the flat doubling is 1e5 wrong in bf16 and still 400% wrong in fp32, and K2's recurrence turns that into NaN. This is what took Kimi-K3 gsm8k to 0.2% with every unit test here passing. Invert the 16-wide diagonal blocks instead, then fold the sub-diagonal block back in with a single exact term, which closes because INV @ L_off is nilpotent at each merge level. The powers peak at 2e3, the matmul count is unchanged, and the result lands within 2e-4 of an fp64 triangular solve. Store it as fp16 rather than bf16. The inverse is bounded by 1, so what limits the fused path is mantissa rather than range, and both are two bytes: bf16 here scores 1.1e-2 on the correlated cases where fp16 scores 2.3e-3. fp32 would fix the storage too but costs 1.3-1.5x, since K2 reads this twice per chunk on its serial path. Store the three C x K tiles before the inversion rather than after. Held live across it, the extra tile pushed the prepare kernel to 274 VGPRs at H=64, over the 256 that gfx9 needs for two waves per SIMD, costing 26% there and nothing at any other head count. Correlated keys with a weak gate now score 2.3e-3 against the fp32 recurrence where the default pipeline scores 1.3e-2, and benchmarks are unchanged within 3% across 13 shapes. The new case fails with NaN on the old algorithm. Co-authored-by: Cursor <[email protected]>
Liang-jianhao97
force-pushed
the
feature/chunk_delta_attn_flashkda
branch
from
August 13, 2026 02:19
c072a4a to
e099f64
Compare
An unannotated fp32 tl.dot is not fp32 on every target. tl.dot resolves input_precision to "tf32" whenever the backend merely allows it, so gfx942 lowered the five dots that invert (I - L) to v_mfma_f32_32x32x4_xf32, which truncates operands to 19 bits without rounding. On a doubling this cancellation-prone that is bf16-grade: the inverse came out 2e1 off and K2's recurrence went NaN on the correlated-key case. gfx950 has no xf32 MFMA and resolves the same dots to ieee, which is why the test only failed on MI308X. Verified on gfx942: the ISA switches to v_mfma_f32_32x32x2_f32, and rho=0.9 and rho=1.0 pass at 1.2e-2 relative error where they previously produced NaN. Co-authored-by: Cursor <[email protected]>
1 task done
1 task
12 of 19 tasks
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.
Motivation
Optimize chunk delta attn performance.
Technical Details
shapes flash_kda_supported() admits and falling back to the default pipeline
for every other shape or flag combination
and add the segment count to K2's autotune key so the segmented and
unsegmented schedules stop sharing one tuned config
Test Plan
Test Result
All correctness tests pass (bfloat16, atol=1e-2, rtol=1e-2). Precision verification passed on GFX1250/GFX950/GFX942.

Kimi-K3 accuracy pass.
https://github.com/ROCm/ATOM/actions/runs/31656616128/job/94313083167
GFX950 Perf Data:
Submission Checklist