Skip to content

[FlyDSL] [Perf] pa_decode: gfx950 MXFP4 KV — MTP, large groups, pages 16/64, sinks/windows, head_dim 64-512, and faster decode - #8000

Open
zhiding512 wants to merge 4 commits into
mainfrom
zhiding512/pa-fp4-gfx950-mxfp4
Open

zhiding512 wants to merge 4 commits into
mainfrom
zhiding512/pa-fp4-gfx950-mxfp4

Conversation

@zhiding512

@zhiding512 zhiding512 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Brings the gfx950 MXFP4 KV path of the shared FlyDSL PA decode tile kernel to the shapes the FP8 KV path takes, and makes it faster. The change has three commits, and each one passes the full op test on its own. A fourth commit only applies ruff fixes.

  1. Coverage: MTP, up to 64 query heads per KV head, 16- and 64-token pages, sinks, sliding windows, head_dim 64/256, and a plan-free split.
  2. Performance: scheduling, K/V streaming and the reducer.
  3. Remaining limits: any query_length, groups past 64, tasks past 4096 pages, head_dim 384/512, and a cap on O registers per CTA.

On MI355X, the 81 MXFP4 shapes main supports run at 0.548x of main's time (geomean). Shapes that main refused now run.

Motivation

The MXFP4 path from #7056 took one query position, at most 16 query heads per KV head, 128-token pages and head_dim 128, with no sinks or windows. Any other shape raised NotImplementedError, so MTP, GQA groups above 16, sinks and windows could not use MXFP4 KV.

Without a work plan it ran one CTA per (sequence, KV head). At b1 with 32K context, one CU walked the whole context: 120 us, against 7.9 us after this PR.

Changes

Coverage (commit 1):

  • MTP, query_length 1..4. Up to four 16-row M-tiles per CTA share the tile's K registers and one bf16 widening of V. Past four, query positions split over CTAs.
  • Two MTP mask fixes. The score mask now also covers the tile before a sequence's last one. The direct-output zero fill of an empty sequence now covers all of its query rows.
  • 1..64 query heads per KV head.
  • Pages of 16 and 64 tokens. Each wave reads its own page ids.
  • Sinks are applied in the shared reducer.
  • Sliding windows mask each query row's left edge.
  • head_dim 64 and 256. head_dim 128 compiles to the same ISA as before.
  • Plan-free split. When CUs would sit idle, a sequence's tiles split over CTAs and the ps reducer merges them.
  • PV runs in 16x16x32 BF16 MFMAs.
  • The MXFP4 reducer opts into kernarg preload through a new kernarg_preload key (gfx950 only).
  • 16 B LDS row pad in the epilogue, which removes a bank conflict.

Performance (commit 2):

  • Tile kernel (MXFP4):
    • Padded query rows are prefetched.
    • Head dims up to 128 peel the first tile.
    • Max reductions use a v_max3 tree.
    • head_dim 256 widens V one K block at a time when that lets two CTAs share a CU.
  • One-slot plans (capacity == batch) write final rows from the tile kernel and skip the reducer launch. Sinks fold into those rows.
  • Non-temporal 128-bit K/V loads are used when independent streams fill the CUs. The last tile is peeled on those paths.
  • MTP and large groups:
    • Query positions split only when CUs would otherwise sit idle.
    • Past two M-tiles, the query positions or the query heads split further.
    • The split CTAs of a task take block ids one XCD apart, so the second K/V read hits L2.
  • Tasks shorter than six tiles keep one tile group. Compact plans use eight 32-token waves.
  • Planner (gfx950, every KV dtype):
    • Single-query, single-KV-head default plans take one slot per CU when tasks are short.
    • Default-budget windows of at most two tiles get one slot per sequence.
    • When plan slots stay empty, CTA ids map with the KV head fastest.
  • Reducer (gfx950, every KV dtype):
    • Dual rungs issue the statistics loads and all logits loads together.
    • Partition groups fill the CTA whatever the average partition count.
  • Block-id mapping moves into pa_decode/context.py (logical_block, logical_slots, logical_kv_heads). This includes gfx942's split-major grid from [FlyDSL] [Perf] pa_decode: gfx942 schedule tuning (K/V streaming, latency hiding, grid-size policies) #7709, with unchanged behavior.

Remaining limits (commit 3):

  • Any query_length. Splits need not divide it.
  • Groups of more than 64 query heads run as equal sets of at most 64 through the KV-head split. A prime group above 64 is still refused.
  • Tasks of more than 4096 pages: the first 4096 page ids are staged, and later tiles read the block table.
  • head_dim 384 and 512. V is widened, and PV run, one K block at a time when staging does not fit in LDS.
  • A CTA takes only as many M-tiles as keep O within 128 VGPRs, and two CTAs share a CU only while O stays within 64 VGPRs. This removes the head_dim 256 spills. On head_dim 256: G64 -34%, MTP4 G16 -50%.

Unchanged: FP8 and BF16 KV kernels, gfx942 and gfx1250. On gfx950, FP8/BF16 KV also go through the planner and reducer changes above.

Performance (if applicable)

Setup:

  • MI355X (gfx950), ROCm 7.2.4, torch 2.10, FlyDSL 0.5.0.
  • Op-level, in-process paired A/B, 20-30 pairs, cold KV, CUDA-graph timing.
  • Before = main edf58c6. The PA files are identical on the current base 95d2112.
  • Change = geomean of after/before.
Hardware Workload/configuration Before After Change
MI355X MXFP4 decode, 81 shapes main supports (plan, plan-free, one-partition) 1.0 0.548 -45% geomean
MI355X MXFP4 plan-free G16 b1, 32K / 128K context 120.1 / 468.1 us 7.9 / 11.3 us 0.066x / 0.024x
MI355X Held-out MXFP4 set (26 shapes never used for tuning): 12 main runs / 14 main refuses 1.0 / refused 0.672 / runs -33% / new
MI355X MXFP4 feature set (30 shapes: MTP, G32/64, p16/p64, sinks, windows, d64/256) refused runs new
MI355X FP8/BF16 KV control set (12 shapes) 1.0 0.982 -1.8%; no shape is >2.5% slower in all blocks

Bandwidth, from the same A/B run. It is the K+V bytes the context lengths read (packed FP4 plus E8M0 scales) divided by kernel time:

Hardware Workload/configuration Before After
MI355X 12 large MXFP4 shapes (KV >= 200 MB: b512 8K, b256 2K, b64 4K) 4.92-5.57 TB/s (median 5.34) 6.10-6.52 TB/s (median 6.32)
MI355X 81 MXFP4 shapes main supports, median 1.60 TB/s 2.86 TB/s
MI355X MXFP4 plan-free G16 b1, 32K / 128K context 0.037 / 0.038 TB/s 0.56 / 1.57 TB/s

For reference, a read-bandwidth microbenchmark on MI355X reaches 7.1-7.3 TB/s with non-temporal loads and at least 32 KB in flight per CU, and 6.0-6.3 TB/s with ordinary loads. Nominal HBM peak is 8 TB/s. The large shapes went from 67-78% to 84-92% of the non-temporal ceiling.

Per commit (full / feature / held-out sets):

  • Commit 1 vs main: full 0.600.
  • Commit 2 vs commit 1: 0.910 / 0.892 / 0.895, control 0.982.
  • Commit 3 vs commit 2: 0.9985 / 0.9994 / 1.0012. All 137 shapes are bit-exact and within ±1.4%. Commit 3 adds coverage rather than speed.

Accuracy:

  • MXFP4 output is bit-exact against the previous step, except where the reduction order changes (maxrel <= 5.2e-3).
  • FP8/BF16 shapes whose partitioning changes stay as close to an FP32 reference as main: FP8 rel-L2 ~2.7e-2 on both, BF16 ~2.85e-3 on both.

Testing

  • Unit tests added or updated: op_tests/test_flydsl_pa_decode.py. MI355X: 804 passed / 34 skipped (main: 427 / 38).
  • Performance benchmarks run (above).
  • Tested on MI250X
  • Tested on MI300-class (MI308X, gfx942): op test 441 passed / 397 skipped / 0 failed (main: 357 / 108). The new cases are gfx950-only and skip there.

Documentation

  • Docstrings updated: compile_pa_decode_tile (split_sequences, kernarg_preload).
  • 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

None. Shapes that raised NotImplementedError now run. The MXFP4 path still refuses head_dim 96, page 32 and prime groups above 64.

PR Self-Review

Reviewed revision

e0b7696

Behavior and intent

On gfx950, pa_decode with MXFP4 KV now accepts these shapes, which used to raise NotImplementedError:

  • MTP and any query_length.
  • Query-head groups past 16.
  • 16- and 64-token pages.
  • Sinks and sliding windows.
  • head_dim 64/256/384/512.
  • Tasks past 4096 pages.

It also runs faster on the shapes it already took. The planner and reducer changes also apply to FP8/BF16 KV on gfx950. Planner output on gfx942 is unchanged: the one-slot window rule is gated to gfx950, and test_pa_decode_plan_short_window checks that.

Validation and unverified scope

Commands:

  • python -m pytest op_tests/test_flydsl_pa_decode.py on MI355X (gfx950) and MI308X (gfx942). Results are in Testing.
  • FP32-reference accuracy (uniform, varied and peaked inputs) on the accuracy, feature and held-out sets: within limits.
  • Graph-replay stress, 2000 replays with the output reset to NaN: 0 mismatches.
  • Paired op-level A/B with an in-process harness (not part of this PR). Results are in Performance.

The performance, accuracy and gfx942 runs used the same three patches on base edf58c6. The rebase onto 95d2112 touches none of the changed files (git range-diff shows the patches identical).

A fourth commit applies the ruff 0.16 fixes CI asked for: import order, one merged if, and parenthesized string concatenations. It changes no behavior. On head e0b7696, MI355X runs 804 passed / 34 skipped.

Not verified:

  • MI250X.
  • gfx1250. Its paths are not changed.
  • End-to-end model serving. Testing was op-level only.

PR-specific question

What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?

  • New MXFP4 shape cases: MTP/any query_length, G17..64 and past 64, pages 16/64, sinks, windows, head_dim 64/256/384/512, and tasks past 4096 pages. Before this PR, pa_decode raised NotImplementedError on every one of them.
  • MTP with an empty sequence and with a short last tile: these cases fail on the two mask bugs fixed in commit 1. They are the score mask on the tile before the last one, and the zero fill that covered only the first query row.
  • Plan-free split, one-slot plan and graph-replay cases: these cases fail if a split's partials are dropped or merged twice, or if the one-slot path skips the reducer without writing final rows. A wrong split count preloaded for graph replay also fails them.
  • NaN/Inf rows in unowned KV at every page size: these cases fail if a 16/64-token page wave reads a page the sequence does not own.
  • test_pa_decode_plan_short_window: on gfx950 it fails without the one-slot window rule. On gfx942 it checks that the plan is unchanged.

op_tests/test_flydsl_pa_decode.py is the canonical test for this op. Before this PR, its MXFP4 cases covered only q1, G<=16, page 128 and head_dim 128. Its FP8/BF16 cases cover similar shapes but not the MXFP4 scale, unpack and V-widening path that these changes touch.

Changed op tests

op_tests/test_flydsl_pa_decode.py adds gfx950 MXFP4 cases for:

  • MTP 1..8, with and without plans, including uneven splits.
  • Groups 17..64 and past 64.
  • Pages 16/64.
  • Sinks and windows.
  • head_dim 64/256/384/512.
  • Tasks past 4096 pages.
  • Plan-free split, one-slot plans, empty rows and graph replay.
  • NaN/Inf rows in unowned KV at every page size.
  • Refusal of unsupported shapes.

None of these shapes had MXFP4 coverage before, because the path refused them. The planner test test_pa_decode_plan_short_window now expects the one-slot window plan only on gfx950.

Overlap: #7701 and #7864 touch the same gfx950 reducer and streaming code. Whichever lands second needs a rebase. #7923 adds MXFP4 K/V on gfx1250 in the same kernel family.

zhiding512 and others added 3 commits November 16, 2026 01:21
…4, sinks, sliding windows, head_dim 64/256

Until now the MXFP4 KV path in the shared PA tile kernel (#7056) took one
query position, at most 16 query heads per KV head, 128-token pages,
head_dim 128, no sinks and no sliding window. Without a work plan it ran
one CTA per (sequence, KV head). This change widens what it accepts and
fixes the plan-free grid. FP8 and BF16 KV are unchanged.

Coverage:
- MTP, query_length 1..4. Query rows take up to four 16-row M-tiles a CTA.
  Each M-tile's QK reuses the tile's K registers and the one bf16 widening
  of V. Past that, query positions split over CTAs (grid y = KV heads x
  splits). Two kernel fixes for MTP: the score mask also covers the tile
  before a sequence's last one, and the direct-output zero fill of an
  empty sequence covers all of its query rows.
- 1..64 query heads per KV head. Rows past the group are padded in the
  last M-tile.
- Pages of 16 and 64 tokens, besides 128. Each wave reads its own page ids
  from the staged window, or from the block table past it.
- Attention sinks, applied in the shared reducer, and sliding windows.
  The window masks each query row's left edge and zeroes the widened V
  of tokens before the MTP window union. Plan-free tasks start at the
  window's first tile.
- head_dim 64, 128 and 256. QK runs one scaled MFMA per 128-element K
  block. head_dim 64 pads its one block with zero K and a 1.0 scale.
  head_dim 128 compiles to the same ISA as before.

Performance (MXFP4 only):
- Plan-free decode splits each sequence's tiles over CTAs when at most
  half of the CUs would otherwise hold one CTA per (sequence, KV head).
  The split count is preloaded, and the shared ps reducer merges the
  splits. On MI355X b1/32k context: 120 us -> 9 us.
- Reducer partitions are bounded by block-table tiles instead of the CU
  count.
- PV uses 16x16x32 BF16 MFMAs (two 16-token chunks each).
- The MXFP4 reducer opts into kernarg preload.
- The epilogue's f32 O rows in LDS get a 16 B pad, which removes a bank
  conflict.

Tests: op_tests/test_flydsl_pa_decode.py gains MTP, G17..64, pages 16/64,
sinks, windows, head_dim 64/256, plan-free split and graph-replay cases,
plus NaN/Inf rows in unowned KV at every page size. Unsupported shapes
(head_dim 96, G65, page 32) are refused.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… reducer

Performance work on the gfx950 PA decode. Most of it applies only to MXFP4
KV. Four changes also reach FP8/BF16 KV on gfx950: the planner, KV-head
dispatch order and both reducer changes. gfx942 and gfx1250 are unchanged.

Tile kernel (MXFP4):
- Padded query rows are prefetched ahead of the K/V burst.
- Head dims up to 128 peel the task's first tile instead of its last, so
  the first tile starts with no history to rescale. Splat operands of the
  packed f32 ops get a defined high half, so vmcnt waits no longer track
  them. Max reductions use a balanced v_max3 tree.
- head_dim 256 widens V one 128-dim K block at a time when that lets two
  CTAs share a CU.
- One-slot plans (capacity == batch) write final rows from the tile kernel
  and skip the reducer launch. Tasks of a sequence that took freed slots
  merge in the last-arriving CTA.
- Sinks fold into the final rows wherever the tile kernel writes them.
- 128-bit non-temporal K/V loads are used when independent sequence/head
  streams fill the CUs, or half of them for unsplit tasks. The last tile
  is peeled on those paths.
- MTP: query positions split only for idle CUs. Past two M-tiles (276
  VGPRs, one wave per SIMD) the query positions, or else a KV head's
  query heads, split further. The split CTAs of a task take block ids one
  XCD count apart, so the second K/V read hits L2.
- Tasks shorter than six tiles keep one tile group.
- Compact plans of at most two tiles per task use eight 32-token waves.

Planner and grid (gfx950, every KV dtype):
- Single-query, single-KV-head plans with the default budget take one slot
  per CU when the per-task tile bound stays within twice the full plan's.
- When a plan leaves slots empty, CTA ids map with the KV head fastest.
- Sliding-window plans whose window union touches at most two tiles get one
  slot per sequence.

Reducer (gfx950, every KV dtype):
- Dual-reducer rungs issue the statistics and all logits loads together,
  with no wait per ladder level.
- Partition groups fill the CTA whatever the average partition count.

The grid mapping lives in pa_decode.context (logical_block, logical_slots,
logical_kv_heads). It covers gfx942's split-major grid (#7709) as well.

Every step was A/B'ed in-process on MI355X: paired, cold KV, 30 pairs, three
rounds plus one with the candidate first. MXFP4 output is bit-exact, except
the eight-wave path (maxrel <= 2.6e-3, FP32 accuracy passes).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…4, long tasks, head_dim 384/512

Removes the remaining MXFP4 shape limits that the FP8 KV path does not
have on gfx950:
- Any query_length. Splits need not divide it: each split takes
  ceil(query_length / splits) positions, and the last one starts that many
  before the end and stores only the rows past the split before it. A
  split past two M-tiles splits further when that adds no M-tile.
- More than 64 query heads per KV head. Such a group runs as equal sets of
  at most 64 query heads, each through the existing KV-head split; only
  K/V reads map back to the cache head. A group with no such split (a
  prime above 64) is still refused.
- Tasks of more than 4096 pages (page-16 tasks past 64K tokens). A task
  stages its first 4096 page ids, and its later tiles read the block table.
- head_dim 384 and 512 (multiples of 128). V is widened, and PV run, one
  K block at a time when the tile's staging does not fit in LDS.
- A CTA takes only as many M-tiles as keep O within 128 VGPRs (four up to
  head_dim 128, two at 256, one past that). Two CTAs share a CU only while
  O stays within a quarter of the 256 registers. On MI355X head_dim 256:
  G64 decode -34%, MTP4 G16 -50%.

Tests cover MTP 5..8 with and without plans, uneven splits, groups past
64, tasks past 4096 pages, head_dim 384/512, windows, sinks, empty rows
and graph replay.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@zhiding512
zhiding512 requested review from a team and a balanced review from Copilot November 16, 2026 01:22
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter standard tests on MI35X
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the Radeon R9700 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 8000 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@aiter-bot

aiter-bot commented Nov 16, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision e0b769600bb7 · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

On gfx950, `pa_decode` with MXFP4 KV now accepts these shapes, which used to raise NotImplementedError:
- MTP and any query_length.
- Query-head groups past 16.
- 16- and 64-token pages.
- Sinks and sliding windows.
- head_dim 64/256/384/512.
- Tasks past 4096 pages.

It also runs faster on the shapes it already took. The planner and reducer changes also apply to FP8/BF16 KV on gfx950. Planner output on gfx942 is unchanged: the one-slot window rule is gated to gfx950, and `test_pa_decode_plan_short_window` checks that.

Validation and unverified scope

Commands:
- `python -m pytest op_tests/test_flydsl_pa_decode.py` on MI355X (gfx950) and MI308X (gfx942). Results are in Testing.
- FP32-reference accuracy (uniform, varied and peaked inputs) on the accuracy, feature and held-out sets: within limits.
- Graph-replay stress, 2000 replays with the output reset to NaN: 0 mismatches.
- Paired op-level A/B with an in-process harness (not part of this PR). Results are in Performance.

The performance, accuracy and gfx942 runs used the same three patches on base edf58c6. The rebase onto 95d2112 touches none of the changed files (`git range-diff` shows the patches identical).

A fourth commit applies the ruff 0.16 fixes CI asked for: import order, one merged `if`, and parenthesized string concatenations. It changes no behavior. On head e0b769600b, MI355X runs 804 passed / 34 skipped.

Not verified:
- MI250X.
- gfx1250. Its paths are not changed.
- End-to-end model serving. Testing was op-level only.

PR-specific question

> What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?

- New MXFP4 shape cases: MTP/any query_length, G17..64 and past 64, pages 16/64, sinks, windows, head_dim 64/256/384/512, and tasks past 4096 pages. Before this PR, `pa_decode` raised NotImplementedError on every one of them.
- MTP with an empty sequence and with a short last tile: these cases fail on the two mask bugs fixed in commit 1. They are the score mask on the tile before the last one, and the zero fill that covered only the first query row.
- Plan-free split, one-slot plan and graph-replay cases: these cases fail if a split's partials are dropped or merged twice, or if the one-slot path skips the reducer without writing final rows. A wrong split count preloaded for graph replay also fails them.
- NaN/Inf rows in unowned KV at every page size: these cases fail if a 16/64-token page wave reads a page the sequence does not own.
- `test_pa_decode_plan_short_window`: on gfx950 it fails without the one-slot window rule. On gfx942 it checks that the plan is unchanged.

`op_tests/test_flydsl_pa_decode.py` is the canonical test for this op. Before this PR, its MXFP4 cases covered only q1, G<=16, page 128 and head_dim 128. Its FP8/BF16 cases cover similar shapes but not the MXFP4 scale, unpack and V-widening path that these changes touch.

Changed op tests

`op_tests/test_flydsl_pa_decode.py` adds gfx950 MXFP4 cases for:
- MTP 1..8, with and without plans, including uneven splits.
- Groups 17..64 and past 64.
- Pages 16/64.
- Sinks and windows.
- head_dim 64/256/384/512.
- Tasks past 4096 pages.
- Plan-free split, one-slot plans, empty rows and graph replay.
- NaN/Inf rows in unowned KV at every page size.
- Refusal of unsupported shapes.

None of these shapes had MXFP4 coverage before, because the path refused them. The planner test `test_pa_decode_plan_short_window` now expects the one-slot window plan only on gfx950.

Overlap: #7701 and #7864 touch the same gfx950 reducer and streaming code. Whichever lands second needs a rebase. #7923 adds MXFP4 K/V on gfx1250 in the same kernel family.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • FAIL — an active Copilot finding has no substantive reply from the PR author
  • FAIL — an active Copilot finding has no substantive reply from the PR author
  • FAIL — an active Copilot finding has no substantive reply from the PR author
  • FAIL — an active Copilot finding has no substantive reply from the PR author

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

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

…t string concat)

