Skip to content

[FlyDSL] gfx1250 PA decode: wider page-local softmax steps, shared clusters and wave-pair MTP4 for MiniMax-M3 - #7619

Merged
coderfeli merged 38 commits into
mainfrom
zhiding512/pa-decode-opt
Nov 13, 2026
Merged

coderfeli merged 38 commits into
mainfrom
zhiding512/pa-decode-opt

Conversation

@zhiding512

@zhiding512 zhiding512 commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #7079 on gfx1250 PA decode, tuned on MiniMax-M3 attention shapes (H16/KV1/D128). This replaces #7579 (same commits, reopened from the author's account).

On gfx1250, every MiniMax-M3 sparse attention call (decode, MTP verify, prefill) runs FlyDSL pa_decode (pa_fwd_asm does not support gfx1250), and dense layers use it with ATOM_PA_FLYDSL=1. The PR has three parts.

Wider softmax steps, kept page-local

A single query tile's step exchanges maxima, sums and P through LDS behind three CTA barriers, so short and sparse tasks spend much of their time on that exchange. Steps now cover more tokens where the grid allows it; compile_pa_decode_tile chooses the width from the grid size it already receives.

  • FP8 page16 (sparse decode, verify, small prefill grids): 128-token steps, two pages per wave, kept page-major in LDS.
  • FP8 page128 (dense decode, one query tile): two-page steps on grids with at most one CTA per CU, or two per CU with about three or more tiles per CTA.
  • Both FP8 two-page steps stay page-local. Each half (waves 0–1, waves 2–3) quantizes its P against its own softmax maximum and V factor and runs its own PV. The halves combine in FP32 with weights exp2(m_h - m) * f_h / F, where F is the factor of the largest weighted factor among the two halves and the history (corr times its factor), so no coefficient exceeds one from step to step.
  • BF16 page16: 128-token steps on grids with at most two CTAs per CU, 256-token steps with at most one (except step-split clusters, below). BF16 page128: two-page steps with at most one CTA per CU.
  • FP8 page16 grids above four CTAs per CU (large sparse prefill) keep 64-token steps.

