Skip to content

[Triton/Gluon] [gfx1250] FlashKDA updates - #8344

Merged
omuhamma merged 2 commits into
omuhamma/flash-kda-950from
omuhamma/flash-kda-1250
Nov 20, 2026
Merged

omuhamma merged 2 commits into
omuhamma/flash-kda-950from
omuhamma/flash-kda-1250

Conversation

@omuhamma

Copy link
Copy Markdown
Contributor

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.

Summary

Motivation

Changes

Performance (if applicable)

Hardware Workload/configuration Before After Change

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

PR Self-Review

Reviewed revision

Behavior and intent

Validation and unverified scope

PR-specific question

Changed op tests

…points, 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.
@omuhamma omuhamma self-assigned this Nov 20, 2026
@omuhamma
omuhamma changed the base branch from omuhamma/flash-kda-950 to main November 20, 2026 19:50
@omuhamma
omuhamma changed the base branch from main to omuhamma/flash-kda-950 November 20, 2026 19:51
@omuhamma
omuhamma marked this pull request as ready for review November 20, 2026 20:36
@omuhamma
omuhamma merged commit 8c4236f into omuhamma/flash-kda-950 Nov 20, 2026
@omuhamma
omuhamma deleted the omuhamma/flash-kda-1250 branch November 20, 2026 20:48
azaidy pushed a commit that referenced this pull request Dec 1, 2026
* [Triton/Gluon] [gfx950] FlashKDA: fused gated RMSNorm, merged scan + 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.

* [Triton/Gluon] [gfx950] FlashKDA: split a dominant sequence in a busy 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.

* checkpoints for vllm

* checkpoints for vllm: no host syncs or copies

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

* FlashKDA: plan from cu_seqlens_cpu, no per-call torch ops

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

* Apply suggestion from @github-actions[bot]

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* [Triton/Gluon] [gfx1250] FlashKDA updates (#8344)

* [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

* FlashKDA: ruff 0.16 and black 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).

* FlashKDA: plan an empty varlen sequence as one zero-chunk segment

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.

* FlashKDA: fix NaN with empty varlen sequences mid-batch, drop duplicate 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.

* FlashKDA: address Copilot review comments

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.

* FlashKDA gfx950 K2: use shared_memory_descriptor.reinterpret

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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant