Repository navigation
[Triton/Gluon] [gfx950/1250] FlashKDA updates - #8043
Conversation
…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.
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>
WAITING ON AUTHORPR Self-ReviewRevision 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
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
* [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).
There was a problem hiding this comment.
🟡 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
Empty segments are assigned chunks and read another sequence's workspace · New Cached device-table uploads can race across streams · New Keep graph-referenced backing allocations alive after buffer growth · New Use persistent storage for cached allocations created during capture · New Initialize capture-created counters and flags before eager use · New Validate norm weight presence, shape, and device · New Reject or pack unsupported gate strides before launching kernels · New Create pinned host-plan source tensors explicitly on the CPU · New Test norm against an independent reference with non-unit weights · New Create cu_seqlens_cpu bounds explicitly on the CPU · New Run checkpoint correctness tests on gfx1250 · New
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
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.
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]>
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).
|
@omuhamma On gfx950 CI, the graph-capture tests of
The first failure is
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: 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? |
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).
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]>


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
out_gate,norm_weight,norm_eps):rmsnorm(o) * norm_weight * sigmoid(out_gate)in pass C, weight cast to fp32 in the kernel.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.gfx950
diag(beta)folded into the fp16 inverse, perm32 operand order with 16 B stores; K2 no longer readsbeta.A_seg/ bf16b_segfor the scan, XCD-aware row pairing.DEFAULT.json, andwarmup_chunk_kimi_delta_attnto precompile the variants.gfx1250
MIN_CHUNKS64 so the Triton and Gluon routes agree; square-root floor on the segment length. Plan values in the gfx1250 GluonDEFAULT.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 Tritonrms_norm_gated, sigmoid gate); after fuses it into FlashKDA (out_gate,norm_weight,norm_eps).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.