Merges and grids

  • Plans with a partition bound in (16, 32] merge in a 16-CTA cluster that splits each sequence's tiles over its CTAs, instead of launching the reducer.
  • Batches with more than 240 split sequences per KV head share each cluster between 2, 4, … sequences. MiniMax-M3 sparse decode at 256 rows now runs one kernel, bit-identical to the reducer.
  • Cluster grids derive each CTA's tiles from context_lengths, read alongside reduce_info, instead of chaining reduce_info → work record → block table.
  • One-partition direct-output grids launch sequences longest-first. In grid order, sparse prefill's full-length rows formed the last wave.
  • Page16 D128 decode clusters of P CTAs over block tables of at most 16 128-token steps (MiniMax-M3's 2048 top-k tokens) give CTA p steps [p·16/P, (p+1)·16/P). For full rows these are the planner's tiles. The CTA's first page ids then depend on no load, so they are fetched together with the context length rather than after it. That removes one dependent round trip from every sparse decode CTA, and reduce_info is no longer read. Each preloaded id goes through readfirstlane, and a sched_barrier follows the preloads: only the active branch reads the ids, and the compiler had otherwise sunk or scheduled their loads after the length's wait (ATT showed the round trip still there).
  • Batches of at most one 16-CTA cluster per CU (sparse decode and MTP verify at up to 16 rows) use 16 such CTAs per row whatever the partition cap, so each CTA covers a single step. gfx1250 plans for such batches reserve 16 slots per sequence, so scratch sized from plan.capacity fits. Both step-split forms need tiles that take 128-token steps: two query tiles, plain BF16 V and grids beyond two (BF16) or four (FP8) CTAs per CU keep plan-derived clusters.
  • Page128 clusters under a max_context_length bound of at most four 256-token tiles per CTA (dense decode up to 16K at P = 16) take fixed runs too: CTA p takes tiles [p·run, (p+1)·run), where the host sizes run from the bound and passes it as a kernel argument. Their first page ids load with the context length (FP8 and BF16; a sched_barrier keeps the scalar loads ahead of the length's wait). Rows at the bound split exactly as the planner splits them, so outputs on MiniMax-M3 dense shapes are bit-identical; shorter rows use fewer CTAs. ATT, FP8 dense bs1 8K: first KV copy issues at cycle 2211 instead of 2564.
  • The cluster merge issues its partial loads back to back. The compiler had rebuilt each load's base address in one SGPR pair (the tile kernel runs at its full SGPR budget), so each load waited for the previous one to read it, about 900 cycles at 16 partials.

Pipelines

  • FP8 MTP4 page128 verify runs its four query tiles in wave pairs. Each wave covers half of every page for two tiles, so every K or V operand feeds two WMMAs (K128 QK, K64 PV) and LDS reads halve. A pair merges its two online-softmax states once.
  • Q global loads are issued before the first page's block-table lookup: FP8 paths with head_dim ≤ 256, and the BF16 wave-pair path.
  • On grids with at most one CTA per CU, page16 steps issue the second stage in the prologue, so two-step sparse tasks overlap both copies.
  • The per-step planner kernel preloads its arguments, like the tile and reducer kernels. A plan refresh at 64 rows drops from 4.03 to 3.64 µs, and at 1024 rows from 6.75 to 6.35 µs.

Performance

Measured on gfx1250 (256 CUs) on one GPU, base zhiding512/pa_benchmark (6752572). Base and head runs alternate, and each case reports the minimum of two runs of the median of three rounds. Each round takes the minimum of five 10-call CUDA graphs with 5 replays.

  • Sparse rows use ATOM's MiniMax-M3 plans: a get_recommended_splits(rows, 1) cap, 2048 top-k tokens, a page16 pool of 4096 pages, and max_context_length=2048. FP8 caches use per-token scales.
  • Dense rows use page128 caches, the default cap and max_context_length = max(lengths).

The table is at 8d0ba96. 54dbb59 then adds the sched_barrier to step-split clusters of fewer than 16 CTAs: FP8 sparse decode at 4, 64 and 128 rows gains a further 2.4–4.5%, BF16 at 64 rows 2.1% (interleaved A/B, bit-identical). The #7619 review fixes (5474b27, 1a039b2) measure neutral: geomean 0.9995× over the 84-point MiniMax-M3 matrix against 54dbb59. After merging main (FlyDSL 0.5.0), e1eb72f against main e9efac0 on the same harness (3 interleaved runs per side): geomean 1.13× over the table's 34 cases (FP8 dense 1.13×, FP8 sparse 1.26×, BF16 dense 1.03×, BF16 sparse 1.14×) and over all 84 points, with 67 points faster and one slower (BF16 dense decode bs1 8K, 0.6%). Main itself times faster than the table's base (FP8 dense decode bs1 8K: 5.20 µs against 7.20 µs), so the margins are smaller than in the table. The two-page history fix (385386d) measures neutral against 1816c76: geomean 0.999× over the 84 points, with ATOM-style FP8 sparse decode at 128 rows 2.6% slower.

Case base (µs) 8d0ba96 (µs) Speedup
FP8 dense decode bs1 8K 7.20 5.38 1.34×
FP8 dense decode bs4 8K 7.54 5.58 1.35×
FP8 dense decode bs8 8K 8.31 6.13 1.36×
FP8 dense decode bs32 8K 11.03 8.67 1.27×
FP8 dense decode bs4 32K 9.61 9.47 1.01×
FP8 dense decode bs3 214K 20.96 19.05 1.10×
FP8 dense verify bs3×4 8K 10.26 7.84 1.31×
FP8 dense verify bs3×4 32K 12.46 10.79 1.15×
FP8 dense verify bs8×4 32K 15.54 13.66 1.14×
FP8 dense verify bs3×4 214K 29.51 26.96 1.09×
FP8 sparse decode 4 rows 7.05 4.29 1.64×
FP8 sparse decode 64 rows 8.06 6.82 1.18×
FP8 sparse decode 128 rows 10.78 8.60 1.25×
FP8 sparse decode 256 rows 17.26 12.43 1.39×
FP8 sparse verify 12 rows 7.16 4.57 1.57×
FP8 sparse prefill 1024 rows 17.27 13.47 1.28×
FP8 sparse prefill 4096 rows 74.10 73.86 1.00×
BF16 dense decode bs1 8K 7.38 6.65 1.11×
BF16 dense decode bs4 8K 8.22 6.84 1.20×
BF16 dense decode bs8 8K 8.89 7.46 1.19×
BF16 dense decode bs32 8K 14.11 11.97 1.18×
BF16 dense decode bs4 32K 10.77 11.14 0.97×
BF16 dense decode bs3 214K 29.24 29.35 1.00×
BF16 dense verify bs3×4 8K 8.88 7.87 1.13×
BF16 dense verify bs3×4 32K 12.21 12.34 0.99×
BF16 dense verify bs8×4 32K 16.85 16.96 0.99×
BF16 dense verify bs3×4 214K 33.25 33.25 1.00×
BF16 sparse decode 4 rows 6.88 4.52 1.52×
BF16 sparse decode 64 rows 8.52 7.78 1.10×
BF16 sparse decode 128 rows 11.47 9.81 1.17×
BF16 sparse decode 256 rows 18.34 13.98 1.31×
BF16 sparse verify 12 rows 7.26 4.94 1.47×
BF16 sparse prefill 1024 rows 18.22 17.64 1.03×
BF16 sparse prefill 4096 rows 107.21 101.59 1.06×
  • Geometric mean over these 34 cases: 1.190× (FP8 dense 1.207×, FP8 sparse 1.315×, BF16 dense 1.072×, BF16 sparse 1.223×).
  • Full bench_pa_decode matrix at 8d0ba96, two alternating runs per side: 1.18× over 189 cases (FP8 1.20×, BF16 1.08×). The worst cases (FP8 mtp and BF16 MTP4 page128, 0.96–0.99×) sit within the base's own 3–4% run-to-run spread, and earlier back-to-back reruns timed them equal. The matrix's cluster8 and cluster16 cases grew their batches in this PR. Review later removed the harness from the PR.
  • ATOM-style dense calls (no max_context_length, block tables padded to 256K tokens) always take the reducer. There, dense gains at 8d0ba96 are 1.04× overall: FP8 1.08× and BF16 1.01×.

PR Self-Review

Reviewed revision

3a0ffdc

Behavior and intent

The PR changes how gfx1250 FP8 and BF16 PA decode tile kernels schedule work (step width, wave pairing, cluster sharing and splitting, prologue order, CTA order), and how many task slots small gfx1250 decode plans reserve. Outputs are unchanged in meaning: these are scheduling changes for the same attention.

The existing behavior left time on fixed overheads. Each 64- or 128-token step paid a cross-wave softmax exchange, the four FP8 MTP4 query tiles each read the whole page from LDS, batches above 240 split sequences took a second reducer launch, prologues chained dependent loads, and long sparse-prefill rows ran last.

Two #7619 review fixes sit on top. pa_decode requests step-split clusters only for tiles that take 128-token steps; other tiles raised ValueError. The FP8 per-token pipelines carry the floored V factor through step rescaling, the half merge and the epilogue; below the 1e-20 floor of P normalization the output was 0.09–0.5× of the reference, including on one-page paths that predate this PR. e1eb72f merges main, which pins FlyDSL 0.5.0 and passes torch dtypes to compile_pa_decode_tile (#7388). 3a0ffdc merges main again for #7700 (gfx942/gfx950 PA decode); its one conflict was two imports added at the same line.

A third review fix (385386d) lets two-page steps keep the history's V factor. Taking the factor from the current halves alone overflowed the history coefficient to infinity when a later step's factor fell far below an earlier one while the maximum held. Review also removed the benchmark harness and the standalone tests (385386d, 8512f23, 511e69b).

Validation and unverified scope

Validated on gfx1250 (MI450, 256 CUs, PyTorch 2.11.0+rocm10.1) on one GPU.

At 3a0ffdc (511e69b merged with main b0c5c02, which adds #7700), with FlyDSL 0.5.0 (main's pin):

At 511e69b (8512f23 minus one compile test), with FlyDSL 0.5.0 (main's pin):

  • python -m pytest -q op_tests/test_flydsl_pa_decode.py: 306 passed, 159 skipped; the tests removed in review had 13 cases.
  • Black and Ruff pass on the changed files.
  • Against 1816c76, 256 of 262 FP8 and BF16 test_pa_decode cases produce byte-identical outputs. Six FP8 per-token, FP16-query page16 cases differ by one FP16 ulp, at most 1.5e-5.
  • The multi-step review case (page logits 0/80/80/80, per-token V scales 1e32/1e-16/1e-16/1e-16) gives the reference on page128 pairs and 128-token page16 steps (output/reference 1.0018); at 1816c76 every output was non-finite on both. Logits 80/80/80/80 with the same scales give 1.0014. Checked by script.
  • The 13 cases of the tests removed in review (test_pa_decode_two_page_steps_keep_page_scales, test_pa_decode_value_factor_below_floor and test_pa_decode_tile_without_context_bound) pass with the fix, run before their removal.
  • MiniMax-M3 matrix against 1816c76 (84 points, 5 interleaved runs per side): geomean 0.999×. One point is outside the run-to-run spread: ATOM-style FP8 sparse decode at 128 rows, 2.6% slower in two runs.

At 1816c76 (e1eb72f plus a test-only fix), with FlyDSL 0.5.0 (main's pin):

  • python -m pytest -q op_tests/test_flydsl_pa_decode.py: 319 passed, 159 skipped. The skipped cases are all MXFP4 or gfx950-only.
  • Black and Ruff pass on the changed files.
  • All 262 FP8 and BF16 test_pa_decode cases produce byte-identical outputs at e1eb72f and at the pre-merge head 1a039b2, both on FlyDSL 0.5.0: merging main changes no output.
  • MiniMax-M3 matrix against main e9efac0 (84 points, 3 interleaved runs per side): geomean 1.13×, with 67 points faster and one 0.6% slower (see Performance).
  • MI35X CI at e1eb72f: test_flydsl_pa_decode.py 427 passed, 50 skipped, 1 failed. The failure was bf16-cluster2-plain-v, a case this PR added: gfx942 and gfx950 reject plain BF16 V caches, and 1816c76 skips positive plain-V BF16 cases there. MI35X CI at 1816c76: 427 passed, 51 skipped.

At 1a039b2, with FlyDSL 0.4.1:

At earlier heads, with FlyDSL 0.4.1 (54dbb59: 291 passed, 159 skipped):

  • Error against an FP32 reference, on MiniMax-M3 shapes with random and e^N(0, 1) per-token magnitudes:
    • FP8 dense decode, BF16 dense and BF16 sparse: unchanged.
    • FP8 MTP4 verify (wave pairs): within 1% relative.
    • FP8 sparse decode: within 1%.
    • Step-split and fixed-run clusters (FP8 and BF16 sparse at 4 and 12 rows): unchanged. For 2048-token rows the fixed runs and the merge-load change are bit-identical to the previous head on all 34 shapes.
  • Page128 fixed runs: bit-identical to the previous head on all 20 MiniMax-M3 dense shapes; FP8 dense error against FP32 unchanged.
  • Outputs are bit-identical to the previous head for the shared clusters, task derivation, prologue order and longest-first order.
  • CUDA-graph replay stress: 2000 NaN-poisoned replays each match eager output bit for bit for sparse decode at 4, 64, 128 and 256 rows, FP8 and BF16 sparse verify, FP8 verify at 8K (cluster and reducer modes) and 214K, and the page128 fixed runs (FP8 and BF16 dense decode at 8K for 1 and 8 rows, BF16 verify 3×4 at 8K).
  • The two [FlyDSL] gfx1250 PA decode: wider softmax steps and leaner prologue for MiniMax-M3 shapes #7579 review findings (the max_context_length=None crash in the wide-step grid heuristic, and the accumulator factor underflowing for a dominant half with a tiny V scale) are fixed in 2149ba6; review later removed their regression tests.

Unverified:

  • No local gfx942/gfx950 runs. The tile-kernel changes are gated to gfx1250. The shared host code and planner ran on gfx950 only in MI35X CI (passing at 1816c76) and not at all on gfx942; at 3a0ffdc the planner was compiled for both but not run.
  • No end-to-end ATOM serving run.
  • The bench harness occasionally reports "invalid GPU kernel time: 0.0" for one case per run. The affected case passes when rerun; this is a profiler-side glitch.
  • The Performance table is at 8d0ba96 with FlyDSL 0.4.1; since the merge only the MiniMax-M3 comparisons in Performance were rerun.
  • Since review removed the standalone tests, no test covers the extreme V-scale cases or compiling a tile without max_context_length; they were checked at 8512f23 by script and by the removed tests.
  • One-page FP8 steps still overflow when the maximum holds across a V-scale drop of this size: logits 80/80/80/80 with V scales 1e32/1e-16/1e-16/1e-16 are non-finite on main. This PR leaves them unchanged.
  • Two unexplained tolerance misses on gfx1250, both just over the 5e-3 tolerance on FP8 per-token, FP16-query, plain-V cases, each on a case's first launch inside a multi-process test run: default-cap at 54dbb59 (4 of 12288 elements, 0.0053) and cluster2-shared at 1816c76 (7 of 497664 elements, 0.0060). Neither recurred in 4000 relaunches per case (alone or with three test shards loading the same GPU), 150 from-scratch reruns, NaN- or random-poisoned partial scratch, or five more full-suite runs.

PR-specific question

Do two-page FP8 steps keep the accuracy of one-page steps? Each half quantizes P against its own maximum and V factor. The halves and the history combine in FP32 with weights w * f / F, where F is the factor of the largest weighted factor among them, so no coefficient exceeds one and only negligible terms can underflow. Error against FP32 matches base on the tested shapes. The extreme-scale review cases give the reference at 8512f23: a 1e40 V-scale range, E4M3 P underflow, a dominant half with a 1e-16 V scale against 1e32, a V factor below the 1e-20 floor, and a 1e48 factor drop between steps. Review removed their standalone tests, so they were checked by script.

Changed op tests

op_tests/test_flydsl_pa_decode.py:

  • cluster16-steps (new _COMMON_CASES entry; 11 rows with empty, 1-, 129- and 257-token rows, graph capture): pins the 16-CTA step-split clusters. cluster8 doubles its batch past that threshold and, like cluster2-shared, now pins the fixed runs of steps. cluster16 quadruples its batch.
  • cluster4-wide-table (new; a 129-page table): pins plan-derived clusters for tables wider than 16 steps.
  • cluster2-gqa32 (new _COMMON_CASES entry; GQA32 page16 decode with empty and short rows), cluster8-wide-grid (new _COMMON_CASES entry; 160 rows at a budget of 2048, so the grid passes two CTAs per CU for BF16 and four for FP8) and cluster2-plain-v (new BF16 entry; GQA16 with plain V): pin plan-derived clusters (cluster_steps=False) for tiles that take 64-token steps. At 54dbb59 all three raise ValueError. No existing step-split candidate had two query tiles, plain BF16 V or a budget past two slots per CU.
  • cluster16-steps-kv2 (new; two KV heads, GQA 8, empty, partial-step and full rows, graph capture): keeps each head's step partials and preloaded page ids apart.
  • cluster16-runs-page128 (new, FP8 and BF16; 8 rows with empty, 1-, 129-token, partial-tile and bound-length rows, graph capture), cluster16-runs-page128-kv2 (FP8; two KV heads, a nine-tile bound, so a 9-CTA cluster) and cluster9-runs-page128-bs1 (BF16; one row, the one-CTA-grid two-page step): pin page128 fixed runs.
  • test_pa_decode_merge_alignment: the one-row D128 cluster case now expects a 16-CTA step-split cluster.
  • cluster2-shared (new _COMMON_CASES entry; 243 sequences, 2 partitions, graph replays): the only case with more than 240 split sequences, so the only one that exercises shared clusters, including a padded last cluster and empty rows. It pins cluster_seqs == 2.
  • _check_pipe_policy drops the new cluster_seqs, cluster_steps and cluster_runs keys before calling PaDecodeSchedule.select, and checks cluster_steps and cluster_runs when a case pins them.
  • _PA_DECODE_CASES and _run_pa_decode_case (6752572, for the benchmark harness that review removed): test_pa_decode's parameter list moves to module level and its body into a helper that also returns the validated launch and check closures, inputs and plan. The refactor leaves case IDs and checks unchanged (diff -w shows only the move, docstrings and the added return).

🤖 Generated with Claude Code

zhiding512 and others added 18 commits November 5, 2026 07:19
…om context lengths

Sequence-indexed grids read context_lengths[seq] alongside reduce_info and
split the visible tiles exactly as plan_pa_decode does, instead of chaining
reduce_info -> work_info -> block table before the first page DMA.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…A cluster

A sequence with more tasks than the cluster has CTAs splits its tiles over
the cluster's CTAs, the planner's split for that count. Dense decode at 8K
with 32 partition bounds now merges on chip instead of launching the reducer
(bs32: 11.0 -> 9.2 us FP8, 14.2 -> 12.3 us BF16). Error against an FP32
reference is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t output

Deriving one-partition tasks from context lengths shortened short grids
but cost many-row sparse prefill (4096 rows) 1-2.5%; only cluster grids
derive their tiles now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
One D128 query tile over page16 caches now stages two pages per wave, so
each softmax exchange and its three barriers cover 128 tokens instead of
64. LDS keeps the pages page-major: V is then the 128-token page layout
and K operands read each page's 16-token block. MiniMax-M3 FP8 sparse
shapes: decode 4/64/128/256 rows 1.18x/1.11x/1.21x/1.26x, verify 1.18x,
prefill 1024/4096 rows 1.26x/1.04x. Error against an FP32 reference is
unchanged within 1% except 4 rows with e^N(0,1) token magnitudes
(5.6e-2 -> 6.3e-2), as P normalizes V scales over 128 tokens.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… small grids

Each wave stages two BF16 page16 pages, page-major, when the grid needs at
most two CTAs per CU; the 128-token stage then halves softmax exchanges.
Larger grids (sparse prefill) keep 64-token stages for occupancy.
MiniMax-M3 BF16 sparse decode 4/64/128/256 rows 1.17x/1.06x/1.11x/1.13x,
verify 1.17x, prefill unchanged; error against FP32 unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
One D128 FP8 query tile over page128 caches stages two pages per step
when the grid has at most one CTA per CU, or two per CU with about three
or more tiles per CTA. P still normalizes each page by its own V scales:
waves 0-1 own page 0's tokens and waves 2-3 page 1's, and the second
page's K128 PV is rescaled to the first page's factor, so error against
an FP32 reference is unchanged. PV and V-scale reductions take any
multiple of 128 tokens, and tail scales loop over the CTA's threads.
MiniMax-M3 FP8 dense decode bs1/4/8 at 8K 1.11x/1.17x/1.17x, bs3 220K
1.03x, others unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… one-CTA grids

With at most one CTA per CU, one D128 BF16 query tile over page128 caches
stages two pages per step (each in the one-page LDS layout), halving the
softmax exchanges per token. MiniMax-M3 BF16 dense decode bs1/4/8 at 8K
1.06x/1.07x/1.05x; error against FP32 unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… one-CTA grids

With at most one CTA per CU, each wave stages four BF16 page16 pages per
step. BF16 P needs no per-step normalization, so the wider step leaves
results within BF16 rounding of the 128-token step. MiniMax-M3 BF16
sparse decode 4 rows 1.05x, verify 12 rows 1.03x, others unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Two-page FP8 steps (page128 pairs and 128-token page16 steps) quantized P
against the whole step's maximum and V factor, and rescaled the second
page by the first page's factor. A first half whose logits trail by 14
rounded its P to zero in E4M3, and a V-scale range of 1e40 overflowed the
page ratio to inf, where one-page steps gave the reference.

Each half (waves 0-1, waves 2-3) now quantizes P with its own maximum and
V factor, runs its own PV, and the halves combine in FP32 with weights
exp2(m_h - m) * f_h / max(f0, f1), all at most one. The FP8 page16 step
stays 64 tokens on grids beyond four CTAs per CU, where the split costs
more than the saved exchange. Adds the two review cases as regressions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
gfx1250 keeps 15 clusters resident per 16 CUs, so batches with more than
240 split sequences per KV head fell back to the separate reducer. Such
batches now put 2, 4, ... sequences in one cluster of P * k CTAs (up to 16):
each sequence still merges its own P partials, every CTA reaches the
cluster barrier, and a padded last cluster's CTAs only sync. MiniMax-M3
sparse decode at 256 rows (2 partitions) runs one kernel: FP8 1.11x,
BF16 1.12x, bit-identical to the reducer. A 243-row test pins the shared
clusters with graph replays; 2000 NaN-poisoned replays match eager.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Four FP8 D128 query tiles over page128 caches gave each wave one tile and
the whole page, so every wave read all of K and V from LDS. Wave pairs now
share two tiles and each wave covers half of every page: each K or V
operand feeds two WMMAs (K128 QK, K64 PV), halving LDS reads, and a pair
merges its two online-softmax states once through the page buffer the last
page left unused. P keeps the page's V normalization; error against an
FP32 reference is unchanged within 1%. MiniMax-M3 FP8 verify 3x4 at 8K
1.07x, 214K 1.05x (ATOM-style calls: 1.02x, 1.05x).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… small grids

Double-buffered steps issued a task's second stage only after the first
stage landed, so two-step sparse tasks paid two copy latencies in series.
On grids with at most one CTA per CU, the prologue now issues both stages
and step 0 waits only for its own copies (same-wave TDM copies complete in
order; scale copies only accompany whole stages). Fuller grids and page128
pairs keep the old order, where the earlier copy's contention cost more.
MiniMax-M3 sparse decode 4 rows: FP8 1.03x, BF16 1.02x; verify 12 rows:
FP8 1.05x; outputs bit-identical.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
One-partition plans write output directly from one CTA per sequence.
Sparse prefill rows see min(row + 1, 2048) tokens, so in grid order the
short rows ran first and the full-length rows formed the last wave. CTAs
now take sequences in reverse order. MiniMax-M3 sparse prefill: FP8 1024
rows 1.06x, BF16 4096 rows 1.04x, the others unchanged; bit-identical.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
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 gfx1201 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 7619 --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.

@github-actions github-actions Bot added the FlyDSL label Nov 8, 2026
@aiter-bot

aiter-bot commented Nov 8, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision 3a0ffdc5ee2e · 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

The PR changes how gfx1250 FP8 and BF16 PA decode tile kernels schedule work (step width, wave pairing, cluster sharing and splitting, prologue order, CTA order), and how many task slots small gfx1250 decode plans reserve. Outputs are unchanged in meaning: these are scheduling changes for the same attention.

The existing behavior left time on fixed overheads. Each 64- or 128-token step paid a cross-wave softmax exchange, the four FP8 MTP4 query tiles each read the whole page from LDS, batches above 240 split sequences took a second reducer launch, prologues chained dependent loads, and long sparse-prefill rows ran last.

Two #7619 review fixes sit on top. `pa_decode` requests step-split clusters only for tiles that take 128-token steps; other tiles raised `ValueError`. The FP8 per-token pipelines carry the floored V factor through step rescaling, the half merge and the epilogue; below the 1e-20 floor of P normalization the output was 0.09–0.5× of the reference, including on one-page paths that predate this PR. e1eb72f1f merges main, which pins FlyDSL 0.5.0 and passes torch dtypes to `compile_pa_decode_tile` (#7388). 3a0ffdc5e merges main again for #7700 (gfx942/gfx950 PA decode); its one conflict was two imports added at the same line.

A third review fix (385386d61) lets two-page steps keep the history's V factor. Taking the factor from the current halves alone overflowed the history coefficient to infinity when a later step's factor fell far below an earlier one while the maximum held. Review also removed the benchmark harness and the standalone tests (385386d61, 8512f2396, 511e69b47).

Validation and unverified scope

Validated on gfx1250 (MI450, 256 CUs, PyTorch 2.11.0+rocm10.1) on one GPU.

At 3a0ffdc5e (511e69b47 merged with main b0c5c0289, which adds #7700), with FlyDSL 0.5.0 (main's pin):

* `python -m pytest -q op_tests/test_flydsl_pa_decode.py`: 306 passed, 159 skipped, as at 511e69b47.
* Black and Ruff pass on the changed files.
* All 262 FP8 and BF16 `test_pa_decode` cases produce byte-identical outputs at 3a0ffdc5e and 511e69b47, and the 260 kernels they compile have identical gfx1250 ISA: the merge changes no gfx1250 kernel.
* #7700 changes only the gfx942/gfx950 PA decode classes and this PR only the gfx1250 ones, and the merge keeps both sides' changes verbatim. Compiled for gfx950 and gfx942 without running, all 20 planner variants build, including #7700's balanced planner with this PR's kernarg preload (all 10 argument dwords).

At 511e69b47 (8512f2396 minus one compile test), with FlyDSL 0.5.0 (main's pin):

* `python -m pytest -q op_tests/test_flydsl_pa_decode.py`: 306 passed, 159 skipped; the tests removed in review had 13 cases.
* Black and Ruff pass on the changed files.
* Against 1816c7628, 256 of 262 FP8 and BF16 `test_pa_decode` cases produce byte-identical outputs. Six FP8 per-token, FP16-query page16 cases differ by one FP16 ulp, at most 1.5e-5.
* The multi-step review case (page logits 0/80/80/80, per-token V scales 1e32/1e-16/1e-16/1e-16) gives the reference on page128 pairs and 128-token page16 steps (output/reference 1.0018); at 1816c7628 every output was non-finite on both. Logits 80/80/80/80 with the same scales give 1.0014. Checked by script.
* The 13 cases of the tests removed in review (`test_pa_decode_two_page_steps_keep_page_scales`, `test_pa_decode_value_factor_below_floor` and `test_pa_decode_tile_without_context_bound`) pass with the fix, run before their removal.
* MiniMax-M3 matrix against 1816c7628 (84 points, 5 interleaved runs per side): geomean 0.999×. One point is outside the run-to-run spread: ATOM-style FP8 sparse decode at 128 rows, 2.6% slower in two runs.

At 1816c7628 (e1eb72f1f plus a test-only fix), with FlyDSL 0.5.0 (main's pin):

* `python -m pytest -q op_tests/test_flydsl_pa_decode.py`: 319 passed, 159 skipped. The skipped cases are all MXFP4 or gfx950-only.
* Black and Ruff pass on the changed files.
* All 262 FP8 and BF16 `test_pa_decode` cases produce byte-identical outputs at e1eb72f1f and at the pre-merge head 1a039b260, both on FlyDSL 0.5.0: merging main changes no output.
* MiniMax-M3 matrix against main e9efac0e2 (84 points, 3 interleaved runs per side): geomean 1.13×, with 67 points faster and one 0.6% slower (see Performance).
* MI35X CI at e1eb72f1f: `test_flydsl_pa_decode.py` 427 passed, 50 skipped, 1 failed. The failure was `bf16-cluster2-plain-v`, a case this PR added: gfx942 and gfx950 reject plain BF16 V caches, and 1816c7628 skips positive plain-V BF16 cases there. MI35X CI at 1816c7628: 427 passed, 51 skipped.

At 1a039b260, with FlyDSL 0.4.1:

* fsx950223's two #7619 findings (step-split dispatch on tiles with 64-token steps, and the unfloored V factor below 1e-20) are fixed in 5474b27f7 and 1a039b260, with regression tests. 316 passed, 159 skipped; the 25 new tests fail at 54dbb596b.
* All 243 FP8 and BF16 `test_pa_decode` cases that run at both revisions produce byte-identical outputs at 1a039b260 and 54dbb596b.
* BF16 kernels and the reducer compile to identical ISA at both revisions; only the 11 FP8 per-token kernels change, and none gains spills.

At earlier heads, with FlyDSL 0.4.1 (54dbb596b: 291 passed, 159 skipped):

* Error against an FP32 reference, on MiniMax-M3 shapes with random and e^N(0, 1) per-token magnitudes:
  * FP8 dense decode, BF16 dense and BF16 sparse: unchanged.
  * FP8 MTP4 verify (wave pairs): within 1% relative.
  * FP8 sparse decode: within 1%.
  * Step-split and fixed-run clusters (FP8 and BF16 sparse at 4 and 12 rows): unchanged. For 2048-token rows the fixed runs and the merge-load change are bit-identical to the previous head on all

[truncated in readiness report; see the PR description for the full answer]

PR-specific question

Do two-page FP8 steps keep the accuracy of one-page steps? Each half quantizes P against its own maximum and V factor. The halves and the history combine in FP32 with weights `w * f / F`, where F is the factor of the largest weighted factor among them, so no coefficient exceeds one and only negligible terms can underflow. Error against FP32 matches base on the tested shapes. The extreme-scale review cases give the reference at 8512f2396: a 1e40 V-scale range, E4M3 P underflow, a dominant half with a 1e-16 V scale against 1e32, a V factor below the 1e-20 floor, and a 1e48 factor drop between steps. Review removed their standalone tests, so they were checked by script.

Changed op tests

`op_tests/test_flydsl_pa_decode.py`:

* `cluster16-steps` (new `_COMMON_CASES` entry; 11 rows with empty, 1-, 129- and 257-token rows, graph capture): pins the 16-CTA step-split clusters. `cluster8` doubles its batch past that threshold and, like `cluster2-shared`, now pins the fixed runs of steps. `cluster16` quadruples its batch.
* `cluster4-wide-table` (new; a 129-page table): pins plan-derived clusters for tables wider than 16 steps.
* `cluster2-gqa32` (new `_COMMON_CASES` entry; GQA32 page16 decode with empty and short rows), `cluster8-wide-grid` (new `_COMMON_CASES` entry; 160 rows at a budget of 2048, so the grid passes two CTAs per CU for BF16 and four for FP8) and `cluster2-plain-v` (new BF16 entry; GQA16 with plain V): pin plan-derived clusters (`cluster_steps=False`) for tiles that take 64-token steps. At 54dbb596b all three raise `ValueError`. No existing step-split candidate had two query tiles, plain BF16 V or a budget past two slots per CU.
* `cluster16-steps-kv2` (new; two KV heads, GQA 8, empty, partial-step and full rows, graph capture): keeps each head's step partials and preloaded page ids apart.
* `cluster16-runs-page128` (new, FP8 and BF16; 8 rows with empty, 1-, 129-token, partial-tile and bound-length rows, graph capture), `cluster16-runs-page128-kv2` (FP8; two KV heads, a nine-tile bound, so a 9-CTA cluster) and `cluster9-runs-page128-bs1` (BF16; one row, the one-CTA-grid two-page step): pin page128 fixed runs.
* `test_pa_decode_merge_alignment`: the one-row D128 cluster case now expects a 16-CTA step-split cluster.
* `cluster2-shared` (new `_COMMON_CASES` entry; 243 sequences, 2 partitions, graph replays): the only case with more than 240 split sequences, so the only one that exercises shared clusters, including a padded last cluster and empty rows. It pins `cluster_seqs == 2`.
* `_check_pipe_policy` drops the new `cluster_seqs`, `cluster_steps` and `cluster_runs` keys before calling `PaDecodeSchedule.select`, and checks `cluster_steps` and `cluster_runs` when a case pins them.
* `_PA_DECODE_CASES` and `_run_pa_decode_case` (67525723f, for the benchmark harness that review removed): `test_pa_decode`'s parameter list moves to module level and its body into a helper that also returns the validated `launch` and `check` closures, inputs and plan. The refactor leaves case IDs and checks unchanged (`diff -w` shows only the move, docstrings and the added `return`).


🤖 Generated with [Claude Code](https://claude.com/claude-code)

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

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.

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

Changes are needed because FP32 ratio underflow can erase finite attention contributions, and direct helper calls without max_context_length can raise TypeError.

2 open issues
What changed in this PR

This PR builds on #7079 to reduce FlyDSL paged-attention decode latency on gfx1250, focusing on MiniMax-M3 decode, verification, and prefill shapes.

Changes:

  • Widens FP8/BF16 softmax steps and introduces FP8 wave-pair processing with earlier query loads.
  • Extends in-kernel partition merging, shares clusters across sequences, and reverses direct-output sequence order to favor longer sparse-prefill rows.
  • Adds numerical and shared-cluster regression cases plus a benchmark harness that reuses correctness-test inputs.
File Description
op_tests/​test_flydsl_pa_decode.py Adds page-local scaling and shared-cluster cases; exposes reusable test setup.
op_tests/​op_benchmarks/​flydsl/​bench_pa_decode.py Adds a correctness-checked FP8/BF16 latency benchmark with JSON output.
aiter/​ops/​flydsl/​pa_decode.py Expands cluster-merge eligibility and passes shared-cluster settings.
aiter/​ops/​flydsl/​kernels/​pa_decode/​traits.py Defines wider-step and early-staging scheduling policies.
aiter/​ops/​flydsl/​kernels/​pa_decode/​pipeline.py Implements wider softmax steps, wave pairs, and revised staging.
aiter/​ops/​flydsl/​kernels/​pa_decode/​op_merge.py Separates cluster synchronization from sequence merging.
aiter/​ops/​flydsl/​kernels/​pa_decode/​op_lds.py Adds multi-page staging and separates query loading from storage.
aiter/​ops/​flydsl/​kernels/​pa_decode_kernel.py Selects grid-dependent policies and implements shared-cluster launches.

Review effort: Balanced

* Two-page FP8 steps took the accumulator factor from the half with the
  larger V factor. When that half is negligible after softmax weighting
  (logits 0 and 128, V scales 1e32 and 1e-16), the dominant half's ratio
  of 1e-48 rounded to zero and the output was lost. The accumulator now
  takes the factor of the half with the larger weighted factor, and each
  half's coefficient is (weight * factor) / chosen factor, at most one,
  so no ratio overflows either.
* The two-page FP8 grid heuristic negated max_context_length, whose
  documented default is None, and raised TypeError for grids between one
  and two CTAs per CU. Without a bound it keeps one-page steps.

Adds both as regressions; outputs and error against FP32 are unchanged on
the MiniMax-M3 shapes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zhiding512

Copy link
Copy Markdown
Contributor Author

Fixed the two open findings from #7579 (@fsx950223, Copilot) in 2149ba6:

  • Dominant half with a tiny V scale (logits 0/128, V scales 1e32/1e-16): the accumulator now follows the half with the larger weighted factor, and each half's coefficient is (weight * factor) / chosen factor <= 1, so neither underflow of the dominant half nor 0 * inf occurs. Regression: test_pa_decode_two_page_steps_keep_page_scales[weighted-factor-16/128] (fails on d129063, passes now).
  • max_context_length=None crash in the two-page grid heuristic: guarded; without a bound the kernel keeps one-page steps. Regression: test_pa_decode_tile_without_context_bound with the reported call.
    Full suite: 246 passed, 159 skipped. Outputs and FP32-reference error unchanged; performance neutral.

Copilot AI balanced review requested due to automatic review settings November 8, 2026 02:35

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

Runtime plan selection independently probes gcnArchName instead of using the required get_gfx_runtime() helper, leaving it inconsistent with the shared runtime/AOT-replay architecture contract.

3 open issues

Review effort: Balanced

@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 1816c76. The two-page FP8 path introduces a multi-step accumulator-rescaling overflow. Targeted gfx942 regression tests passed, but gfx1250 execution remains unverified and gfx950 testing was unavailable because all devices were busy.

[P2] Include accumulated history when selecting the wide-step V factor — aiter/ops/flydsl/kernels/pa_decode/pipeline.py:2167

For gfx1250 FP8 D128/page128 decode with one partition, 512 tokens, cached V=1, page logits [0, 80, 80, 80], and per-token V scales [1e32, 1e-16, 1e-16, 1e-16], selecting the factor solely from the current halves makes the second wide step overflow. The first step retains a nonzero accumulator (~1.03e-30) normalized by ~2.23e29; the second selects ~2.23e-19 while corr=1, so the subsequent corr * state[-1] * vnorm becomes infinity. A scalar FP32 reproduction of the source recurrence confirms this overflow, whereas the base's one-page recurrence returns approximately 0.000601617, matching the reference. GPU execution remains unverified. Preserve a factor that also accounts for weighted history, or apply the rescaling without an overflowing intermediate, and add a multi-step regression.

Validation:

  • PASS on local: git -C checkout rev-parse HEAD
    Verified 1816c76; supplied base is also the merge-base. Complete diff saved in complete.diff.
  • PASS on local: python3 scalar_rescale.py
    Exit 0. Reproduced head-only FP32 history coefficient and accumulator overflow; base output 0.0006016171537339687 versus reference 0.0006016171292819052. Script and output preserved in scalar_rescale.py and scalar-rescale.log.
  • PASS on hjbog-srdc-39.amd.com / sixifang_dev: flock -w 30 /tmp/codex-pr-review-7619-1816c762-20261113/gpu.lock timeout 300 /opt/venv/bin/python -m pytest -q op_tests/test_flydsl_pa_decode.py -k 'cluster2-gqa32 or cluster2-plain-v or cluster16-steps-kv2 or invalid-select'
    Exit 0: 24 passed, 1 skipped, 453 deselected in 22.02s. Confirmed idle device 0 is gfx942 and imports resolve to isolated exact-head source and task-local FlyDSL 0.5.0. Plain BF16 V positive case skipped as unsupported. Environment and command saved in gfx942-final-command.sh; output in gfx942-final.log.
  • SKIP on dzm-mi355-gpu34-dev / fsx950223_pr_review_gfx950: srun --overlap --jobid=9581 --ntasks=1 --cpus-per-task=1 podman exec -i fsx950223_pr_review_gfx950 rocm-smi --showuse --showpids
    Discovered active allocation 9581 and verified gfx950 inside the configured container. All eight devices reported 100% utilization with existing processes; no GPU tests launched. Logs saved in gfx950-allocation.log, gfx950-probe.log, and gfx950-activity.log.
  • SKIP on gfx1250: Multi-step FP8 overflow GPU reproduction
    No configured gfx1250 environment. The scalar recurrence comparison does not constitute target GPU validation.

Remaining validation:

  • The blocking finding is supported by source tracing and scalar FP32 evaluation, not gfx1250 GPU execution.
  • gfx942 tests exercise shared host code and existing architecture paths, not the new gfx1250 pipelines or their performance.
  • Available CI statuses were inspected and saved in ci-results.json; the run-log request returned no log text, so CI test counts were not independently verified.
  • No end-to-end serving or performance benchmark was run.

Automated Codex review of commit 1816c7628377.

@zhiding512
zhiding512 requested a review from fsx950223 November 13, 2026 03:00
Two-page FP8 steps took the accumulator factor from the current halves
only. When a later step's factor fell far below the factor the history was
normalized by, while the softmax maximum held (corr = 1), the history
coefficient corr * state[-1] * vnorm overflowed: page logits 0, 80, 80, 80
with per-token V scales 1e32, 1e-16, 1e-16, 1e-16 gave inf on page128 pairs
and 128-token page16 steps, where one-page steps give the 6.0e-4 reference.

The accumulator now takes the factor of the largest weighted factor among
the two halves and the history (corr times its factor), so every
coefficient, the history's included, is at most one. P quantization keeps
each half's own factor. Both cases give the reference, as do logits 80, 80,
80, 80, which also overflow one-page steps. test_pa_decode outputs are
unchanged except one-ulp FP16 differences in six FP8 per-token page16 cases.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: Cursor <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 13, 2026 05:24
As requested in review, remove test_pa_decode_two_page_steps_keep_page_scales
and test_pa_decode_value_factor_below_floor, and the test module's pointer to
bench_pa_decode.py, which 385386d removed together with the two-page fix.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: Cursor <[email protected]>
@zhiding512

Copy link
Copy Markdown
Contributor Author

@fsx950223 All three points are addressed in 385386d and 8512f23.

[P2] Include accumulated history when selecting the wide-step V factor (385386d)

Confirmed on gfx1250 before the fix. Your case (page128, page logits 0/80/80/80, per-token V scales 1e32/1e-16/1e-16/1e-16) gave non-finite values for every output at 1816c76. The same pattern on 128-token page16 steps did too. Main's one-page steps give the 6.0e-4 reference.

The two-page accumulator now takes the factor of the largest weighted factor among the two halves and the history (corr * state[-1]). Every coefficient, the history's included, is therefore at most one. P quantization still uses each half's own factor. Both step kinds now give the reference (output/reference 1.0018, bf16 rounding).

Logits 80/80/80/80 with the same scales now also work on two-page steps (1.0014). On main, one-page steps still overflow in that case; that predates this PR and is unchanged here.

Following your inline comments, the PR no longer adds standalone tests, so I verified this case with a script rather than adding a regression test.

Removals: op_tests/op_benchmarks/flydsl/bench_pa_decode.py is removed in 385386d, and test_pa_decode_two_page_steps_keep_page_scales and test_pa_decode_value_factor_below_floor are removed in 8512f23.

Validation on gfx1250 (MI450, FlyDSL 0.5.0):

  • python -m pytest -q op_tests/test_flydsl_pa_decode.py: 307 passed, 159 skipped.
  • The 12 cases of the two removed tests pass with the fix (run before removing them).
  • Against 1816c76, 256 of 262 FP8/BF16 test_pa_decode cases are byte-identical. Six FP8 per-token, FP16-query page16 cases differ by one FP16 ulp, at most 1.5e-5.
  • MiniMax-M3 matrix (84 points, 5 interleaved runs per side): geomean 0.999x against 1816c76. One point is outside the run-to-run spread: ATOM-style FP8 sparse decode at 128 rows is 2.6% slower, reproduced in a second run. That kernel keeps the same register counts and has seven fewer instructions.

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

The new scaling and floor behavior lack targeted extreme-scale regression tests, and the existing tolerance would accept zero output in the tiny-scale case.

3 open issues
1 resolved since last review

Review effort: Balanced

Comment thread op_tests/test_flydsl_pa_decode.py Resolved
As requested in review, remove test_pa_decode_tile_without_context_bound.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: Cursor <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 13, 2026 05:42

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

A scalar FP32 reproduction exposes potential output-erasing underflow in a specific BF16/FP8 decode configuration, requiring human assessment because GPU behavior remains unverified.

2 open issues
1 resolved since last review

Review effort: Balanced

#7700 and this branch each add an import at the same line of
pa_decode/pipeline.py; keep both. The rest merges cleanly: #7700 changes
the gfx942/gfx950 PA decode classes and this branch the gfx1250 ones.

Co-authored-by: Cursor <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 13, 2026 06:11

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

All nonempty test rows fit within one CTA’s 1024-token capacity, leaving the shared-cluster merge path untested even during graph replay.

3 open issues

Review effort: Balanced

Comment thread op_tests/test_flydsl_pa_decode.py Resolved
@coderfeli
coderfeli merged commit 5398a99 into main Nov 13, 2026
@coderfeli
coderfeli deleted the zhiding512/pa-decode-opt branch November 13, 2026 13:30
fsx950223 added a commit that referenced this pull request Nov 16, 2026
…cies

main now carries #7700 (at bdabd08) and #7709 (at ce737ce, including
its own resolution against #7700) as squash merges, plus #7619's gfx1250
pa_decode changes. Every conflict in op_lds.py, pipeline.py, traits.py,
pa_decode_kernel.py, pa_decode_plan.py, pa_decode.py and the test takes
main's side, so the stack's older #7700/#7709 heads and their merge
resolutions are superseded. On top of main the branch keeps only #7701
(02dc5d1, unchanged) and this PR's three commits.

The STREAM_KV commit's flag rename now also renames main's named cache key
fields: PaDecodeCacheKey.gfx942_busy -> busy_grid and gfx942_two_per_cu ->
two_per_cu. Every consumer other than STREAM_KV stays gated on "gfx94".
Two hunks of this PR's commits were already on main through #7709's resolution
and drop out of this PR's diff: DUAL_GROUP's "not STREAM_KV" and the
_zero_rows kv_query axis follows SPLIT_MAJOR.

The merged tree is identical to main + #7701's five commits + this PR's
three commits cherry-picked.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fsx950223 added a commit that referenced this pull request Nov 16, 2026
Resolve conflicts with #7619 (gfx1250 wide steps, shared clusters, MTP4)
and #7709 (gfx942 schedule tuning).

- gfx1250_tile_traits also selects MXFP4 tiles: direct_output becomes
  plan_free, per_token_kv is off, query splits default to
  mxfp4_gfx1250_query_splits, and latency_grid stays off (no page16
  stages). compile_gfx1250_pa_decode(t) validates the MXFP4 limits on the
  traits and refuses cluster_steps/cluster_runs/cluster_seqs for MXFP4.
- Gfx1250Traits keeps plan_free/fuse_tasks after the new fields, which
  the selection passes positionally.
- Kernel: the fuse_tasks branch is unchanged; its else holds main's task
  selection plus the plan-free tasks and the MXFP4 pipeline.
- Host: cluster kernels now read work as context lengths and take
  run_tiles, so MXFP4 cluster launches pass context_lengths and 0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
lirui927 pushed a commit that referenced this pull request Nov 16, 2026
pa_decode gains optional quantized_output / output_scale (OCP FP8 plus
one FP32 descale per token), store_output and quantized_pad_rows. On
gfx1250 with one KV head, the one-partition direct output and cluster
merges write the FP8 output from the final values in registers; other
plans write BF16 and run the standalone per-token quant.

Rebased onto main after #7619 as one commit. The epilogue now also
covers step-split (cluster_steps) and run-split (cluster_runs) clusters
and the reversed direct-output order; clusters shared by several
sequences (cluster_seqs > 1) fall back to the standalone quant.

Squashes the PR's commits 5d72374..3b3b556:
- feat(flydsl): fuse sparse PA output quantization
- test(flydsl): cover production PA plan capacity
- perf(flydsl): quantize sparse PA output from registers
- fix(flydsl): fall back to the standalone quant for other PA output modes
- perf(flydsl): write a padded bucket's FP8 rows in the sparse PA quant launch
- refactor(flydsl): share the cluster sync and a thread's token slice in the PA quant epilogue
- test(flydsl): run the sparse PA FP8 output test from CI, time it, and trim it
- refactor(flydsl): fold the FP8 output tensors into pa_decode's existing checks
- feat(flydsl): widen the fused PA FP8 output to any GQA, D, page and MTP
- test(flydsl): fold the PA FP8 output test into test_flydsl_pa_decode.py

Co-Authored-By: Claude Opus 5.5 <[email protected]>
lirui927 added a commit that referenced this pull request Nov 17, 2026
* feat(flydsl): fuse sparse PA output quantization

pa_decode gains optional quantized_output / output_scale (OCP FP8 plus
one FP32 descale per token), store_output and quantized_pad_rows. On
gfx1250 with one KV head, the one-partition direct output and cluster
merges write the FP8 output from the final values in registers; other
plans write BF16 and run the standalone per-token quant.

Rebased onto main after #7619 as one commit. The epilogue now also
covers step-split (cluster_steps) and run-split (cluster_runs) clusters
and the reversed direct-output order; clusters shared by several
sequences (cluster_seqs > 1) fall back to the standalone quant.

Squashes the PR's commits 5d72374..3b3b556:
- feat(flydsl): fuse sparse PA output quantization
- test(flydsl): cover production PA plan capacity
- perf(flydsl): quantize sparse PA output from registers
- fix(flydsl): fall back to the standalone quant for other PA output modes
- perf(flydsl): write a padded bucket's FP8 rows in the sparse PA quant launch
- refactor(flydsl): share the cluster sync and a thread's token slice in the PA quant epilogue
- test(flydsl): run the sparse PA FP8 output test from CI, time it, and trim it
- refactor(flydsl): fold the FP8 output tensors into pa_decode's existing checks
- feat(flydsl): widen the fused PA FP8 output to any GQA, D, page and MTP
- test(flydsl): fold the PA FP8 output test into test_flydsl_pa_decode.py

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(flydsl): write every descale of an empty sequence longer than a CTA

store_empty wrote one descale per thread, so an empty sequence with
query_length above BLOCK_THREADS (128) left the rest of its descales
unwritten (reported by fsx950223). Stride the descale stores over the
block like the FP8 zeros. A BF16 GQA-1 D256 case with query_length 129
and an empty second sequence checks it against NaN-poisoned descales.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(flydsl): check that gfx942/gfx950 refuse the PA FP8 output

The quant-tagged pa_decode cases checked the FP8 output on gfx1250 only,
so MI35X CI ran none of it. There they now assert that quantized_output
and output_scale raise NotImplementedError.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(flydsl): correct the PA FP8 output's comments and contiguity message

- Name the missing typed API at the raw cvt_pk_fp8_f32 call, as the
  other FlyDSL kernels do.
- Padding rows clamped to the last row also load a row's first pmax
  entry before the cluster barrier, harmlessly; the comments said only
  the owner wave reads it.
- The contiguity error also covers quantized_output.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(flydsl): keep the D1024 MTP4 query split under the PA FP8 output

The spilling BF16 D1024/GQA16/MTP4/page128 tile kept query_splits=1 when
the FP8 output was requested, so its direct output could quantize in the
epilogue. It now keeps its measured four-way query split, and pa_decode
quantizes after the output with the standalone per-token kernel whenever
the selected tile splits its query rows. With FP8 output on one MI455X,
that is 1679 -> 295 us at one sequence of 2048 tokens and 9122 -> 1576 us
at four of 8192.

The pa_decode docstring now states exactly when the epilogue quantizes:
one KV head, no query split, and the one-partition direct output or a
cluster merge with one sequence per cluster. It also states that the
fallback writes the padded rows after the standalone quant. The stride
check that the contiguity check implies is removed. The test runs
cluster2-shared with the FP8 output, and adds the D1024 shape.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* refactor(flydsl): share the PA FP8 output's fused-path predicate with the test

pa_decode now decides with one helper, fuses_quant_output, whether the
gfx1250 tile quantizes the FP8 output in its epilogue: one KV head, the
one-partition direct output or a cluster merge with cluster_seqs == 1,
and no query split. The host dispatch and _check_quant_output both call
it, so the test no longer repeats the predicate or filters the compile
arguments through inspect.signature. The dispatch is unchanged.

The BF16 invalid-input cases now also cover the FP8 output's argument
errors: an output_scale without quantized_output, store_output=False
without the FP8 output, a negative or bool quantized_pad_rows, and pad
rows without the FP8 output.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(flydsl): pin the PA FP8 output's fused or fallback path per case

The quant tag on each case now names the path the dispatch must take,
"fused" or "fallback", and _check_quant_output asserts the launch's
quant_output against it. The test no longer rebuilds the tile options or
calls the dispatch's predicate, so a plan that stops fusing fails instead
of matching itself. The predicate is private to the dispatch again.

Also: _INVALID_CASES covers quantized_output without output_scale, the
FP8 shape comments and docstring include the quantized_pad_rows rows, and
the store_empty docstring states that descale 0 gives 0xFE bytes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(flydsl): count sequence-KV-head pairs in the shared-cluster note

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* pa_decode: share the FP8 output quant unit and test its operand guards

Add PaDecodeTraits.quant_unit, the gcd(GQA, 16)-row group that shares one
FP8 output scale, and use it both for the LDS maxima in total_bytes and in
Gfx1250OutputQuant, so the reservation and the layout cannot drift apart.

Cover the gfx1250 quantized_output and output_scale shape and dtype checks
in _INVALID_CASES: a missing pad row, a BF16 quantized_output, a [rows]
output_scale and an FP16 output_scale each raise before compilation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* pa_decode: clarify the quant-unit and padded-cluster comments

quant_unit is the row count behind one per-wave LDS maximum, not the
FP8 scale group; the padded cluster grid pads in t.cluster_merge rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: lirui927 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
rebklee added a commit to rebklee/aiter that referenced this pull request Nov 25, 2026
Conflicts in op_softmax.py, traits.py, pa_decode_kernel.py,
pa_decode.py, pa_decode_tuning.py and test_flydsl_pa_decode.py, all
where main and this PR add fields or arguments side by side. Kept
main's code and added causal on top:
- traits.py: causal is a named PaDecodeCacheKey field, which main now
  builds by keyword, and the last Gfx1250Traits field, since
  gfx1250_tile_traits passes the earlier ones by position.
- pa_decode_kernel.py: causal reaches compile_gfx1250_pa_decode through
  Gfx1250Traits, and ROCm#7619's wave-pair pipelines keep this PR's
  causal_rows gate.
- pa_decode.py: causal goes into tile_options, which feeds the cluster
  steps probe, _fuses_quant_output and compile_pa_decode_tile.
- op_softmax.py: this PR's causal-aware slack, with TILE_TOK renamed
  to KV_COMPUTE_BLOCK.
- The test file keeps both case lists. _check_pipe_policy builds one
  set of schedule kwargs for the MTP4 pin and main's pipe and NHD
  pins.

Main's BF16_MTP_FUSED, FP8_MTP4_LEAN and NHD paths take their row
bounds from context.py's offsets, so causal=False reaches them
unchanged. With main's planner fallback for torch builds without
shared_memory_per_block (ROCm#7205), the non-causal cases also pass on
torch 2.9.1.

Signed-off-by: Rebecca Lee <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants