Skip to content

[Triton/Gluon] [gfx950/1250] FlashKDA updates - #8043

Merged
azaidy merged 16 commits into
mainfrom
omuhamma/flash-kda-950
Dec 1, 2026
Merged

azaidy merged 16 commits into
mainfrom
omuhamma/flash-kda-950

Conversation

@omuhamma

@omuhamma omuhamma commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Speeds up the Gluon FlashKDA prefill (chunk_kimi_delta_attn) on gfx950 and gfx1250, and adds a fused output gated RMSNorm, native prefill checkpoints and a host-side plan. The existing API is unchanged; every new argument is optional.

Both architectures

  • Fused norm (out_gate, norm_weight, norm_eps): rmsnorm(o) * norm_weight * sigmoid(out_gate) in pass C, weight cast to fp32 in the kernel.
  • Checkpoints (checkpoint_state, checkpoint_offsets, checkpoint_state_indices): pass C writes mid-prefill states in place into a padded paged state cache, with no host syncs.
  • cu_seqlens_cpu: the plan is built from the host copy, cached by value and uploaded non-blocking, so a call makes no device-to-host read.
  • Busy-step planning: a long sequence alongside many short ones is split instead of walked serially.

gfx950

  • K1: diag(beta) folded into the fp16 inverse, perm32 operand order with 16 B stores; K2 no longer reads beta.
  • Pass A: fp8 A_seg / bf16 b_seg for the scan, XCD-aware row pairing.
  • Scan + pass C in one launch: per-XCD scan replicas, epoch-tagged flags, tapered segment plan for long sequences. Epochs live on the device, so CUDA graph replay is safe.
  • Copier-wave pass C: 4 waves copy and normalize while 4 run the recurrence.
  • Persistent per-stream workspaces, no-op dtype casts skipped, plan values in the gfx950 Gluon DEFAULT.json, and warmup_chunk_kimi_delta_attn to precompile the variants.

gfx1250

  • Pass C: fused gated RMSNorm (row sums with one barrier) and prefill checkpoints, matching gfx950.
  • K1: chunk-matrix inverse as four 16x16 tiles in registers, with D^T the only trip through LDS; exp2 on two tiles instead of four; seven waves per SIMD.
  • Pass A: skips each sequence's last segment, which the scan never reads.
  • Segment planner: one-wave fit; packed pass C (two workgroups per CU) from 64 chunks; MIN_CHUNKS 64 so the Triton and Gluon routes agree; square-root floor on the segment length. Plan values in the gfx1250 Gluon DEFAULT.json.

Testing

Unit tests in op_tests/triton_tests/kimi_delta_attn/ pass on 350 & 450.

Performance 950

MI355X, Kimi-K3 TP8 shapes (H = 12, K = V = 128, bf16, q/k/v as bands of one fused projection). GPU kernel time per call in µs (torch profiler, mean of 50 calls). Before is FlashKDA on main (cefb40042), after is this PR. With norm: before runs FlashKDA followed by a separate gated RMSNorm (FLA Triton rms_norm_gated, sigmoid gate); after fuses it into FlashKDA (out_gate, norm_weight, norm_eps).

batch × seqlen without norm: before after speedup with norm: before after speedup
1 × 2,048 89.2 56.7 1.57x 96.5 59.6 1.62x
4 × 2,048 162.7 121.1 1.34x 184.4 126.9 1.45x
16 × 2,048 416.0 387.7 1.07x 490.2 409.1 1.20x
1 × 4,096 115.2 73.5 1.57x 126.4 76.9 1.64x
2 × 4,096 166.4 125.3 1.33x 188.5 130.3 1.45x
4 × 4,096 275.6 222.0 1.24x 315.3 226.6 1.39x
8 × 4,096 431.1 406.5 1.06x 502.1 484.8 1.04x
1 × 8,192 172.4 125.7 1.37x 195.5 136.7 1.43x
2 × 8,192 284.6 226.0 1.26x 322.1 233.1 1.38x
4 × 8,192 511.1 426.5 1.20x 584.3 444.1 1.32x
1 × 16,384 291.4 227.4 1.28x 327.8 234.7 1.40x
2 × 16,384 514.9 433.9 1.19x 584.5 449.2 1.30x
1 × 32,768 523.0 440.2 1.19x 593.3 455.7 1.30x
9,170 + 7,168 (one continues a cached prefix) 287.9 229.7 1.25x 326.8 232.8 1.40x
2,370 + 11,585 + 2,368 (busy step) 382.2 232.7 1.64x 411.4 233.6 1.76x

Performance 1250

gfx1250, H = 12 and 24, K = V = 128, bf16. µs per call (CUDA-graph replay, best of two runs). Main is FlashKDA on main (31f72a408). Main + norm runs FlashKDA followed by a separate torch gated RMSNorm.

Case (H: tokens) Main This PR Speed-up Main + norm This PR + norm Speed-up
12: 3072 50.7 46.2 1.10x 144.1 51.1 2.82x
12: 3x1112 37.9 36.6 1.04x 140.9 50.9 2.77x
12: 8192 80.3 79.1 1.02x 221.0 89.7 2.46x
12: 13295+3072 120.2 114.5 1.05x 321.5 125.0 2.57x
12: 16384 123.7 115.6 1.07x 322.7 133.5 2.42x
12: 30848+15x128 654.0 203.1 3.22x 1016.2 222.2 4.57x
12: 32768 208.1 182.6 1.14x 573.9 209.2 2.74x
12: 65536 381.9 318.6 1.20x 1097.6 385.5 2.85x
24: 3072 66.1 65.8 1.00x 191.6 70.0 2.74x
24: 8192 117.3 108.7 1.08x 317.3 120.9 2.62x
24: 13295+3072 215.3 175.5 1.23x 584.6 200.9 2.91x
24: 16384 219.1 176.1 1.24x 587.9 205.9 2.86x
24: 30848+15x128 758.8 370.0 2.05x 1446.6 405.0 3.57x
24: 32768 378.2 326.7 1.16x 1098.4 340.1 3.23x
24: 65536 749.0 604.1 1.24x 2144.6 722.0 2.97x

…pass C, copier-wave walk

Speed up the gfx950 Gluon FlashKDA prefill (chunk_kimi_delta_attn) and fuse
vLLM's output gated RMSNorm into it (optional out_gate / norm_weight /
norm_eps arguments; the old API is unchanged).

- K1: rewritten workspace (diag(beta) folded into the fp16 inverse, perm32
  operand order, 16 B stores), so K2 needs no beta.
- Pass A: fp8 A_seg and bf16 b_seg for the scan; XCD-aware row pairing.
- Scan + segmented pass C in one launch, with per-XCD scan replicas and
  epoch-tagged flags, and a tapered segment plan for long sequences.
- Unsegmented pass C with the norm: copier-wave walk (4 waves copy and
  normalize, 4 run the recurrence), partner row partials exchanged per chunk.
- Epochs live on the device (advanced by K1), so CUDA graph replays are safe.
- Plan values in the gfx950 Gluon DEFAULT.json (flash_kda_gluon_plan).
- Tests: CUDA graph replay vs eager; routes-agree bound for the gfx950 pair.
… step

With more blocks than CUs the planner never segmented, so in a chunked-prefill
step (one long sequence plus many short ones) the long sequence walked all its
chunks serially (30848 + 15x128 tokens: 1.8 ms). On the gfx950 Gluon pipeline,
split it when its walk outlasts the device's share of all the work. Uniform
batches keep their plan.
- Pass C computes each checkpoint's segment and chunk from the device
  offsets, rows and sequence starts: no .tolist() or host-built tensors.
- checkpoint_state / offsets / indices skip input_guard, so a padded vLLM
  state cache is written in place instead of a throwaway contiguous copy.
- Plan tables upload from pinned memory without blocking.
- The gfx950 Gluon K1 reads beta at its token stride (no packed copy).
- A strided out_gate that is not 16 B aligned is packed instead of failing
  to compile.
- Tests: padded vLLM cache as the checkpoint destination; strided beta.
- Optional cu_seqlens_cpu: sequence bounds, chunk indices and the K1 tile
  table come from the CPU copy (read via data_ptr), cached by value and
  uploaded pinned and non-blocking; prepare_chunk_indices and _seq_bounds
  are skipped.
- _build_segments uploads without blocking and returns its rows pre-split.
- gfx950 Gluon workspaces are persistent per stream, with cached views.
- The norm weight is cast to fp32 in the kernel; dtype conversions only run
  when the dtype differs.
- warmup_chunk_kimi_delta_attn compiles the variants a serving run reaches.
- Tests: cu_seqlens_cpu matches the device plan and does not sync; warmup.
omuhamma added a commit to omuhamma/vllm that referenced this pull request Nov 17, 2026
The ROCm Kimi-K3 KDA `gluon` prefill backend now calls AITER's FlashKDA
(chunk_kimi_delta_attn) instead of AITER chunk_kda. Selection is unchanged:
`auto` picks gluon when AITER is on, the GPU is CDNA4, the recurrent state is
fp32 and the gate is bounded.

- gluon writes the mid-prefill KDA checkpoints itself, so checkpoint steps no
  longer fall back to the fused HIP kernel.
- The GDN metadata keeps the host copy of the prefill cu_seqlens and passes
  it as cu_seqlens_cpu, so FlashKDA plans without a device read-back.
- The Kimi-K3 ROCm metadata builder converts checkpoint rows from
  NULL_BLOCK_ID to -1 once per step instead of in every layer.
- The gated o_norm is fused into FlashKDA when the prefill rows are one
  contiguous run (no spec-decode tokens interleaved).

Needs an AITER build with FlashKDA cu_seqlens_cpu support (ROCm/aiter#8043);
without it the gluon backend reports unavailable.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Omar Muhammad <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@omuhamma
omuhamma marked this pull request as ready for review November 20, 2026 20:16
@omuhamma
omuhamma requested a review from a team November 20, 2026 20:16
@aiter-bot

aiter-bot commented Nov 20, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 872cf3db73cf · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. Which exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer
  • FAIL — changed op test not explained in Changed op tests: op_tests/triton_tests/kimi_delta_attn/test_fast_launch.py
  • FAIL — changed op test not explained in Changed op tests: op_tests/triton_tests/kimi_delta_attn/test_flash_kda.py
  • FAIL — Changed op tests must explain why each changed op test is necessary and non-redundant

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

* [Triton/Gluon] [gfx1250] FlashKDA: fused gated RMSNorm, prefill checkpoints, faster K1 and segment plan

- Pass C: fused gated RMSNorm (out_gate, norm_weight, norm_eps) and prefill
  checkpoints, as on gfx950.
- K1: chunk-matrix inverse as four 16x16 tiles, exp2 on two tiles instead of
  four, seven waves per SIMD.
- Pass A skips each sequence's last segment.
- Segment planner: one-wave fit, packed pass C (two workgroups per CU) from
  64 chunks, square-root floor on the segment length; tuning in DEFAULT.json.

* FlashKDA tests: checkpoint refusal checked on the Triton route on every arch; ruff fixes
- Unused unpacked variables prefixed with _ (RUF059).
- dict() call written as a literal (C408).
- The K2 if NORM keeps its nesting inside the Gluon kernel (noqa SIM102),
  like if STORE_FINAL.
- f-string in _vmwait (UP031).
@omuhamma omuhamma changed the title [Triton/Gluon] [gfx950] FlashKDA updates [Triton/Gluon] [gfx950/1250] FlashKDA updates Nov 20, 2026
@Boss2002n
Boss2002n requested a balanced review from Copilot November 20, 2026 22:33

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

Unresolved critical findings can cause out-of-bounds reads, incorrect sequence and gate results, and unsafe cache reuse across streams and graph captures.

11 open issues
What changed in this PR

This PR updates Aiter’s FlashKDA prefill path for gfx950 and gfx1250 to reduce kernel launches and memory traffic. It adds optional serving features while preserving existing call signatures.

Changes:

  • Adds fused gated RMSNorm, prefill checkpoints, CPU-based sequence planning, and a warmup helper.
  • Revises Gluon preparation, recurrence, and scan kernels, with architecture-specific scheduling.
  • Extends tests for graph replay, checkpoints, strided inputs, host planning, and warmup.
File Description
op_tests/​triton_tests/​kimi_delta_attn/​test_flash_kda.py Adds feature and replay tests; updates route expectations.
aiter/​ops/​triton/​kimi_delta_attn/​chunk_delta_attn.py Exposes optional arguments and the warmup helper.
aiter/​ops/​triton/​kimi_delta_attn/​__init__.py Exports the warmup helper.
aiter/​ops/​triton/​configs/​gfx950/​gluon/​attention/​chunk_delta_attn/​DEFAULT.json Updates gfx950 schedules and planning values.
aiter/​ops/​triton/​configs/​gfx1250/​gluon/​attention/​chunk_delta_attn/​DEFAULT.json Adds packed pass C and gfx1250 planning settings.
aiter/​ops/​triton/​_triton_kernels/​kimi_delta_attn/​flash_kda.py Adds planning, cached workspaces, epoch handling, and feature dispatch.
aiter/​ops/​triton/​_triton_kernels/​kimi_delta_attn/​chunk_fwd.py Forwards new options and adds fallback normalization.
aiter/​ops/​triton/​_gluon_kernels/​gfx950/​kimi_delta_attn/​flash_kda_k2.py Combines scan and recurrence; adds normalization and checkpoints.
aiter/​ops/​triton/​_gluon_kernels/​gfx950/​kimi_delta_attn/​flash_kda_k1.py Revises workspace layout, inverse preparation, and beta handling.
aiter/​ops/​triton/​_gluon_kernels/​gfx1250/​kimi_delta_attn/​flash_kda_k2.py Adds normalization and checkpoints; skips unused pass A segments.
aiter/​ops/​triton/​_gluon_kernels/​gfx1250/​kimi_delta_attn/​flash_kda_k1.py Introduces tiled inverse preparation and reuses decay factors.

Review effort: Balanced

@zufayu
zufayu requested review from a team, Dewei-Wang-sh and brunomazzottiamd November 21, 2026 11:39
@azaidy
azaidy requested review from azaidy and removed request for brunomazzottiamd November 24, 2026 14:37
@azaidy azaidy assigned azaidy and unassigned brunomazzottiamd Nov 24, 2026
Resolve the flash_kda.py conflicts: keep this branch's Gluon pipeline and use
main's _IS_GFX1250_FAMILY (gfx1250-strict) arch test. fast_launch now comes
from aiter/ops/triton/utils (main #8061), which replaces this branch's copy.
cdiv(0, L) - 1 gave a zero-length sequence a segment of L chunks starting at
TOTAL_TILES, so pass C read up to L * C rows past the K1 workspace (a GPU
memory fault with vLLM's trailing padding rows) and pass A's chunk offsets
drifted. The varlen test gains a case with trailing empty sequences.
…te tests

Build chunk indices from the per-sequence bounds (_host_tiles) instead of
prepare_chunk_indices, which numbers sequences by their first chunk and so
shifts every sequence after an empty one. Add an empty-sequence test against
the fp32 recurrence, and remove test cases that duplicate other coverage.
CUDA graph safety of the cached device state (plans, workspaces, epoch
counters and flags):
- Key cached plan tables by stream, so a stream never reads a table another
  stream is still uploading.
- Allocate cached state first created inside a capture from the persistent
  pool (graph_alloc.persistent_alloc), and keep the pinned source of a
  captured upload alive, since every replay copies from it again.
- Zero-filled epoch counters and flags created inside a capture are private
  to that graph (as capture_scoped_cache does); eager-initialized ones are
  still shared with captures.
- Keep every cached buffer a captured graph addresses alive, so a later
  workspace growth or plan-cache eviction cannot free memory the graph uses.
- Look the stream up once per call with _cuda_getCurrentRawStream instead of
  current_stream() per buffer.

Input checks:
- Require norm_weight with shape [V] on the input device when out_gate is set.
- Pack out_gate when its heads or elements are not packed, or its batch
  stride is padded; the Gluon kernels read it as packed heads.
- Build pinned host tables and the warmup cu_seqlens_cpu on the CPU
  explicitly, so a CUDA default device does not break them.

Cleanup: drop _tile_table, unreachable now that varlen always plans its
tiles on the host.

Tests: check the fused output norm against an fp32 rmsnorm reference with
random bf16 and fp32 weights and a non-default eps, on unsegmented and
segmented batches and both K2 routes; run the checkpoint tests on gfx1250
as well as gfx950.

The empty-sequence segment comment was fixed in 0dc4737.
omuhamma added a commit to ROCm/vllm that referenced this pull request Nov 30, 2026
Port of vllm-project#68085 (38a0ca6) on top of the vllm-project#64545 KDA view
split.

The ROCm Kimi-K3 KDA gluon prefill backend calls AITER's FlashKDA
(chunk_kimi_delta_attn) instead of AITER chunk_kda; gluon writes the
mid-prefill KDA checkpoints itself; the GDN metadata keeps the host
prefill cu_seqlens for FlashKDA planning; checkpoint rows are converted
from NULL_BLOCK_ID to -1 once per step; the gated o_norm is fused into
FlashKDA when the prefill rows are one contiguous run.

Conflict with vllm-project#64545 (kda.py, chunk_kda_prefill call): vllm-project#64545 writes the
prefill output at core_attn_out[:, non_spec_start + nd_tok:] so batches
with leading spec tokens stay direct; vllm-project#68085 drops the forced 'fused'
backend for checkpoints and fuses o_norm over core_attn_out[:, nd_tok:].
Both are kept: the prefill run starts at num_unfused = non_spec_start +
nd_tok, FlashKDA norms that run, and the leading spec tokens plus peeled
decodes ([:num_unfused]) are normed after the merge.

Needs an AITER build with FlashKDA cu_seqlens_cpu support (ROCm/aiter#8043);
without it the gluon backend reports unavailable.

Signed-off-by: omuhamma <[email protected]>
omuhamma and others added 2 commits November 30, 2026 16:53
Triton 3.9.0 (the version install_triton.sh pins for CI) renamed
shared_memory_descriptor._reinterpret to reinterpret, with the same
arguments. The gfx950 Gluon pass A / pass C still called the old name, so
they failed to compile and every flash_kda test on the gfx950 Gluon path
failed (and test_fast_launch / test_chunk_kda through it).

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

LGTM!

@azaidy
azaidy merged commit 85f4f66 into main Dec 1, 2026
65 of 67 checks passed
@azaidy
azaidy deleted the omuhamma/flash-kda-950 branch December 1, 2026 14:05
@zhanglx13

Copy link
Copy Markdown
Contributor

@omuhamma On gfx950 CI, the graph-capture tests of test_flash_kda.py fail. They failed on this PR before the merge, and they fail on main now:

The first failure is test_cuda_graph_replay_matches_eager[lens0-False]:

op_tests/triton_tests/kimi_delta_attn/test_flash_kda.py:1149          (in torch.cuda.graph(graph))
aiter/ops/triton/_triton_kernels/kimi_delta_attn/flash_kda.py:2087    in flash_kda_fwd
aiter/ops/triton/_triton_kernels/kimi_delta_attn/flash_kda.py:1279    in _scf_table
aiter/ops/triton/_triton_kernels/kimi_delta_attn/flash_kda.py:1186    in _upload
    src = torch.tensor(rows, dtype=dtype, device="cpu", pin_memory=True)
torch.AcceleratorError: HIP error: operation not permitted when stream is capturing
(hipErrorStreamCaptureUnsupported)

_upload makes a pinned host tensor while the stream captures, and the CI image (ROCm 7.2.4, torch 2.10) does not permit this. After this error, the stream stays in capture mode, so the next tests in the same pytest process also fail. In each run above, the first failed test is this one, and 18 tests of test_flash_kda.py fail. Then the tests that come after it in the shard fail:

Thus other PRs get failures in tests that they do not change.

On ROCm 10.2 (nightly) with torch 2.12, I did not see the failure: test_flash_kda.py and then test_compile_gemm_a16w16.py pass (108 passed). Thus possibly only some ROCm or torch versions reject the pinned allocation during capture.

Can you make the pinned host tensor before the capture starts (for example, in the warm-up call), or skip these tests on the CI image until a fix is available?

huizzhan pushed a commit that referenced this pull request Dec 4, 2026
Resolves the chunk_kimi_delta_attn signature and docstring conflict with #8043 by keeping both sides: main's out_gate / norm_weight / norm_eps / checkpoint_* / cu_seqlens_cpu, then bwd_backend / save_fwd.

main's entry point was forward-only; with the backward here, the fused output norm and the prefill checkpoints join out / state_cache as inference-only arguments, rejected when an input requires grad (test extended).
ganyi1996ppo added a commit to ganyi1996ppo/aiter that referenced this pull request Dec 4, 2026
Picks up FlashKDA updates (ROCm#8043); the stale merge ref failed test_flash_kda.py in Triton shard 1.

Co-Authored-By: Claude <[email protected]>
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