Sorts the imports of pipeline.py and pa_decode.py, merges the nested
planner if in traits.py, marks the const_expr/runtime if pair in the
epilogue noqa: SIM102 (as attention_a2a_intranode_kernel.py does), and
parenthesizes implicit string concatenations in the op test. No
behavior change.

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

Critical regressions break gfx1250 cluster-merge tracing and valid decode plans with absent arrival counters or zero-width block tables, while balanced-plan refreshes also perform unnecessary searches and synchronization.

4 open issues
What changed in this PR

Extends the shared FlyDSL paged-attention decode kernel’s gfx950 MXFP4 support beyond the limits introduced in #7056, while optimizing scheduling, memory loads, and partition reduction.

Changes:

  • Adds multi-token queries, larger query-head groups, pages of 16/64 tokens, sinks, sliding windows, and head dimensions through 512.
  • Adds plan-free splitting and one-slot in-kernel merging, plus gfx950 planner and reducer optimizations shared with FP8/BF16.
  • Expands tests for supported shapes, masking, empty rows, graph replay, and unsupported inputs.
File Description
op_tests/​test_flydsl_pa_decode.py Expands MXFP4 correctness and scheduling coverage.
aiter/​ops/​flydsl/​pa_decode.py Adds validation, split policies, scratch handling, and launch selection.
aiter/​ops/​flydsl/​kernels/​pa_decode/​traits.py Defines expanded shape support and resource-aware schedules.
aiter/​ops/​flydsl/​kernels/​pa_decode/​pipeline.py Extends MXFP4 computation and optimizes tile processing.
aiter/​ops/​flydsl/​kernels/​pa_decode/​op_softmax.py Adds a balanced maximum-reduction helper.
aiter/​ops/​flydsl/​kernels/​pa_decode/​op_merge.py Switches cluster merging to the shared block mapper.
aiter/​ops/​flydsl/​kernels/​pa_decode/​op_lds.py Generalizes query, page, scale, and value loading.
aiter/​ops/​flydsl/​kernels/​pa_decode/​op_gemm.py Supports multiple MXFP4 head-dimension blocks.
aiter/​ops/​flydsl/​kernels/​pa_decode/​op_epilog.py Adds sink handling and one-slot partition merging.
aiter/​ops/​flydsl/​kernels/​pa_decode/​context.py Centralizes block mapping and uneven query splits.
aiter/​ops/​flydsl/​kernels/​pa_decode_reduce.py Adds gfx950 argument preloading and load scheduling.
aiter/​ops/​flydsl/​kernels/​pa_decode_plan.py Adds compact and short-window planning policies.
aiter/​ops/​flydsl/​kernels/​pa_decode_kernel.py Wires new schedules, output modes, and launch arguments.

Review effort: Balanced

group = max(1, 128 // (t.cluster_merge * elems))
lane = fx.Int32(gpu.thread_id("x")) % t.WAVE
kv_query = fx.Int32(gpu.block_id("y"))
kv_query = logical_block(t)[1]
reduce_partitions = min(
partitions,
capacity,
-(-max_blocks_per_seq * page_size // KV_COMPUTE_BLOCK),
work_plan is not None
and not direct
and same_strides
and capacity == num_seqs
Comment on lines +175 to +178
fewer = (compact >= fx.max(rows_used, 1)).select(compact, capacity)
lo_compact = tile_bound(fewer)
merge = (lo <= 2) & (lo_compact <= 2 * lo)
lo = merge.select(lo_compact, lo)
Copilot AI balanced review requested due to automatic review settings November 16, 2026 01:32

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.

🔵 Needs a closer look

Critical regressions break gfx1250 cluster-merge tracing and cause valid counter-free or all-empty decode plans to fail.

4 open issues

Review effort: Balanced

@fsx950223
fsx950223 self-requested a review November 16, 2026 03:02
@fsx950223

Copy link
Copy Markdown
Contributor

Independent perf check on MI355X (gfx950) and MI308X (gfx942)

Revision: head e0b769600b vs base 95d2112848. FlyDSL 0.5.0, ROCm 7.2.4, torch 2.10.

The MXFP4 gains reproduce. However, three of the gfx950 planner/grid changes also apply to FP8/BF16 KV, and they regress several common shapes by up to 1.5x. The worst cases are sliding-window decode (GPT-OSS-style window 128/256), MTP, and short single-KV-head FP8 decode such as MiniMax-M3 TP4. gfx942 is neutral.

Method:

  • Both trees' pa_decode sources are imported side by side in one process and run on the same inputs.
  • Each version gets one CUDA graph; replays alternate ABBA, with 20-60 pairs.
  • Cold KV: R copies of the KV pool with offset block tables, so every call reads KV the previous calls evicted (at least 1 GB per rotation).
  • All numbers below are PR / main kernel time (the PR body's after/before convention; > 1 means the PR is slower). "x/y" means x of y 10-pair blocks agree on the sign.
  • Ablation: both sides get an explicit workgroup_budget equal to main's default budget (2·CU for q1; clamp(4·B·H, CU, 2·CU) for q>1). This leaves main's plan unchanged and turns off only this PR's two default-budget planner rules.

MXFP4: claims reproduce

  • 57 main-supported shapes, chosen independently: geomean 0.502 (planned 0.845, plan-free 0.314). None is slower.
  • Plan-free G16 b1: 32K 121.9 → 8.4 µs, 128K 469.4 → 11.9 µs.
  • 16 shapes with KV ≥ 200 MB: 4.96-5.89 → 5.48-6.76 TB/s (median 5.25 → 6.18).
  • A second, 198-shape MXFP4 grid (H 1/2/8, G 4/8/16, plan/free, hint, mp, budget, padded tables, FP8 Q): geomean 0.627, worst 1.03.

Regression 1: window rule (pa_decode_plan.py L480-L487)

The rule sets capacity = batch for default-budget windows over at most two tiles, for every KV dtype. The comment's justification only holds for MXFP4, whose one-slot plans write final rows.

On gfx950 FP8/BF16, direct_output requires num_partitions == 1 and no sinks. A window plan has num_partitions = window_tiles = 2, so the reducer still launches. The rule's only effect is that the two window tiles run serially in one CTA instead of in two CTAs.

Any window that is not 256-aligned triggers it, so real varlen batches hit it. Over 80 window shapes the geomean is 1.092; with the ablation it is 1.001, and all are bit-exact with main.

Shape (cold KV, unaligned/varlen lengths) main → PR (µs) PR/main Ablation
bf16 D64 p16 H8 G8 sinks win128 B8 ctxU 1-32K ql1 6.96 → 7.48 1.076 (4/4) 0.993
fp8 D64 p16 H8 G8 sinks win128 B8 ctxU 1-32K ql1 6.65 → 7.41 1.110 (4/4) 1.004
bf16 D64 p16 H8 G8 sinks win128 B8 ctxU 1-32K ql2 6.29 → 7.90 1.255 (4/4) 0.997
bf16 D64 p16 H8 G8 sinks win128 B8 ctxU 1-32K ql4 7.60 → 9.90 1.303 (4/4) 1.006
fp8 D64 p16 H8 G8 sinks win256 B1 ctx 4000 ql1 6.36 → 8.29 1.314 (4/4) 0.961
bf16 D64 p16 H8 G8 sinks win256 B1 ctx 4000 ql2 5.99 → 9.17 1.532 (4/4) 1.026
fp8 D128 p128 H1 G16 win128 B32 ctxU 1-32K ql1 6.25 → 7.70 1.234 (4/4) 1.013
bf16 D128 p128 H1 G16 win128 B32 ctxU 1-32K ql4 10.91 → 16.19 1.483 (4/4) 0.999
fp8 D64 p16 H8 G8 sinks win128 B64 ctxU 1-8K ql1 (capacity is already = batch) 11.11 → 11.18 1.007 1.003

Regression 2: compact rule (pa_decode_plan.py L488-L503)

The rule applies to gfx950, q1, a single KV head and the default budget, for every KV dtype. It merges two-tile tasks into one slot per CU. For FP8 KV, two CTAs per CU of the shorter tasks are faster. BF16 sees a smaller version of the same regression, except at B128 with ctx 128-2K, which improves (0.935).

These are the ~128K-256K-token totals where the rule fires:

Shape (cold KV) main → PR (µs) PR/main Ablation
MiniMax-M3 TP4 fp8 (per-token) D128 p128 G16, b32 8K 16.79 → 18.20 1.084 (6/6) 1.005
same, b4 32K 12.22 → 12.97 1.061 (6/6) 0.998
fp8 per-token D128 p16 G8 B64 2K 11.15 → 13.02 1.168 (4/4) 0.994
fp8 per-token D128 p16 G8 B4 32K 12.62 → 14.20 1.125 (4/4) 1.000
fp8 per-tensor D128 p64 G8 B32 8K 17.01 → 19.04 1.119 (4/4) 1.004
fp8 per-token varlen B64 ctxU 128-2K 9.16 → 10.06 1.100 (6/6) 1.003
bf16 D128 p64 G8 B64 2K 15.92 → 17.17 1.078 (4/4) 1.007

All ablation outputs are bit-exact with main. In a 264-shape single-KV-head q1 grid, 47 shapes are more than 2% slower and 23 are more than 5% slower. The PR body's "no FP8/BF16 shape is >2.5% slower" holds for its 12-shape control set but not beyond it.

Smaller: KV-head-fastest CTA mapping (traits.py L755-L766)

On gfx950 the FP8/BF16 tile kernels are not ISA-identical to main. For H>1, or MTP with query splits, the prologue now loads gridDim from the kernarg segment and does a ~35-instruction scalar division before the work-info load can issue.

Short calls pay for it, and the plan and output are unchanged (bit-exact, ablation-insensitive):

Shape (cold KV) main → PR (µs) PR/main
fp8 per-token D128 p128 G16 B8 ql4 4K 10.32 → 11.17 1.082 (4/4)
fp8 per-token D128 p128 G16 B1 ql4 32K 11.76 → 12.49 1.062 (4/4)
fp8 D128 p16 H8 G8 B4 2K 8.56 → 8.76 1.023 (4/4)

It does help elsewhere: bf16 H8 G8 p16 B1 2K is 10.11 → 8.19 µs (0.810). It is a trade-off rather than a pure loss. I attribute the slowdown to the prologue from the ISA diff; there is no knob to toggle the mapping, so this attribution is not confirmed by ablation.

Neutral

  • FP8/BF16 with explicit budget or max_partitions, padded tables, B512/B1024 short contexts, skewed varlen, and MTP without query splits: 0.96-1.00.
  • gfx942 (MI308X, 952 UT + grid cases, BF16 and the four FP8 variants): geomean 1.0007, all bit-exact, worst single case 1.035.
    • ISA: 109 tile kernels differ from main only in one kernarg offset (0x70 → 0x98). The plan kernel changes as expected.

Suggestions

  • Gate the window and compact rules to MXFP4. plan_pa_decode does not know the KV dtype, so one option is a kv_dtype argument. Another is to let gfx950 FP8/BF16 write final rows for capacity == batch plans, the way MXFP4 does; the window rule would then pay off for them too.
  • Limit HEADS_FASTEST to the cases where it wins, or precompute the division on the host (it divides by the grid's y dimension).
  • Widen the FP8/BF16 control set with varlen, unaligned windows and per-token FP8. Fixed-length, 256-aligned windows hide regression 1 for q1.

Not covered: gfx1250, end-to-end serving, and accuracy beyond an output comparison with main.

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

Reviewed exact head e0b7696. Three correctness regressions were independently reproduced, and existing exact-SHA performance feedback identifies substantive FP8/BF16 planner regressions. Targeted gfx942 tests passed, but gfx950 validation was unavailable because the configured login host timed out. Detailed commands and logs are preserved in validation.md.

[P1] Restore the gfx1250 cluster-merge block mapping — aiter/ops/flydsl/kernels/pa_decode/op_merge.py:286

Existing gfx1250 FP8/BF16 decodes that select cluster merging now call logical_block() with Gfx1250Traits. That type has none of the mapping fields the helper reads, starting with SPLIT_MAJOR. A minimal trace using the pinned FlyDSL 0.5.0 reproduces AttributeError before code generation. Consequently, these previously supported cluster-merge specializations cannot compile. Restore the previous y-axis lookup here, or explicitly provide a mapping compatible with Gfx1250Traits.

[P2] Require arrival counters before selecting the one-slot path — aiter/ops/flydsl/pa_decode.py:569

PADecodePlan.arrival_counters defaults to None, and validate() explicitly accepts it to retain the shared reducer. For MXFP4 with capacity equal to batch, max_partitions > 1 and matching output/query strides, this predicate nevertheless selects one_slot_plan. Pointer preparation then raises AttributeError on work_plan.arrival_counters.data_ptr(). The metadata-only reproduction fails at head and is accepted at base. Require non-null arrival counters in this predicate so valid counter-free plans use the reducer fallback.

[P2] Keep the reducer specialization bound positive for empty tables — aiter/ops/flydsl/pa_decode.py:557

A zero-width block table with zero context lengths is accepted by the input contract. For a non-direct MXFP4 planned call, such as batch 1, capacity 2 and max_partitions 2, this term makes reduce_partitions zero. compile_pa_decode_ps_reduce() then raises ValueError instead of producing zero output. The same metadata-only input is accepted at base. Clamp the specialization bound to at least one; reduce_info already records zero live partitions for the empty sequence.

[P2] Avoid applying MXFP4 planner heuristics to slower FP8/BF16 paths — aiter/ops/flydsl/kernels/pa_decode_plan.py:483

The default-budget short-window rule applies to every KV dtype, although its reducer-elimination justification holds for MXFP4. FP8/BF16 two-tile window plans still launch the reducer, so capacity=batch serializes tiles without saving that launch. Existing reviewer measurements on this exact head/base show BF16 D128, page128, H1/G16, batch32, query_length4, window128 increasing from 10.91 to 16.19 us; restoring the base budget gives a ratio of 0.999. The neighboring compact-plan rule similarly slows per-token FP8 D128/page16/G8, batch64, context2048 by 16.8%, with budget ablation restoring baseline. Gate these heuristics by KV dtype or provide equivalent final-output paths before applying them to FP8/BF16. These measurements were reviewed as existing evidence, not rerun today.

Validation:

  • PASS on local: git -C checkout rev-parse HEAD; git -C checkout merge-base 95d21128485c56fbadb37d5d158508985da5615b HEAD; git -C checkout diff --check
    HEAD matched e0b7696; merge-base matched the supplied base; diff check passed.
  • PASS on hjbog-srdc-39.amd.com / sixifang_dev: ssh -o BatchMode=yes -o ConnectTimeout=10 -o RequestTTY=no -o ControlMaster=no -o ControlPath=none hjbog-srdc-39.amd.com "docker exec -i sixifang_dev bash -s" < gfx942-tests.sh
    Exit 0: 71 passed, 106 skipped, 661 deselected. Verified gfx942, exact remote HEAD, FlyDSL 0.5.0 and intended aiter import. Selection and output are preserved in gfx942-tests.sh and gfx942-tests.log.
  • PASS on hjbog-srdc-39.amd.com / sixifang_dev: ssh -o BatchMode=yes -o ConnectTimeout=10 -o RequestTTY=no -o ControlMaster=no -o ControlPath=none hjbog-srdc-39.amd.com "docker exec -i sixifang_dev bash -s" < gfx942-regression.sh
    Exit 0: 97 passed, 54 skipped, 687 deselected. Covered short-window planning and NaN/Inf masking in unowned KV rows, including FP8/BF16 and MTP. Log: gfx942-regression.log.
  • FAIL on hjbog-srdc-39.amd.com / sixifang_dev: ssh -o BatchMode=yes -o ConnectTimeout=10 -o RequestTTY=no -o ControlMaster=no -o ControlPath=none hjbog-srdc-39.amd.com "docker exec -i sixifang_dev bash -s" < gfx942-repro.sh
    Harness exit 0 with regression exceptions caught: missing counters raised NoneType.data_ptr AttributeError; empty table raised a zero-partition ValueError; Gfx1250Traits mapping trace raised missing-SPLIT_MAJOR AttributeError. Wrapper launches were suppressed; the tracing check used a CPU argument. Log: reproduce-retry.log.
  • PASS on hjbog-srdc-39.amd.com / sixifang_dev: ssh -o BatchMode=yes -o ConnectTimeout=10 -o RequestTTY=no -o ControlMaster=no -o ControlPath=none hjbog-srdc-39.amd.com "docker exec -i sixifang_dev bash -s" < gfx942-base-repro.sh
    Exit 0: the same missing-counter and empty-table inputs were accepted by the exact base wrapper with compilation and launches suppressed. Separate source and cache; log: reproduce-base.log.
  • SKIP on dzm-mi355-gpu34-dev: ssh -o BatchMode=yes -o ConnectTimeout=10 -o RequestTTY=no -o ControlMaster=no -o ControlPath=none -o RemoteCommand=none dzm-mi355-gpu34-dev "squeue -h -u zhiming_ding_qle -o '%i|%N|%t'"
    Allocation discovery failed with exit 255: connection to aac16.amd.com:22 timed out on both attempts. No gfx950 GPU tests ran. Logs: allocation.log and allocation-retry.log.

Remaining validation:

  • gfx950 MXFP4 correctness, synchronization stress and performance could not be independently tested in this run.
  • The gfx1250 finding was verified at FlyDSL tracing time; no gfx1250 GPU or ISA validation was performed.
  • Base comparisons checked wrapper acceptance with launches suppressed, not numerical GPU output.
  • CI checks were inspected and the op's pytest dispatch was confirmed, but individual CI test logs were unavailable.
  • Existing exact-SHA performance measurements were read and traced to the changed planner rules; they were not rerun.

Automated Codex review of commit e0b769600bb7.

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

No activity for 15 days, so this is now labelled stale. A push or a comment clears it; keep-open exempts it. Nothing is closed automatically.

@github-actions github-actions Bot added the stale The PR hasn't been updated in 2 weeks label Dec 2, 2026
Arist12 added a commit to Arist12/FlyDSL that referenced this pull request Dec 3, 2026
SGLang's aiter backend decodes with page size 1 on HIP: the cache holds
one [num_kv_heads, head_dim] row per token slot and each sequence names
its slots through kv_indptr/kv_indices, so aiter calls
paged_attention_ragged.  FlyDSL has no kernel for that layout
(pa_decode_tile takes 16- or 64-token pages in the vectorized 5-D
layout), which leaves the layout without a portable fast path.

Add pa_decode_ragged_fast for the serving geometry: one query row per
sequence, BF16 K/V/output, head_dim 256, 1..16 query heads per KV head,
at most 64 sequences, and at least 16K slots per sequence on average
(kv_indices.numel() >= 16384 * num_seqs; the predicate cannot read
device lengths).  One CTA owns one (sequence, KV head, global KV split);
its four waves walk 16-token tiles and run online softmax
independently, then merge once in LDS.  QK runs as
mfma_f32_16x16x32_bf16 with tokens on M and query heads on N, so P stays
in registers for the PV MFMA; V is staged in a wave-private LDS tile,
retired with s_waitcnt lgkmcnt(0), and read back transposed with
ds_read_b64_tr_b16.  The split count comes from the device's CU count
and the batch's total slot bound.  A second kernel merges the KV splits,
with a single-launch path for small batches.

The kernel is not wired into a page-1 entry yet: this adds the kernel
and its shape/dtype/stride/device/arch acceptance predicate so a caller
(or the generalized ragged kernel) can select it.  The predicate refuses
every non-gfx950 architecture because the kernel uses the gfx950-only
ds_read_b64_tr_b16 LDS read; the entry asserts the same condition.
Other shapes are refused by the predicate, so no existing path changes.

MI350X, public API, symmetric A/B/B/A against production's aiter HIP
paged_attention_ragged, 5 rounds x 50 calls per arm, per-call CUDA
events.  Two runs of the ten production decode shapes (B = 1, 2, 4, 8
or 12 sequences, 106,960 tokens each, 8 query heads, 1 KV head,
head_dim 256) measure 1.543x and 1.560x geomean; combined over the two
runs it is 1.552x, per-shape 1.371-1.954x.  Same-arm A/A pair medians
are ~1.01 in both runs.

A generality sweep over 18 shapes (head_dim 128/256, group 8 with 1 and
2 KV heads, group 16 with 1 KV head, a group-17 refusal, Q 1/2/4,
varlen, 64/65 sequences, 1-262,144 tokens) accepts six shapes and
refuses twelve in the predicate (head_dim, Q>1, group>16, more than 64
sequences, batch-average context below 16K slots, or a non-gfx950
arch).  The six accepted shapes are 1.274x geomean faster than HIP
(0.977-1.547x); the exact-16K-gate shape is 0.977x in this run (a 2%
loss against HIP).  A mixed-length batch [65536,1,1,1] (average
16,384.75 slots/sequence) is 2.10x faster than HIP; [32768,1,1,1]
(average 8,192.75) is refused, which is conservative.

Correctness: 18 tests, including an fp64 reference on nine length sets
with planted keys and a sparse slot pool, the 4-D cache view,
non-contiguous query/output and empty-index refusals, a real 65-sequence
refusal, a monkeypatched gfx942 arch refusal, group 1/16, repeated
launches and the mixed-length gate.  max |out - ref| /
(0.01 * (|ref| + rms/2)) is 0.175-0.194 on the ten production shapes
and 0.175-0.191 on the six accepted generality shapes; all finite.
FlyDSL 0.5.5 passes 18/18.

ISA (gfx950, production shape, 0 spills): attention 206 VGPR, 36 SGPR,
45,072 B LDS; reduce 88 VGPR, 31 SGPR, 3,072 B LDS.

No new dependencies.  No open FlyDSL PR adds a page-1 ragged decode
kernel; ROCm#1448/ROCm#1452/ROCm#1056/ROCm#1505-1507 touch other
kernels/layouts, and the aiter PA decode PRs (ROCm/aiter#8000/#7864/
#7206/#8910, draft ROCm/aiter#2919) are page-16/64/128 or HIP.
Production still calls HIP today; this is an enablement change, not a
serving win.

Signed-off-by: Arist12 <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

FlyDSL stale The PR hasn't been updated in 2 weeks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants