Skip to content

[FlyDSL] pa_decode: MXFP4 K/V on gfx1250 (MTP, sliding window, query splits) - #7923

Merged
coderfeli merged 17 commits into
mainfrom
fsx/pa-gfx1250-mxfp4-kv
Nov 25, 2026
Merged

coderfeli merged 17 commits into
mainfrom
fsx/pa-gfx1250-mxfp4-kv

Conversation

@fsx950223

@fsx950223 fsx950223 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Run the FlyDSL pa_decode MXFP4 KV cache (e2m1 data + one e8m0 scale per 32 elements) on gfx1250. Until now it was gfx950-only. The API and cache views are the same as on gfx950. gfx1250 runs PV in FP8 (an E4M3 P), as the FP8 KV path does; gfx950 keeps its bf16 P and V. Supported: head_dim 128, page 128, 1..16 query heads per KV head, e4m3 or bf16 query, bf16 output.

Beyond gfx950, gfx1250 also takes MTP query lengths, sliding windows and query_splits > 1 (at most 64 query rows per CTA).

MXFP4 KV is classified as per-token KV on both architectures: its e8m0 bytes are each row's scales. It is requested with per_token_kv=True, and on both architectures the kernel keeps FP8's f32 per-token scale path off.

Motivation

On gfx1250, pa_decode refused MXFP4 caches (NotImplementedError: MXFP4 pa_decode supports gfx950). MXFP4 K+V is 136 B per token and head, against 264 B for FP8 with per-token scales. Decode at long context is bandwidth-bound, so the smaller cache should cut decode time.

Changes

Commit 1 (0e03046e2): gfx1250 MXFP4 decode with query_length 1.

  • Gfx1250Mxfp4Pipeline (kernels/pa_decode/pipeline.py): four wave32 waves each own 64 tokens of a 256-token tile and all 128 dims, so the tile loop has no barrier. The waves merge once through LDS (34 KB, the only LDS use). Raw K/V rows load straight into WMMA operand order one tile ahead, and page ids two tiles ahead.
    • QK: one V_WMMA_SCALE_F32_16X16X128_F8F6F4 per 16 tokens. A is the e2m1 K rows with each token's e8m0 dword as scale A; B is the e4m3 Q. A bf16 Q is normalized per row in the kernel: the exponent of its scale goes to scale B and the mantissa scales the scores, as on gfx950. Lane/byte layouts of the mixed fp4×fp8 operands and of both scale operands were measured on gfx1250.
    • V: dequantized by the same scaled WMMA against e2m1 identity blocks. The product is exact in f32 and comes out transposed (lane = dim, registers = tokens). After a bf16 pack it is the A operand of V_WMMA_F32_16X16X32_BF16, and P stays in registers as B. The eight identity operands are 8-dword windows of two 14-dword rows (28 VGPRs).
    • Why not a VALU widen: v_cvt_scale_pk8_{f32,f16,bf16}_fp4 ignore their data operand on gfx1250 with FlyDSL 0.5.0 (B0 silicon, asic_rev=1). Inputs 0x22222222 and 0x76543210 both convert to the nibbles of 0x7F7F7F7F, whether the operands are VGPRs, SGPRs or literals. The gfx950 v_cvt_scalef32_pk_bf16_fp4 does not exist for gfx1250 and asserts in LLVM.
    • Softmax: the running maximum stays in accumulator units, and P·2⁻²⁰ = exp2(fma(s − max, scale, −20)). The max token's difference is therefore exactly 0 even for logits near the f32 limit. The O rescale is skipped when no row's maximum grew (α = 1 exactly).
    • Scheduling: dim tiles dequantize in groups of four before any of them is packed. One dequant → pack → PV chain at a time serialized every WMMA.
  • kernels/pa_decode/op_lds.py: Gfx1250Mxfp4Loader (row/scale loads in WMMA order, page ids from the block table; pages past the context read the sequence's first page). op_gemm.py: Gfx1250Gemm.mma_mx.
  • kernels/pa_decode/traits.py, pa_decode_kernel.py: Gfx1250Traits(compute_dtype="mxfp4", plan_free=...). The gfx1250 tile kernel serves the plan-free form (one CTA per sequence, context lengths as work) and dispatches the new pipeline.
  • pa_decode.py (_pa_decode_mxfp4): accepts gfx1250 and launches its kernel. Output modes:
    • plan-free / one-partition plans write final rows;
    • other plans write packed partials for the shared reducer;
    • sequences whose tasks fit a workgroup cluster merge there instead of using the reducer (the rule is under "Review round 1").
    • gfx1250 additionally requires 16 B aligned query/output base pointers. It has no PAGE_ID_STAGE_LIMIT bound, since page ids come from the table.
  • gfx950: no kernel change. _pa_decode_mxfp4 keeps its launch arguments, now built through a shared tuple.

Commit 2 (411283ff7): MTP, sliding window, query splits, per-token KV.

  • MTP: a CTA owns (query positions of its split) × (GQA heads) rows in 16-row M-tiles, and each row masks its own causal bound. Every M-tile reuses the tile's V dequantization; only QK, softmax and the bf16 PV WMMAs repeat per M-tile. Tiles away from the causal edge or a window start run unmasked.
  • query_splits: positions split across CTAs through block_id.y, as on the other gfx1250 paths.
    • By default a CTA keeps at most 32 rows (2 M-tiles, 441 VGPRs, no spills), so G16 × MTP4 splits in two. At most 64 rows are allowed.
    • Measured on G16 × MTP4 (µs for splits 1 / 2 / 4): B3 × 32k 12.88 / 10.57 / 11.15; B3 × 225k 25.13 / 23.77 / 27.69.
  • Sliding window: planned tasks cover the window union as before; plan-free CTAs start at the first tile their positions can see.
  • Per-token KV: compile requests for MXFP4 carry per_token_kv=True.
    • gfx950's PaDecodeSchedule.select now keys MXFP4 as per-token instead of refusing it, and PaDecodeTraits.create keeps the f32 per-token scale tensors and LDS buffers off for MXFP4.
    • gfx1250 behaves the same: either flag selects the same kernel.
    • The gfx950 MXFP4 ISA is unchanged: 5 specializations, cross-compiled with ARCH=gfx950 COMPILE_ONLY=1 from the PR base and from this branch, are identical.
  • Wrapper (commit 2): query rows are context_lengths × query_length; windowed plans must match the window and the query length; the reducer and scratch take query_length × group rows. gfx950 still refuses MTP and windows with the same errors.

Commit 4 (aa93dff0f): fuse adjacent MXFP4 MTP tasks.

  • Problem: a CTA with several query M-tiles fits two to a CU. G16 × MTP4 splits into 2 CTAs of 32 rows at 441 VGPRs. A default plan (2×CU tasks) therefore runs its split CTAs in two rounds, each paying about 3 µs of first-load latency and epilogue for a couple of tiles.
  • Fix: when tasks × splits exceed two CTAs per CU, a CTA runs two plan slots. Since review round 1 the kernel decides this from the plan's live tasks.
    • A sequence's adjacent tiles run as one task whose partial is the first slot's.
    • The second slot gets an empty partial (max −inf, sum 0) for the reducer.
    • Pairs across sequences run one after the other.
  • Scope: single-token decode, cluster merges and plan-free calls never fuse; their kernels are ISA-identical to commit 3.
  • Tried and dropped, all slower:
    • FP8 P/V in PV (PV costs ~0 of MTP4);
    • a wave per M-tile over LDS-staged K/V (4× the V dequantization);
    • an async global→LDS K/V ring (decode and MTP both slower);
    • occupancy hints (spills).

Review round 1 (886d8d941), on a merge of main (debc901ea) that brings in #7401:

  • Merge with [FlyDSL] feat(flydsl): fuse sparse PA output quantization #7401. [FlyDSL] feat(flydsl): fuse sparse PA output quantization #7401 appended quantized_output, output_scale and quant_rows to the gfx1250 tile launch. The positional MXFP4 launch now passes null pointers and the batch size. MXFP4 tiles also refuse quant_output in the kernel; pa_decode already refused it.
  • Fused tasks follow the live tasks. With fuse_tasks=2 the grid is half the plan capacity. Each CTA reads the live task count (the last sequence's first slot plus its count in reduce_info) alongside its slots.
    • A CTA runs two slots only when the live tasks × KV heads × query splits exceed two CTAs per CU.
    • Otherwise CTA b runs slot b alone, so a table-capacity max_context_length (as ATOM passes) no longer serializes a short batch.
    • The host compiles the fusing kernel only when the length bound allows that many tasks. That bound is now taken within the sliding window, as on the FP8/BF16 path, and counts KV heads.
  • Cluster merge for default plans. As on the FP8/BF16 path, partitions are bounded by the length bound and the window. Up to 32 of them merge in a 16-CTA cluster. Two refinements:
    • Each query split is a cluster of its own, so both residency bounds count the splits. Without that, G16 × MTP4 at B32 × 8k ran 1024 cluster CTAs in two rounds (16.4 µs against 14.4 µs).
    • Single-token decode uses a cluster only with at most 16 tiles a sequence, or when the clusters fill the CUs. Otherwise the plan's one-tile tasks and the reducer are faster (below).
  • gfx1250-strict (MI450 A0) refuses MXFP4, in pa_decode and in compile_pa_decode_tile. It was not run there, nor checked against A0's S_CLAUSE erratum for scaled WMMAs.
  • PaDecodeSchedule.select now says it takes MXFP4 only on gfx950 and that gfx1250 selects gfx1250_tile_traits.

Review round 2 (31628751e):

  • Fuse and cluster residency by M-tiles. A shared mxfp4_gfx1250_resident_ctas gives the CTAs resident at once: two a CU up to 32 rows (≤ 441 VGPRs), one with 3 or 4 M-tiles (579 / 710 VGPRs).
    • Such CTAs (MTP3 × G16, MTP5 × G8 / G12, MTP7 × G8) now fuse once the live tasks exceed one CTA a CU.
    • MTP clusters of them stay within the CUs.
  • Kernel diff. The fused branch returns early, so main's task-selection block keeps its indentation. The kernel diff against main is +282/−19, and every kernel the suite builds is byte-identical to round 1's.
  • Docstring. The pa_decode docstring states the default query split as it is.
  • Tests. MTP5 × G8 and MTP5 × G12 cases are added.

Round 3 (6e6de7f38): toward MXFP4 beating FP8 across the PA configs.

  • PV in FP8 (16x16x64), as on the FP8 KV path.
    • The identity-WMMA dequant scales each V block relative to S_b, the wave's running largest scale of that 32-dim block: V'' ≤ 384, exact in E4M3 within 2¹¹ of S_b.
    • P'' = P · 2⁸ rides in exp2. A growing S_b rescales its dims as a growing maximum rescales its row.
    • Dequant group 1 keeps 2-M-tile CTAs at 512 VGPRs (two a CU).
  • MTP clusters shrink until their CTAs fit one round, and take cluster runs. Decode merges in a cluster from a quarter of the CUs.
  • Load order: query loads issue before the first page ids and K/V, and the query quantizes after K/V issue.
  • Per-wave partials: clusters of at most 8 CTAs whose scratch holds a slot per wave store each wave's partial for the cluster merge. That skips the CTA's LDS merge of its four waves, which cost ~0.8 µs of a 1k decode.
  • Tolerance: gfx1250 MXFP4 tests compare at 1.5e-2 (E4M3 P). gfx950 MXFP4 kernels are unchanged.

Round 4 (24c5d6750, ce4d3dd99): wave pairs, reducer bound, merge order.

  • Wave pairs for 41–64 query rows. When such a call would fuse plan tasks (throughput-bound, reducer), each task now runs whole in one CTA, instead of in two query-split CTAs. The CTA takes 489 VGPRs, so two fit a CU.
    • Wave 2g+p owns M-tiles 2g and 2g+1, and the 64 tokens [64p, +64) of each 128-token page.
    • The two waves that read the same tokens each dequantize half the dims and swap them through LDS, with one barrier per page. That halves the V dequant per row.
    • The pair's two partials merge through LDS at the end.
  • Pair selection, measured cold (pairs vs fuse):
    • 64 and 60 rows: pairs win at every long-context shape, by 3–7%.
    • 48 rows: pairs win by 3–5% at low batch and lose by 2% at B16–B32, where both beat FP8 by 12–16%.
    • 40 rows: fusing wins, by up to 12%.
    • Where clusters merge, which is latency-bound, pairs lose by up to 30%, so those calls keep their path.
  • Reducer bound. The MXFP4 reducer's partition count is now bounded by the tiles that the length bound and window allow, as on the FP8/BF16 path. It used to be the plan's cap of up to 256. Short decode now takes a shorter register rung: G16 B1 × 8k goes 5.4 → 5.3 µs. Reverted in round 8: it dropped the partials of a context longer than the bound.
  • Merge order. The LDS merge of a CTA's waves now merges every M-tile before storing any.
    • Before, the row checks and lane-masked max/sum stores split each tile's stores into their own basic blocks. Every tile's LDS loads then waited behind the previous tile's stores: four serial ~500-cycle merges in a pair CTA.
    • Now only a part-filled M-tile checks its rows, and all eight threads of a row store its (equal) maximum and sum.
    • Cold, µs: MTP4 B3 × 8k 6.96 → 6.73, B3 × 32k 9.37 → 9.17; MTP2 B8 × 32k 10.28 → 9.76.
  • Tried and dropped:
    • Cluster runs for single-token decode: B128 × 1k and B8 × 8k got slower, B1 × 4k did not change.
    • Partner-only barriers for the pairs: the slowest wave of a CTA never waits at the barrier, so they would not shorten the CTA.

Round 5 (804782ed3): wave dims for one-M-tile decode.

  • Why: latency-bound decode lost to FP8 mostly in merging its token-split waves. Each wave held a 16 × 128 partial O over 64 tokens, and the CTA merged the four through 32 KB of LDS and a barrier. An ablation that dropped the V dequant entirely still lost B1 × 4k (4.7 against 4.0 µs).
  • Wave dims (run_dims):
    • Wave w still scores its own 64 tokens.
    • It now dequantizes dim block w (32 dims) of all 256 tokens of the tile. Four tokens' 16-byte block slices pack into one E2M1 A operand, so the identity dequant stays at 32 WMMAs a wave, with one running S a wave.
    • It runs its PV against every wave's P'', which the waves exchange through LDS once a tile, with one barrier.
    • Each P'' is relative to its source wave's running maximum. Wave w therefore keeps one accumulator per (source wave, dim tile) and rescales it by that wave's α.
    • The end exchanges the rows' (max, sum) and combines the accumulators in registers. Each wave then stores its own 32 dims, in the existing partial format for the reducer and the cluster merge.
  • Selection: at 522–532 VGPRs one CTA fits a CU, so only one-M-tile clusters whose CTAs all run in one round use dims (B32 × 8k with dims: 10.5 against 7.7 µs).
    • Single-token decode then takes the cluster instead of the reducer, plus cluster runs.
    • Dims replace per-wave partials from 8-CTA clusters (B4 × 2k: 4.28 → 4.17 µs). Clusters of 4 keep per-wave partials (B1 × 1k: 3.86 against 3.96 µs).
  • Cold KV, G16 decode (µs, MXFP4 before → after, FP8): B1 × 4k 4.81 → 4.01 (4.01); B4 × 4k 4.88 → 4.10 (4.26); B4 × 8k 5.86 → 5.17 (5.22); B8 × 8k 5.84 → 5.29 (5.42); B16 × 8k 6.17 → 5.56 (6.30).
  • Tried and dropped:
    • A split barrier (signal after publishing P'', wait after the dequant): within noise.
    • One lane offset plus immediate offsets for the dims V loads: slower.

Round 6 (0f8a5533a): G16 × MTP4 runs whole in long clusters.

  • Why: G16 × MTP4 splits its 64 query rows over two 32-row CTAs. Each split dequantizes the whole V for its half of the rows. Skipping the dequant saves 1.2 µs at B32 × 8k (11.5 µs).
  • Change: when the clusters fit one round with one 3–4 M-tile CTA a CU, and each CTA runs at least 8 tiles, the host runs each sequence and KV head as one such CTA. It dequantizes V once. The host now passes its query split to the compile.
  • Cold KV (µs, MXFP4 before → after, FP8):
    • B64 × 8k: 17.35 → 16.00 (17.21).
    • B128 × 8k (2-CTA clusters instead of the reducer): 29.72 → 25.99 (31.10).
    • 2 KV heads: B32 × 8k 17.66 → 16.41 (17.23); B64 × 8k 29.76 → 26.38 (31.22).
    • 4 KV heads: B16 × 8k 17.88 → 16.47 (17.60); B32 × 8k 29.90 → 26.22 (30.94).
  • Kept as is: with 4 tiles a CTA the splits still win (B32 × 8k: 11.5 against 11.7 µs).
  • Tried for G16 × MTP4 and dropped:
    • A 64-row CTA whose waves each own an M-tile over K and V'' staged in LDS (ties wave pairs on one-tile CTAs, slower on long loops: B3 × 225k 25.2 against 22.9 µs).
    • Wave dims for 2–4 M-tiles with a shared row maximum (two barriers a tile; B32 × 8k 12.3 against 11.5 µs).
    • Wave pairs in clusters (B3 × 8k 8.7 against 6.7 µs).
    • Wave pairs with fused tasks (B8 × 32k 16.2 against 12.8 µs).
    • A split barrier around the pairs' V'' swap (within noise).

Round 7 (01e902c4e): bank-conflict-free LDS operand exchanges.

  • Change: the pairs' V'' swap and the dims' P'' exchange used to store each lane's 8-dword operand at a 32-byte lane stride, which makes every 128-bit LDS access 2-way bank-conflicted. They now store two 16-byte halves at a 16-byte lane stride.
  • Cold KV (µs, before → after):
    • G16 decode: B2 × 8k 5.18 → 5.02 (FP8 5.00); B1 × 8k 5.01 → 4.96.
    • G16 × MTP4: B3 × 225k 23.23 → 23.02.
  • Tried for G16 × MTP4 and dropped: an FP8-style pipeline, like the FP8 MTP4 kernel, that stages K/V into LDS asynchronously instead of loading them straight into registers.
    • It is correct and uses 420–500 VGPRs.
    • With per-page stages two pages ahead and a swizzled, conflict-free layout, it ties wave pairs on long loops (B3 × 225k 23.05 µs) but is 2–4% slower on one-tile CTAs.
    • With whole-tile stages and one softmax update a tile, it is 5–7% slower.

Round 8 (4b0a62f21): review round 4 and its MI450 addendum.

  • Contexts longer than the bound are attended in full again.
    • The MXFP4 reducer takes the plan's partition cap again (min(max_partitions, capacity)), as in round 3. The plan splits the real length, so round 4's bound by max_context_length dropped partials (MI35X mxfp4-short-bound-np2).
    • Cluster runs had the same gap on gfx1250: they size each CTA's run from the bound. The cluster's last CTA now also runs the tiles past the runs. It chooses its run end before the context length arrives; a select after the length cost 0.2 µs at decode B1 × 8k.
    • Cost: the reducer's rung goes back to the plan's cap. Decode B128 × 8k goes 20.2 → 21.3 µs (round 3: 21.8, same GPU); B64 × 8k and below do not change.
  • Wave-partial slots. The cluster merge without runs indexed its per-wave partials from the plan's first slot of the sequence.
    • Once an MTP cluster is smaller than the sequence's tasks, that slot runs ahead of seq × cluster_merge, the range the host bounds by the scratch. Waves then wrote past the scratch or into the next KV head: a GPU memory fault at G16 × MTP8 with window 4096, B10 × 4k.
    • The kernel now takes seq × cluster_merge.
  • At most 64 rows a CTA. The whole-CTA and wave-pair rules now require query_length × group <= MXFP4_GFX1250_MAX_ROWS. G16 × MTP6 and G16 × MTP8 keep their splits instead of raising.
  • Tokens before the window. Masked tiles of run, run_pairs and run_dims now zero the V rows and scales of tokens before every row's window start, as they do past the context, so those scales no longer raise S_b.
  • Wave dims on long runs. Dims now take at most 4 tiles a CTA. B1 × 128k with max_partitions=8 gets round 3's 8-CTA cluster back without dims: 68.4 → 52.6 µs (round 3: 53.1).
  • Unchanged elsewhere. On the cold decode and MTP2/3/4 sets, every call compiles the same kernels as at d371a58aa, and times agree within 1.5% on the same GPU, except B128 × 8k above.

Performance (if applicable)

gfx1250 (MI450 eng. sample, B0, 256 CUs), FlyDSL 0.5.0, torch 2.11 ROCm. Shapes: 16 query heads / 1 KV head / D128 / page 128, bf16 query and output, planner defaults (2×CU budget), tight max_context_length. FP8 uses per-token K/V scales.

  • Measurement: the time is the whole pa_decode call (tile plus reducer or cluster merge), median of 3 rounds of min-of-5.
  • Cold KV: each CUDA graph replays at least 10 calls that rotate through at least 512 MB of KV copies, so no call finds its KV in the MALL.
  • Earlier numbers were warm: the tables before review round 1 reused one KV copy, and MXFP4's 92–142 MB caches stayed in the MALL. That overstated MXFP4 at B128 × 8k, B16 × 64k and B3 × 225k (1.67× / 1.77× / 1.38× claimed, against 1.26× / 1.49× / 1.33× here).

Before this PR MXFP4 was refused on gfx1250, so the comparison is against FP8. As of round 7 (01e902c4e), MXFP4 is faster in 60 of 71 configs of a cold-KV matrix (59 in round 5, 55 in round 4, 50 in round 3):

  • decode at G16 and G8, and with 8 KV heads;
  • windows;
  • MTP2/3/4, MTP4 with 2 KV heads and with G8;
  • ATOM's 128K-table bound.

The other 11 are 0.86–0.99×: G16 × MTP4, decode B128 × 1k, and three decode shapes within run-to-run noise of FP8 (below).

Hardware Batch × context FP8 KV (µs) MXFP4 KV, bf16 Q (µs) MXFP4 vs FP8
gfx1250 1 × 1024 3.79 3.87 0.98×
gfx1250 32 × 1024 4.22 4.13 1.02×
gfx1250 1 × 4096 4.10 3.99 1.03×
gfx1250 1 × 8192 5.03 4.99 1.01×
gfx1250 8 × 8192 5.37 5.21 1.03×
gfx1250 32 × 8192 7.90 7.74 1.02×
gfx1250 64 × 8192 14.04 10.59 1.33×
gfx1250 128 × 8192 26.19 21.32 1.23×
gfx1250 4 × 32768 7.70 7.14 1.08×
gfx1250 16 × 65536 25.54 16.32 1.56×
gfx1250 3 × 225280 17.34 13.09 1.32×
  • B128 × 8k depends on the GPU. MXFP4 runs 20.2–21.8 µs on GPUs 1–2 of this MI450 and 16.6–17.7 µs on GPU 3; FP8 runs 26.1–26.8 µs on all three. The row shows GPU 2 with round 8's reducer. Earlier rounds listed GPU 3's 16.90 µs (1.53×).

MTP (same harness, µs):

Hardware Workload B3 × 8k B3 × 32k B8 × 32k B3 × 225k B32 × 8k
gfx1250 FP8, MTP2 6.92 8.35 11.25 24.10 9.23
gfx1250 MXFP4, MTP2 6.34 7.76 9.85 15.40 8.92
gfx1250 FP8, MTP3 8.41 9.46 12.90 — 11.25
gfx1250 MXFP4, MTP3 7.37 9.24 12.09 — 10.12
gfx1250 FP8, MTP4 6.97 8.66 11.80 25.13 9.88
gfx1250 MXFP4, MTP4 6.69 9.17 12.67 23.04 11.50

Sliding window 4096, at contexts that do not start the window on a tile boundary (µs):

Hardware Workload B3 × 8292 B8 × 32868 B3 × 225380 B32 × 8292
gfx1250 FP8, decode 10.89 8.56 8.22 11.48
gfx1250 MXFP4, decode 5.33 4.65 4.75 7.24
gfx1250 FP8, MTP4 18.23 16.45 16.22 20.06
gfx1250 MXFP4, MTP4 7.65 6.77 7.53 10.53
  • The review harness measured FP8 window decode B3 × 8292 at 8.8 µs (1.65× for MXFP4). This harness measures 10.6–11.0 µs on GPUs 1–3, with MXFP4 at 5.3–5.7 µs.

G16 × MTP4 beyond the matrix: larger batches and more KV heads (same harness, µs; round 6 runs these whole in 2–4-CTA clusters):

Hardware Workload FP8 KV MXFP4 KV MXFP4 vs FP8
gfx1250 B64 × 8k 17.18 15.95 1.08×
gfx1250 B128 × 8k 31.56 26.18 1.21×
gfx1250 2 KV heads, B32 × 8k 17.52 16.16 1.08×
gfx1250 2 KV heads, B64 × 8k 31.37 26.43 1.19×
gfx1250 4 KV heads, B16 × 8k 18.20 16.40 1.11×
gfx1250 4 KV heads, B32 × 8k 31.43 26.33 1.19×
gfx1250 B16 × 8k 7.90 8.81 0.90×
gfx1250 2 KV heads, B16 × 8k 9.95 11.48 0.87×
gfx1250 4 KV heads, B8 × 8k 9.82 11.49 0.85×
gfx1250 B16 × 16k 11.74 12.63 0.93×
gfx1250 2 KV heads, B8 × 16k 11.72 12.60 0.93×

Where MXFP4 still trails (round 7):

  • G16 × MTP4 (64 query rows per sequence and KV head). The losing shapes:
    • B3 / B8 × 32k (0.95× / 0.93×) and B32 × 8k (0.86×);
    • the same MTP4 with a 128K bound at 8k–32k (0.94×);
    • outside the matrix (table above), B16 × 8k and its 2- and 4-KV-head equivalents (0.85–0.90×), and B16 × 16k (0.93×).
    • Why: at B16–B32 × 8k the two 32-row split CTAs each read K and V, 272 B a token against FP8's 264, so MXFP4 keeps no bandwidth edge there and does more compute.
    • The 64-row alternatives either run one CTA a CU (whole CTAs; they win only with at least 8 tiles a CTA) or pay a V'' swap a page (wave pairs).
    • FP8's MTP4 kernel uses wave pairs as well, with K/V staged in LDS. That staging did not help MXFP4 (round 7).
  • G12 × MTP5 outside the matrix (0.88–0.93×). It runs one 60-row CTA a CU.
  • Decode B128 × 1k (0.95×). It is throughput-bound with 4-CTA clusters.
  • Within run-to-run noise (±2–3%) of FP8: decode B1 × 1k, B8 × 1k and B2 × 8k (0.98–0.99×).
  • An e4m3 query in long single-CTA runs is 4–8% slower than a bf16 one (B1 × 8k with one partition: 26.7 against 24.8 µs; round 3: 25.7 / 25.4). The tables use bf16 Q.
    • Both loops run the same instructions. In each, a v_mov copies the next tile's first V-scale word into the loop-carried register, and it has to wait for that load.
    • With e4m3 Q, LLVM places the copy after 7 of the V dequant WMMAs instead of 19. ATT (B32 × 8k, one partition) puts the wait at 20.2k cycles a wave against 16.4k for bf16, out of 64.0k against 58.3k.
    • The bf16 loop spends 28% of its cycles on the same wait. Loading the next tile into registers that need no copy would help both.
  • What limits the remaining G16 × MTP4 shapes (ablations, timing only):
    • Wave pairs at long contexts gain nothing without the V dequant or the PV. Without the per-page V'' swap they gain about 5% (B8 × 32k 12.9 → 12.3 µs), which still trails FP8 (11.6).
    • The B32 × 8k split CTAs gain 1.2 µs without the dequant and 0.9 µs without the merge of their waves.

Review round 1 against the merge before it (cold, µs, MXFP4):

Call Before After Change
MTP4 + window 4096, B3 × 32k / B8 × 32k / B3 × 225k 11.71 / 12.15 / 12.10 6.70 / 6.63 / 6.70 the window bounds the fuse; cluster merge
MTP4, 128K-table bound, B3 × 8k / B8 × 8k 9.72 / 10.11 8.00 / 8.43 the live tasks decide the fuse
MTP4 / MTP2 at B8 × 8k 8.41 / 8.07 7.09 / 6.83 cluster merge
MTP4 B3 × 8k, MTP2 B32 × 8k 7.39, 10.28 7.04, 9.37 cluster merge
Decode B32 × 8k, window decode B32 × 8k 8.23, 6.84 8.01, 6.49 cluster merge
G16 MTP4 with 2 KV heads: B3 × 32k / B8 × 32k / B32 × 8k 14.6 / 21.1 / 22.8 13.6 / 19.6 / 21.6 fuse counts KV heads
  • Unchanged paths: the other rows of the tables above take the same kernel as before. Those kernels are byte-identical, and their times agree within run-to-run noise (B128 × 8k varies by ±0.5 µs).
  • Fusing under cold KV (forced off against on, MTP4): B3 × 32k 11.3 → 10.3, B8 × 32k 15.1 → 13.4, B32 × 8k 15.8 → 14.1 µs. The exception is B3 × 225k, which goes 27.3 → 27.9 µs.
  • Decode cluster rule: measured on contexts that do not start windows on a tile boundary, as in real decoding.
    • With 17–32 tiles, a cluster is 6–9% slower at B1–B2, within ±2% at B4–B8, and 3–4% faster at B16–B32 (8k).
    • With at most 16 tiles it is 5–6% faster.

Review round 2, CTAs of 3–4 M-tiles (cold, µs, MXFP4, 1 KV head; before / after):

Shape B3 × 32k B8 × 32k B32 × 8k
MTP3 × G16 (48 rows) 11.59 / 9.84 13.81 / 12.10 16.58 / 11.82
MTP5 × G8 (40 rows) 12.91 / 9.63 15.15 / 11.96 16.00 / 11.67
MTP5 × G12 (60 rows) 13.95 / 10.87 16.63 / 13.59 17.92 / 14.40
MTP7 × G8 (56 rows) 14.42 / 10.76 17.04 / 13.52 17.64 / 14.08
  • Forced fuse off: every fused shape above is slower without the fuse. B32 × 8k without it takes the reducer at 13.6–17.8 µs; before this round it took a 16-CTA cluster that one CTA a CU could not hold.
  • Unchanged shapes: B3 × 8k and B16 × 8k still take a cluster, and G16 × MTP4 with 2 or 4 KV heads is unchanged.
  • 4 KV heads: fused and unfused agree within ±4%.

The earlier optimization-step numbers (15.0 → 13.6 µs at B16 × 64k, and others) were taken with warm KV; they still rank the steps.

Testing

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

Documentation

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

Dependencies

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

Breaking Changes

None. gfx1250 callers that hit NotImplementedError for MXFP4 caches now run. gfx1250-strict (A0) and gfx942 still refuse MXFP4. PaDecodeSchedule.select refuses non-gfx950 MXFP4 with a message pointing gfx1250 to gfx1250_tile_traits.

PR Self-Review

Reviewed revision

4b0a62f21

Behavior and intent

pa_decode with an MXFP4 cache (dtypes.fp4x2/uint8 data views plus dtypes.fp8_e8m0/uint8 scale views) now runs on gfx1250 instead of raising, including MTP, sliding windows and query splits there. MXFP4 is requested as per-token KV on both architectures. On gfx950 the design keeps bf16 P and V, the P shift and the query-scale split. On gfx1250, since round 3, P is E4M3 in an FP8 PV, as on the FP8 KV path, and results match the fp32 reference within 1.5e-2. The extreme-scale and exact-mean cases still pass unchanged: V'' is exact in E4M3 and the 2**(S_b - 141) restore is exact.

Validation and unverified scope

On gfx1250 (B0), in a container with FlyDSL 0.5.0 (the requirements.txt pin), GPU 1:

python -m pytest -q op_tests/test_flydsl_pa_decode.py           # 480 passed, 109 skipped
python -m pytest -q op_tests/test_flydsl_pa_decode.py -k mxfp4  # 113 passed, 17 skipped
  • The MXFP4 cases cover: group sizes 1/3/4/8/16 with 1–4 KV heads; e4m3 and bf16 queries; contexts 1..2048, 4097, 5000 and 128k (peaked softmax against fp64); np1/2/3/8 plans, which exercise the reducer and the cluster merge; plan-free and graph replay; extreme e8m0 scales (subnormal V at 2⁻¹²⁷, 2¹⁹ tokens at 1.5·2¹²⁷, Q = 2⁻⁸⁰ against K = 2¹²⁰); short max_context_length bounds; rejected inputs; and NaN/Inf poisoning of unowned rows at page 128.
  • The new gfx1250 cases cover:
    • MTP 2–5 at groups 1/4/8/12/16 (including 40- and 60-row CTAs whose last M-tile is part-filled), with contexts below the query length and empty sequences;
    • windows 1 / 64 / 100 / 257 / 300 / 1000 with and without MTP, planned and plan-free;
    • forced query_splits 1 / 2 / 4;
    • MTP4 graph replay, and MTP2 + window with 2 KV heads and an e4m3 query;
    • 256 sequences that run wave pairs (G16 × MTP4 with and without a window, G16 × MTP3 at 48 rows, G12 × MTP5 at 60 rows), or fused tasks (G8 × MTP5 at 40 rows, with and without a window), each pinned to its path;
    • a 128K-table length bound over 32 short sequences (G8 × MTP5), which compiles the fusing kernel but runs one slot a CTA;
    • MTP4 behind a 4096 window at 32k contexts, pinned to a 16-CTA cluster without fusing;
    • default-plan decode pinned to wave dims in 16-CTA clusters (G16 at 4k and 8k, G8 at 4k) and to the reducer at 16k;
    • MTP4 unowned-row NaN/Inf poisoning;
    • refusals of 80-row CTAs and of windowed plans built for another query length;
    • round 8: G16 × MTP8 and G16 × MTP6 kept at 32- and 48-row splits; MTP8 window clusters with 1 and 2 KV heads; decode and MTP4 cluster runs under a 4096 bound over contexts up to 8192, where only tokens past the bound carry V; window tiles whose tokens before the window carry 2²⁰ V scales, on wave dims, split CTAs and wave pairs; and an 8-CTA decode cluster of 8 tiles a CTA, without dims.
  • The 17 skips are by design: 14 unowned-row cases with page 16/64 or head 256, which MXFP4 does not support, and three gfx950-only refusals (sliding-window, query-length-2, oversized-task).
  • The gfx950 MXFP4 kernels (5 tile specializations, 2 reducers, the planner) were cross-compiled with ARCH=gfx950 COMPILE_ONLY=1 from current main and from ed730c57d, and their ISA is identical. Every FP8/BF16 kernel the suite compiles on main is byte-identical here (one reducer binary varies run to run on main too).
  • Round 4, checked against ed730c57d:
    • gfx950: the MXFP4 tile kernels and the planner are byte-identical. Only the reducer's partition rung changes (np256 → np8 for a 2048-token bound), as on the FP8 path.
    • gfx1250: all 456 non-MXFP4 kernels that both suites compile are byte-identical. The 43 kernels that differ are MXFP4 tiles (merge order). The other new specializations are the wave-pair tiles and reducer rungs that follow the MXFP4 reducer bound.
  • Every kernel the full suite compiles on main (FP8/BF16 tiles, reducers, planner; 455 names) builds to byte-identical binaries here; the planner has 8 extra batch-bucket variants for the new cases.
  • Lint: ruff 0.16.0 clean, black 26.5.1 clean.

Not verified:

  • gfx950 was not run on hardware; there is no gfx950 here. Its MXFP4 ISA is identical to the base (above), and its host-side changes are the launch-argument tuple and the per-token schedule key.
  • gfx1250 A0 (gfx1250-strict) was not run, and the ISA was not checked against A0's S_CLAUSE rule for scaled WMMAs, so MXFP4 is refused there.
  • Whether the v_cvt_scale_pk8_*_fp4 behaviour is a compiler or a hardware issue was not determined.
  • 11 of the 71 matrix configs remain slower than FP8, by 1–14% (listed under Performance).
  • An intermittent abort is not root-caused. A few full-suite runs on cold FlyDSL caches aborted at a GPU sync in _check_output.
    • The kernel log shows the cause: no-retry page fault reads (TCP) at tiny addresses (0x8000, 0x1c000), i.e. a near-null pointer plus an offset.
    • One abort hit an FP8 case before any MXFP4 kernel had launched in that process.
    • Round 8 measured its rate on MI450 with warm caches. The -k mxfp4 subset aborted in 5 of 12 runs at d371a58aa and in 6 of 12 with round 8, each time at a different case. With AMD_SERIALIZE_KERNEL=3 HIP_LAUNCH_BLOCKING=1 it passed 8 of 8, so the abort depends on launch timing.
    • The suite counts above come from runs that did not abort.

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?

Before this PR, the MXFP4 cases of test_pa_decode and test_pa_decode_unowned_kv_rows were skipped on gfx1250 by their arch gate. With the gate widened but without the kernel, they fail on gfx1250 at the first pa_decode call with NotImplementedError: MXFP4 pa_decode supports gfx950.

The new gfx1250 MTP, window and query_splits cases also fail after commit 1 alone:

  • MTP: NotImplementedError: MXFP4 KV supports query_length 1, got 4
  • windows: ... supports no sliding window
  • forced splits: compile refuses query_splits != 1

These are the canonical MXFP4 pa_decode tests: the change widens their arch gate and adds gfx1250 cases to the same tables. No other op test exercises MXFP4 KV on gfx1250, or MXFP4 with MTP, windows or splits. The one case kept skipped there, oversized-task, asserts gfx950's PAGE_ID_STAGE_LIMIT refusal, which gfx1250 does not need because it reads page ids from the block table.

Changed op tests

op_tests/test_flydsl_pa_decode.py:

  • The existing MXFP4 cases (functional, extreme-scale pools, rejections, graph, unowned rows) now run on gfx1250 as well as gfx950.

  • New gfx1250-only MXFP4 cases cover MTP, sliding windows, forced query splits, fused MTP tasks, MTP graph replay and MTP unowned rows. They are skipped on gfx950, which still refuses MTP and windows. No other test covers MXFP4 with these features.

  • Rejection cases are split by architecture: gfx950-only (MTP, window, page-staging bound) and gfx1250-only (rows over 64, windowed-plan query length).

  • Review round 1 adds the following:

    • the fused cases take 256 sequences, so that clusters cannot serve them;
    • a loose-bound fusing case, a windowed long-context case pinned to fuse_tasks == 1, and default-plan decode pins for the cluster and the reducer.
      The fused and window cases fail before the round: the windowed case fuses, and the fused cases (80 sequences) now take the cluster.
  • Review round 2 adds MTP5 × G8 and MTP5 × G12 to the gfx1250 MTP cases.

  • Round 4 splits the 256-sequence fused cases by path, with a pairs pin on the compile requests:

    • wave pairs at G16 × MTP4 (with and without a window), G16 × MTP3 (48 rows, the last pair's second M-tile empty) and G12 × MTP5 (60 rows, part-filled);
    • fused tasks at G8 × MTP5 (40 rows, with and without a window), with the loose-bound case moved to G8 × MTP5.

    The pair cases fail before the round: their calls compiled fuse_tasks=2.

  • Round 8 adds ten cases. Each fails at d371a58aa (checked one by one):

    • mxfp4-mtp8-whole-capped (G16 × MTP8, 4 KV heads) and mxfp4-mtp6-g16-fused raised ValueError (more than 64 rows a CTA, and wave pairs of 48-row splits).
    • mxfp4-mtp8-window4096-cluster-kv1 and -kv2 (G16 × MTP8, window 4096, B10 × 4k): kv1 faulted the GPU, and kv2 returned wrong rows.
    • mxfp4-decode-runs-short-bound and mxfp4-mtp4-runs-short-bound: 16-CTA cluster runs under a 4096 bound over contexts of 8192 / 6000 / 4500, with V only past the bound. Both output 0 where the reference is 0.5, because the runs dropped the tail.
    • mxfp4-decode-np8-long-cta: an 8-partition decode plan over 16k, pinned to dims=False; it compiled wave dims.
    • The new _tail_pool builds those pages: K = 0, and V = 1 on the logical pages past the bound.
    • mxfp4-window-head-scales-decode-dims / -mtp4 / -mtp4-pairs (wave dims, split CTAs, wave pairs): visible V is 1, and tokens before every row's window start carry a 2²⁰ V scale (_window_head_pool). Unmasked, those scales raised S_b and every row was off by 0.04–0.15.
  • Round 7 removes test_pa_decode_mxfp4_gfx1250_strict_refused and test_pa_decode_mxfp4_is_per_token_kv. The gfx1250-strict refusal and the per-token schedule key stay in the code.

  • Round 6 adds mxfp4-mtp4-whole-cluster: G16 × MTP4 with 4 KV heads over 16 sequences of about 8k, pinned to one query split in 4-CTA clusters. Before the round it compiled two splits.

  • Round 5 replaces the decode pins with wave-dims pins (G16 at 4k and 8k, G8 at 4k with a part-filled M-tile) and a 16k reducer pin. A dims pin checks the compile requests. Before the round the 8k case took the reducer, and no call compiled wave_dims.

🤖 Generated with Claude Code

Extend the MXFP4 KV-cache decode (e2m1 data + e8m0 scale per 32 elements,
head_dim 128, page 128, query_length 1, up to 16 query heads per KV head)
from gfx950 to gfx1250, with the same pa_decode API, views and numerics:
e4m3 Q (or bf16 Q normalized per row, the scale's exponent on the WMMA B
scale), bf16 P and V, P shifted by 2**-20.

Gfx1250Mxfp4Pipeline: four wave32 waves each own 64 tokens of a 256-token
tile and all dims, so the tile loop has no barrier; the waves merge once
through LDS. Raw K/V rows load straight into WMMA operand order one tile
ahead, page ids two tiles ahead.

- QK: one V_WMMA_SCALE_F32_16X16X128_F8F6F4 per 16 tokens, A = e2m1 K rows
  with their e8m0 dwords, B = e4m3 Q (layouts measured on gfx1250 B0).
- V: dequantized by the same scaled WMMA against e2m1 identity blocks: exact
  in f32 and transposed (lane = dim), i.e. the bf16 PV A operand after a pack.
  v_cvt_scale_pk8_{f32,f16,bf16}_fp4 ignore their data operand on gfx1250
  with FlyDSL 0.5.0, and the gfx950 v_cvt_scalef32_pk_bf16_fp4 does not
  exist there. The eight identity operands are windows of two 14-dword rows.
- Dim tiles dequantize in groups of four before packing, so the dequant
  WMMAs overlap; the O rescale is skipped when no row's maximum grew.
- Output: plan-free (one CTA per sequence), packed partials for the reducer,
  or the gfx1250 cluster merge (2..16 tasks per sequence) instead of it.

Tests: the MXFP4 cases of test_flydsl_pa_decode.py now run on gfx1250 too
(66 pass, incl. extreme-scale, 128k peaked, graph and NaN/Inf unowned rows);
the full file passes on gfx1250 (298 passed, 94 skipped).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fsx950223
fsx950223 requested review from a team and a balanced review from Copilot November 13, 2026 07:46

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@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 7923 --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 13, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 4b0a62f21439 · 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

`pa_decode` with an MXFP4 cache (`dtypes.fp4x2`/uint8 data views plus `dtypes.fp8_e8m0`/uint8 scale views) now runs on gfx1250 instead of raising, including MTP, sliding windows and query splits there. MXFP4 is requested as per-token KV on both architectures. On gfx950 the design keeps bf16 P and V, the P shift and the query-scale split. On gfx1250, since round 3, P is E4M3 in an FP8 PV, as on the FP8 KV path, and results match the fp32 reference within 1.5e-2. The extreme-scale and exact-mean cases still pass unchanged: V'' is exact in E4M3 and the 2**(S_b - 141) restore is exact.

Validation and unverified scope

On gfx1250 (B0), in a container with FlyDSL 0.5.0 (the `requirements.txt` pin), GPU 1:

```
python -m pytest -q op_tests/test_flydsl_pa_decode.py           # 480 passed, 109 skipped
python -m pytest -q op_tests/test_flydsl_pa_decode.py -k mxfp4  # 113 passed, 17 skipped
```

- The MXFP4 cases cover: group sizes 1/3/4/8/16 with 1–4 KV heads; e4m3 and bf16 queries; contexts 1..2048, 4097, 5000 and 128k (peaked softmax against fp64); np1/2/3/8 plans, which exercise the reducer and the cluster merge; plan-free and graph replay; extreme e8m0 scales (subnormal V at 2⁻¹²⁷, 2¹⁹ tokens at 1.5·2¹²⁷, Q = 2⁻⁸⁰ against K = 2¹²⁰); short `max_context_length` bounds; rejected inputs; and NaN/Inf poisoning of unowned rows at page 128.
- The new gfx1250 cases cover:
  - MTP 2–5 at groups 1/4/8/12/16 (including 40- and 60-row CTAs whose last M-tile is part-filled), with contexts below the query length and empty sequences;
  - windows 1 / 64 / 100 / 257 / 300 / 1000 with and without MTP, planned and plan-free;
  - forced `query_splits` 1 / 2 / 4;
  - MTP4 graph replay, and MTP2 + window with 2 KV heads and an e4m3 query;
  - 256 sequences that run wave pairs (G16 × MTP4 with and without a window, G16 × MTP3 at 48 rows, G12 × MTP5 at 60 rows), or fused tasks (G8 × MTP5 at 40 rows, with and without a window), each pinned to its path;
  - a 128K-table length bound over 32 short sequences (G8 × MTP5), which compiles the fusing kernel but runs one slot a CTA;
  - MTP4 behind a 4096 window at 32k contexts, pinned to a 16-CTA cluster without fusing;
  - default-plan decode pinned to wave dims in 16-CTA clusters (G16 at 4k and 8k, G8 at 4k) and to the reducer at 16k;
  - MTP4 unowned-row NaN/Inf poisoning;
  - refusals of 80-row CTAs and of windowed plans built for another query length;
  - round 8: G16 × MTP8 and G16 × MTP6 kept at 32- and 48-row splits; MTP8 window clusters with 1 and 2 KV heads; decode and MTP4 cluster runs under a 4096 bound over contexts up to 8192, where only tokens past the bound carry V; window tiles whose tokens before the window carry 2²⁰ V scales, on wave dims, split CTAs and wave pairs; and an 8-CTA decode cluster of 8 tiles a CTA, without dims.
- The 17 skips are by design: 14 unowned-row cases with page 16/64 or head 256, which MXFP4 does not support, and three gfx950-only refusals (`sliding-window`, `query-length-2`, `oversized-task`).
- The gfx950 MXFP4 kernels (5 tile specializations, 2 reducers, the planner) were cross-compiled with `ARCH=gfx950 COMPILE_ONLY=1` from current main and from `ed730c57d`, and their ISA is identical. Every FP8/BF16 kernel the suite compiles on main is byte-identical here (one reducer binary varies run to run on main too).
- Round 4, checked against `ed730c57d`:
  - gfx950: the MXFP4 tile kernels and the planner are byte-identical. Only the reducer's partition rung changes (np256 → np8 for a 2048-token bound), as on the FP8 path.
  - gfx1250: all 456 non-MXFP4 kernels that both suites compile are byte-identical. The 43 kernels that differ are MXFP4 tiles (merge order). The other new specializations are the wave-pair tiles and reducer rungs that follow the MXFP4 reducer bound.
- Every kernel the full suite compiles on main (FP8/BF16 tiles, reducers, planner; 455 names) builds to byte-identical binaries here; the planner has 8 extra batch-bucket variants for the new cases.
- Lint: `ruff 0.16.0` clean, `black 26.5.1` clean.

Not verified:
- gfx950 was not run on hardware; there is no gfx950 here. Its MXFP4 ISA is identical to the base (above), and its host-side changes are the launch-argument tuple and the per-token schedule key.
- gfx1250 A0 (`gfx1250-strict`) was not run, and the ISA was not checked against A0's `S_CLAUSE` rule for scaled WMMAs, so MXFP4 is refused there.
- Whether the `v_cvt_scale_pk8_*_fp4` behaviour is a compiler or a hardware issue was not determined.
- 11 of the 71 matrix configs remain slower than FP8, by 1–14% (listed under Performance).
- An intermittent abort is not ro

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

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

Before this PR, the MXFP4 cases of `test_pa_decode` and `test_pa_decode_unowned_kv_rows` were skipped on gfx1250 by their arch gate. With the gate widened but without the kernel, they fail on gfx1250 at the first `pa_decode` call with `NotImplementedError: MXFP4 pa_decode supports gfx950`.

The new gfx1250 MTP, window and `query_splits` cases also fail after commit 1 alone:
- MTP: `NotImplementedError: MXFP4 KV supports query_length 1, got 4`
- windows: `... supports no sliding window`
- forced splits: compile refuses `query_splits` != 1

These are the canonical MXFP4 `pa_decode` tests: the change widens their arch gate and adds gfx1250 cases to the same tables. No other op test exercises MXFP4 KV on gfx1250, or MXFP4 with MTP, windows or splits. The one case kept skipped there, `oversized-task`, asserts gfx950's `PAGE_ID_STAGE_LIMIT` refusal, which gfx1250 does not need because it reads page ids from the block table.

Changed op tests

`op_tests/test_flydsl_pa_decode.py`:

- The existing MXFP4 cases (functional, extreme-scale pools, rejections, graph, unowned rows) now run on gfx1250 as well as gfx950.
- New gfx1250-only MXFP4 cases cover MTP, sliding windows, forced query splits, fused MTP tasks, MTP graph replay and MTP unowned rows. They are skipped on gfx950, which still refuses MTP and windows. No other test covers MXFP4 with these features.
- Rejection cases are split by architecture: gfx950-only (MTP, window, page-staging bound) and gfx1250-only (rows over 64, windowed-plan query length).
- Review round 1 adds the following:
  - the fused cases take 256 sequences, so that clusters cannot serve them;
  - a loose-bound fusing case, a windowed long-context case pinned to `fuse_tasks == 1`, and default-plan decode pins for the cluster and the reducer.
  The fused and window cases fail before the round: the windowed case fuses, and the fused cases (80 sequences) now take the cluster.
- Review round 2 adds MTP5 × G8 and MTP5 × G12 to the gfx1250 MTP cases.
- Round 4 splits the 256-sequence fused cases by path, with a `pairs` pin on the compile requests:
  - wave pairs at G16 × MTP4 (with and without a window), G16 × MTP3 (48 rows, the last pair's second M-tile empty) and G12 × MTP5 (60 rows, part-filled);
  - fused tasks at G8 × MTP5 (40 rows, with and without a window), with the loose-bound case moved to G8 × MTP5.

  The pair cases fail before the round: their calls compiled `fuse_tasks=2`.
- Round 8 adds ten cases. Each fails at `d371a58aa` (checked one by one):
  - `mxfp4-mtp8-whole-capped` (G16 × MTP8, 4 KV heads) and `mxfp4-mtp6-g16-fused` raised `ValueError` (more than 64 rows a CTA, and wave pairs of 48-row splits).
  - `mxfp4-mtp8-window4096-cluster-kv1` and `-kv2` (G16 × MTP8, window 4096, B10 × 4k): kv1 faulted the GPU, and kv2 returned wrong rows.
  - `mxfp4-decode-runs-short-bound` and `mxfp4-mtp4-runs-short-bound`: 16-CTA cluster runs under a 4096 bound over contexts of 8192 / 6000 / 4500, with V only past the bound. Both output 0 where the reference is 0.5, because the runs dropped the tail.
  - `mxfp4-decode-np8-long-cta`: an 8-partition decode plan over 16k, pinned to `dims=False`; it compiled wave dims.
  - The new `_tail_pool` builds those pages: K = 0, and V = 1 on the logical pages past the bound.
  - `mxfp4-window-head-scales-decode-dims` / `-mtp4` / `-mtp4-pairs` (wave dims, split CTAs, wave pairs): visible V is 1, and tokens before every row's window start carry a 2²⁰ V scale (`_window_head_pool`). Unmasked, those scales raised S_b and every row was off by 0.04–0.15.
- Round 7 removes `test_pa_decode_mxfp4_gfx1250_strict_refused` and `test_pa_decode_mxfp4_is_per_token_kv`. The gfx1250-strict refusal and the per-token schedule key stay in the code.
- Round 6 adds `mxfp4-mtp4-whole-cluster`: G16 × MTP4 with 4 KV heads over 16 sequences of about 8k, pinned to one query split in 4-CTA clusters. Before the round it compiled two splits.
- Round 5 replaces the decode pins with wave-dims pins (G16 at 4k and 8k, G8 at 4k with a part-filled M-tile) and a 16k reducer pin. A `dims` pin checks the compile requests. Before the round the 8k case took the reducer, and no call compiled `wave_dims`.

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

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot could not review the current head (for example, quota or service failure)

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.

…per-token KV

gfx1250 MXFP4 KV now takes MTP query lengths, sliding windows and query
splits; MXFP4 KV is per-token KV on both architectures.

- Rows: a CTA owns (query positions of its split) x (GQA heads) rows in
  16-row M-tiles, each row masking its own causal and window bounds. Every
  M-tile reuses the tile's V dequantization; only QK, softmax and the bf16 PV
  WMMAs repeat per M-tile. Tiles at the causal edge or a window start mask;
  others run unmasked.
- query_splits: positions split across CTAs through block_id.y as on the other
  gfx1250 paths. By default a CTA keeps at most 32 rows (two M-tiles: 441
  VGPRs, no spills; G16 x MTP4 splits in two); at most 64 are allowed.
  G16 x MTP4 verify, us for splits 1/2/4: B3 x 32k 12.88/10.57/11.15,
  B3 x 225k 25.13/23.77/27.69.
- Sliding window: plans cover the window union as before; plan-free CTAs
  start at the first tile their positions can see.
- Per-token KV: MXFP4's e8m0 bytes are each row's scales, so its kernels are
  requested with per_token_kv=True (gfx950's schedule keys it so instead of
  refusing it). On both architectures the kernel keeps the f32 per-token scale
  path off and either flag selects the same kernel: the gfx950 MXFP4 ISA is
  unchanged (5 specializations cross-compiled and diffed against the base).
- Wrapper: query rows are context_lengths x query_length; windowed plans must
  match the window and query length; the reducer and scratch take
  query_length x group rows. gfx950 still refuses MTP and windows.

Tests: gfx1250 MXFP4 cases for MTP 2-4 (groups 1/4/8/16, contexts below the
query length), windows 1..1000 with and without MTP (planned and plan-free),
forced query_splits 1/2/4, MTP graph replay and 2 KV heads; MTP4 unowned-row
poisoning; the per-token classification; refusals of 80-row CTAs and windowed
plans of another query length. Full file on gfx1250: 321 passed, 94 skipped.
Single-token decode is unchanged (A/B within 0.05 us).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 13, 2026 08:21

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@fsx950223 fsx950223 changed the title [FlyDSL] pa_decode: MXFP4 K/V on gfx1250 [FlyDSL] pa_decode: MXFP4 K/V on gfx1250 (MTP, sliding window, query splits) Nov 13, 2026
Copilot AI balanced review requested due to automatic review settings November 13, 2026 08: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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

A gfx1250 MXFP4 CTA with several query M-tiles (G16 x MTP4 splits into two
CTAs of 32 rows, 441 VGPRs) fits two to a CU, so a default plan (2 x CU tasks)
runs its split CTAs in two rounds, each paying a task's load latency and
epilogue over only a couple of tiles. Measured: one CTA per task costs about
3 us before its first tile and 0.6 us a tile alone, and halving the plan budget
made MTP4 15-20% faster.

When the tasks times the query splits exceed two CTAs a CU (bounded by the
batch's tile count), a CTA now runs two plan slots (fuse_tasks=2): a
sequence's adjacent tiles run as one task whose partial is the first slot's,
the second slot gets an empty partial (max -inf, sum 0) for the reducer, and
pairs across sequences run one after the other. Single-token decode, cluster
merges and plan-free calls never fuse; their kernels are ISA-identical.

G16 x MTP4, default plan, us (A/B interleaved): B3 x 8k 7.44 -> 7.44 (not
fused), B3 x 32k 10.55 -> 9.98, B8 x 32k 14.5 -> 13.0, B3 x 225k 23.7 -> 23.4,
B32 x 8k 15.2 -> 13.8.

Tried and dropped (slower): FP8 P and V in PV (PV costs ~0 of MTP4), a wave per
M-tile over LDS-staged K/V (4x the V dequantization), an async global-to-LDS
K/V ring (decode and MTP both slower), occupancy hints (spills).

Tests: two MTP4 cases with 80 sequences (one windowed) that fuse; full file on
gfx1250: 322 passed, 94 skipped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 13, 2026 09:21

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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]>
Copilot AI balanced review requested due to automatic review settings November 16, 2026 04:14

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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

FlyDSL PA review (automated harness)

Verdict: CHANGES_NEEDED · head 97b22a4156 · base = merge-base e3931369ce

No FP8/BF16 regression on gfx1250 (their ISA is identical). The new MXFP4 path passes every test on gfx1250, but the fuse_tasks heuristic slows down windowed and ATOM-style MTP calls, and several of the PR's speedup claims do not reproduce once the KV cache is rotated out of the MALL.

Performance and correctness

arch machine status verdict key numbers
gfx1250 MI450 container, 256 CUs, FlyDSL 0.5.0 both sides done no regression in FP8/BF16; MXFP4 perf issues (code review 1, 3) geomean time ratio head/base: prod 104 cases 0.999, unit 325 1.003 (60 MXFP4 cases run on head only), grid 1467 0.997, claims 36 1.000. 0 cases lost on head. All 1851 shared cases have bit-identical outputs. FP8/BF16 ISA identical: 306 kernels from the unit set, plus 46 from the two prod-set shards that finished before the GPU hang. pytest: base 306 passed / 159 skipped, head 395 / 94, 0 new failures
gfx950 MI355X not verified - the harness container was unreachable. CI (MI35X) at this head: test_flydsl_pa_decode.py 427 passed / 62 skipped. No ISA check here. The PR reports gfx950 MXFP4 ISA identical for 5 specializations
gfx942 MI308X not verified - the harness container was unreachable. Code reading only: gfx942 still refuses MXFP4, and every shared change is MXFP4-gated or defaulted

About the gfx1250 A/B: with the 2.5% band, 104 cases come out slower and 134 faster, with ratios between 0.90 and 1.14. Most are short latency-bound cases: median 6.4 us, 90% under 11 us. The kernels are ISA-identical and the outputs bit-identical, and a same-code control in the same session (two head-tree workers) spread 0.97-1.07. So this is noise, not a regression. The slower cases were not re-measured at 30 pairs, because the GPUs then hit a KFD hang that has nothing to do with this PR. The trigger was fp32 hipBLASLt faults in the test's reference GEMM when two workers built cases on one GPU at once. Those crashes hit base and head alike, and every affected case was re-run serialized and passed.

PR claims, re-measured on gfx1250. These use the head tree only, with the PR's shapes: G16, 1 KV head, D128, page 128, bf16 Q, default plan, tight max_context_length, FP8 with per-token scales. Times are in us. The harness rotates KV copies (at least 512 MB) so each call reads cold KV.

B x ctx (q1) FP8 measured (PR) MXFP4 measured (PR) MXFP4 vs FP8, measured claimed
1 x 8192 4.83 (5.04) 5.50 (4.94) 0.88x 1.02x
8 x 8192 5.76 (5.52) 6.26 (5.49) 0.92x 1.01x
32 x 8192 9.23 (7.51) 9.06 (6.83) 1.02x 1.10x
64 x 8192 14.74 (10.75) 11.70 (8.95) 1.26x 1.20x
128 x 8192 26.24 (24.11) 21.11 (14.42) 1.24x 1.67x
4 x 32768 8.61 (6.36) 7.56 (6.35) 1.14x 1.00x
16 x 65536 26.19 (23.97) 18.77 (13.55) 1.40x 1.77x
3 x 225280 18.50 (14.90) 14.26 (10.79) 1.30x 1.38x
  • The large-shape speedups do not reproduce. Measured 1.24x and 1.40x against the claimed 1.67x and 1.77x.

    • BF16 KV is 537 MB at B128 x 8K and at B16 x 64K, and there our times match the PR's: 38.6 vs 38.4 us and 38.0 vs 37.1 us.
    • MXFP4 KV is 92-142 MB at B128 x 8K, B16 x 64K and B3 x 225K, and there our times are 32-46% higher than the PR's.

    This pattern suggests the PR's numbers were taken with KV resident in the MALL. Please say whether the KV was rotated, and re-measure cold.

  • At B1 and B8 x 8K, MXFP4 is 8-12% slower than FP8 here. The PR claims parity. See code review 3 for a likely cause.

  • MTP4 without a window: MXFP4 is slower than FP8 at all five table-2 shapes. The gap is 11-46% (B3 x 8K 7.77 vs 7.02 us, B32 x 8K 16.01 vs 10.93 us), not 8-17% at three shapes. MTP2 and window-4096 decode reproduce in direction: MTP2 B3 x 225K gives 1.41x (claimed 1.37x); window 4096 gives 1.10-1.26x (claimed 1.19-1.37x).

  • MXFP4 MTP4 + window 4096 is 12.3-12.6 us at B3 x 32K, B8 x 32K and B3 x 225K, against the claimed 7.2-7.9 us. At B3 x 8K it is 7.57 us, which matches the claim. See code review 1.

  • The FP8 baselines in table 2 predate the merge with main. FP8 MTP4 + window 4096 measures 16.3-16.7 us against the claimed 11.3-11.9 us. FP8 code and ISA are identical between base and head, so this difference does not come from this PR.

Code review

  1. [major] fuse_tasks fires on the length bound, not on the tiles a call can actually have (pa_decode.py:386-395). max_tasks = min(capacity, num_seqs * ceil(schedule_context_length / 256)) ignores the sliding window. It also takes max_context_length at face value, and ATOM passes the block-table capacity there. When the bound overstates the tiles, the few real tasks get paired and run serially. For MXFP4, max_context_length changes nothing else in the selected tile (gfx1250_tile_traits uses it only for FP8/BF16 stages), so the slowdown below comes from the fuse alone. Measured on the head tree, G16 MTP4 MXFP4, default plan:

    • Window 4096: B3 x 8K does not fuse and runs in 7.57 us. B3 x 32K and B3 x 225K read the same 4K-token window, but max_tasks is 384 and 512, so they fuse and take 12.5 and 12.3 us. That is 1.65x slower, and slower than the PR's own 7.25 us, which was measured before commit 4 added fusing.
    • ATOM-style max_context_length = 128K table: B3 x 8K goes from 7.77 to 10.05 us (+29%).

    Suggestion: bound the per-sequence tiles by the window, as the FP8/BF16 path already does (window_tiles at pa_decode.py:1051-1056). Also consider deciding the fuse on the device from the plan's live task count, since the host cannot know real lengths without a sync. A test pinning fuse_tasks == 1 for a windowed long-context case would keep this from coming back.

  2. [major] gfx1250-strict (MI450 A0) gets the new MXFP4 kernel without validation (pa_decode.py:246, :713). chip_info._detect_native says strict maps to the gfx1250 family "only at explicitly validated dispatch sites". The PR states that A0 was not run, and that the A0 erratum on scaled WMMAs inside S_CLAUSE was not checked. Meanwhile the tests skip MXFP4 on gfx1250-strict (arch not in ("gfx950", "gfx1250")), so production calls on A0 run an untested kernel. Suggestion: refuse MXFP4 on gfx1250-strict until the ISA has been checked against the erratum and the tests run there.

  3. [minor] With a default plan, MXFP4 never takes the on-chip cluster merge (pa_decode.py:369-379). partitions = min(work_plan.max_partitions, capacity) equals the CU count (256) for a default plan, so 2 <= partitions <= 16 never holds and every planned call launches the reducer. FP8/BF16 first bound partitions by ceil(max_context_length / 256) and by the window, and merge up to 32 partitions with 16-CTA clusters (pa_decode.py:1046-1124). So at B1-B32 x 8K FP8 merges on chip while MXFP4 pays a second launch. The comment "As for FP8/BF16 on gfx1250" and the PR text ("sequences with 2..16 tasks merge within a workgroup cluster") do not match what runs. This plausibly explains the 0.88x and 0.92x rows above. That attribution comes from code reading only; it was not isolated by experiment.

  4. [minor] Conflicts with #7401. git merge-tree reports textual conflicts in traits.py, pa_decode_kernel.py and test_flydsl_pa_decode.py. #7401 also appends quantized_output, output_scale and quant_rows after run_tiles in the gfx1250 tile kernel's launch signature. The new positional MXFP4 gfx1250 _run_compiled(...) call (pa_decode.py:461-481) does not pass them. pa_decode.py itself merges cleanly, so whichever PR lands second would only find the mismatch at runtime. The PR merges cleanly onto current main, and #7864 does not conflict.

  5. [nit] Misleading refusal message (traits.py:248-251). The check is still arch != "gfx950", but the message now says "requires gfx950 or gfx1250". Called with gfx1250, it prints "requires gfx950 or gfx1250; got gfx1250". PaDecodeSchedule is the gfx942/gfx950 schedule; say so, and point gfx1250 to gfx1250_tile_traits.

  6. [process]

    • The PR body's "Reviewed revision" is aa93dff0f, not the head (aiter-bot flags it).
    • CI runs only on MI35X, so none of the roughly 60 new gfx1250 MXFP4 cases run in CI. They do pass on gfx1250 in this run: head pytest 395 passed, 0 failed.
Method
  • A/B design. Paired ABBA A/B on gfx1250. Two worker processes share one GPU, one per tree, each building cases with its own tree's op_tests/test_flydsl_pa_decode.py::_run_pa_decode_case (that tree's reference check included). Each worker captures a CUDA graph of 10 ATOM-style calls with explicit output and plan scratch, rotating at least 512 MB of KV copies to defeat the MALL. Each case uses 3 memory layouts, 12 pairs x 8 replays. Ratio = head / base.
  • Sets.
    • prod: ATOM's route, FP8 per-tensor, page 16, default plan (D256: 64/256), max_context_length = 128K table plus bounded twins.
    • unit: every valid test parameter.
    • grid: every non-MXFP4 test geometry x B{1,16,64} x {1K,8K,32K}.
    • claims: the PR's FP8/BF16 rows.
  • Verdict rule. slower = median ratio > 1 + band with at least 90% of pairs slower in every layout. The band is max(2.5%, A/A spread); the A/A control was base vs base on prod, 88 cases, 1-99% spread 1.9%.
  • Serialized builds. Workers were run with builds serialized after the hipBLASLt faults described above. Timing is unchanged by this.
  • MXFP4 claims. Measured head vs head, since base refuses MXFP4 on gfx1250. The time is the mean of both workers.
  • ISA. FlyDSL final ISA dumps, instruction streams hashed and compared as multisets, compile cache off.
  • Environment. torch 2.11.0+rocm10.1.0a, FlyDSL 0.5.0 (both sides).

Comment thread aiter/ops/flydsl/pa_decode.py Resolved
Comment thread aiter/ops/flydsl/pa_decode.py Resolved
Comment thread aiter/ops/flydsl/pa_decode.py Resolved
Comment thread aiter/ops/flydsl/pa_decode.py Resolved
Conflicts with #7401 (fused FP8 output quantization):
- pa_decode_kernel.py: the gfx1250 tile body is main's (quant_output,
  pad_output, pad_grid) under the fused-task branch, with the MXFP4
  plan-free task and pipeline dispatch re-applied.
- traits.py: main's quant_output/store_output precede the PR's plan_free
  and fuse_tasks; MXFP4 keeps its own LDS size.
- MXFP4 tiles refuse quant_output (pa_decode already does), and the
  positional MXFP4 gfx1250 launch passes the new quantized_output,
  output_scale and quant_rows arguments.

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

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

Follow-up: remaining measurements and second review pass

Head 97b22a4156, same gfx1250 box (MI450, 256 CUs, FlyDSL 0.5.0). The GPU hang that cut the first run short has cleared, so the measurements it left open are done. They confirm code review 1 and the MALL explanation, find no FP8/BF16 regression, and turn up one more issue with the fuse rule.

Measurements the first review left open

  • FP8/BF16: no regression. The 104 cases flagged slower at 12 pairs were re-measured at 30 pairs: 100 same, 3 faster, 1 slower (unit|bf16-cluster8, 1.032). That one did not hold up: a repeat gave 0.996, head against head gave 0.962, and with base and head swapped the base came out slower (1.022). All 104 outputs are bit-identical. The prod-set ISA comparison now covers all 104 cases, and the ISA is identical.

  • Forcing fuse_tasks=1 confirms code review 1. Same case, the wrapper's choice against fuse_tasks=1, interleaved in one process (G16, MTP4, MXFP4, 1 KV head, default plan). Times in us:

    case wrapper (fuses) fuse_tasks=1
    window 4096, B3 x 32K 12.68 7.71
    window 4096, B8 x 32K 12.81 8.41
    window 4096, B3 x 225K 12.52 7.61
    no window, 128K table bound (ATOM style), B3 x 8K 10.07 7.86
    no window, tight bound, B3 x 32K 11.49 12.24
    no window, tight bound, B8 x 32K 15.10 16.75
    no window, tight bound, B32 x 8K 16.10 17.74

    Fusing pays where it was designed to (the last three rows, 6-10%), so it is worth keeping. It is the trigger that needs to change.

  • The large-shape speedups depend on the MALL. Same shapes, q1, with KV rotated over at least 512 MB (cold) and with one resident copy (warm). Times in us:

    B x ctx FP8 cold / warm MXFP4 cold / warm PR FP8 / MXFP4
    128 x 8192 26.25 / 25.65 21.01 / 15.14 24.11 / 14.42
    16 x 65536 26.18 / 25.51 18.08 / 14.20 23.97 / 13.55

    Warm, MXFP4 lands within 5% of the PR's numbers, and the speedup matches the claim: 1.69x against 1.67x, and 1.80x against 1.77x. The 264 MB FP8 caches miss either way, while the 136 MB MXFP4 caches stay resident. Cold, the speedups are 1.25x and 1.45x. In a full model the other layers' KV reads evict each layer's cache between steps, so the cold numbers are closer to serving. Please state the cache condition next to the table, or add cold numbers.

  • The merge with main did not change MXFP4. Pre-merge aa93dff0f against the head on the 28 MXFP4 claim cases (same harness, same test builder): every output is bit-identical, and the time ratios are 0.96-1.02 (geomean 0.999). So the window slowdown predates the merge, and so does the gap to the PR at B1 x 8K (5.4 us here at both revisions, 4.94 us in the PR). The head's gfx1250 pytest run (395 passed) already covers the merged cluster path. What is left is bookkeeping: please update "Reviewed revision" to the head, and re-run the gfx950 ISA cross-compile there.

New in this pass

  1. [minor] The fuse trigger also misses shapes where fusing pays (pa_decode.py:395). max_tasks * splits > 2 * num_compute_units matches the point the PR measured: 32-row CTAs, two per CU, one KV head. The grid, though, is capacity x (kv_heads * query_splits), and the > 16 rows gate also admits CTAs with 3 or 4 M-tiles. With one split and the default budget, max_tasks * 1 is at most 512 (for B up to 512), which never exceeds 2 x 256 CUs, so those shapes never fuse. Measured at B8 x 32K, tight bound, default plan. Times in us:

    shape rows per CTA (splits) wrapper: no fuse fuse_tasks=2
    MTP3 x G16 48 (1) 15.56 13.44
    MTP5 x G8 40 (1) 16.32 13.20
    MTP7 x G8 56 (1) 18.41 14.89
    MTP5 x G12 60 (1) 18.07 14.97
    MTP4 x G16, 2 KV heads 32 (2) 22.82 20.93

    That leaves 8-19% unused. With 4 KV heads, forcing the fuse changed nothing (within 1%). MTP6 x G16 (48 rows, 2 splits) does fuse and saves 26% (22.48 against 30.46 us).

    Together with code review 1, the rule fires on windows and table-capacity bounds, where fusing hurts, and stays off here, where it helps. Basing it on the tiles a task really gets, and on how many CTAs of that M-tile count fit on a CU, would cover both. A benchmark or test with 3-M-tile CTAs and with 2+ KV heads would keep the threshold honest.

  2. [nit] The docstring's "at most 32 rows by default" is not what the split does (pa_decode.py:617). mxfp4_gfx1250_query_splits falls back to the largest of 1/2/4 that divides query_length. So MTP3/6 x G16 keep 48 rows, MTP5/7 x G8 keep 40/56, and MTP5 x G12 keeps 60. MTP5/7 x G16 (80/112 rows) are refused.

    • Every accepted shape above passes the test's reference check here, with an np7 plan, the default plan, plan-free, and window 300. Only the wording needs fixing.
    • Adding MTP5 x G8 or MTP5 x G12 to _MXFP4_GFX1250_CASES would cover multi-M-tile CTAs whose last M-tile is partly filled.
  3. [minor] A GPU-free guard was dropped. Commit 55273278c removed test_pa_decode_mxfp4_is_per_token_kv. Without a GPU, it checked that PaDecodeSchedule.select keys MXFP4 as per-token while PaDecodeTraits.create keeps the f32 per-token scale path off, which is what keeps the gfx950 MXFP4 kernel unchanged. What is left (test_flydsl_pa_decode.py:2326) only checks that the host passes per_token_kv=True, and CI has no ISA check. Consider restoring the select/create half.

  4. [nit] Most of the kernel diff is re-indentation. Of the +432/-210 lines in pa_decode_kernel.py, only +242/-20 remain with whitespace ignored. The fuse_tasks > 1 branch re-indents main's task-selection block, and that is what makes the #7401 conflicts large. Handling the fused case first and leaving main's block at its indentation would shrink both.

Method
  • The re-measurement, the ISA comparison and the pre-merge A/B use the same paired harness as the first review: two worker processes on one GPU, 3 memory layouts, ABBA pairs (30 pairs for the re-measurement).
  • The fuse, MALL, row-count and KV-head experiments run the head tree in one process.
    • Each case and its variant are built by the test's _run_pa_decode_case, including its reference check, then captured as CUDA graphs of 10 ATOM-style calls and timed interleaved (12 rounds x 8 replays over 3 layouts).
    • fuse_tasks is forced through the compile arguments the wrapper passes; the launch grid follows it.
  • The row-count and KV-head runs were repeated, and the two runs agree within about 1%.

Comment thread aiter/ops/flydsl/pa_decode.py Resolved
Comment thread aiter/ops/flydsl/pa_decode.py Resolved
@zhiding512

Copy link
Copy Markdown
Contributor

#7401 landed on main (d6ea3d1a2). This PR now conflicts with main in traits.py, pa_decode_kernel.py and op_tests/test_flydsl_pa_decode.py, and, being second, it is the one that has to adapt the gfx1250 launch (code review 4 above).

The conflicts will not show the part most likely to break. pa_decode.py merges cleanly, and after the merge the MXFP4 gfx1250 _run_compiled(...) call still ends with ..., 0, stream. The tile kernel's launch now takes run_tiles, quantized_output, output_scale, quant_rows, stream, so stream lands in the quantized_output slot and the call is three arguments short.

MXFP4 has no quantized output (the wrapper already refuses it), so passing what the FP8/BF16 caller passes with quantization off should be enough: flyc.from_c_void_p(fx.Float8E4M3FN, 0), flyc.from_c_void_p(fx.Float32, 0) and quant_rows (that caller passes num_seqs), then stream.

MI35X CI skips every gfx1250 MXFP4 case, so it will not catch a slip here. Please run the gfx1250 MXFP4 tests after rebasing and post the counts; the harness will re-check the new head.

- Fused MTP tasks follow the plan's live tasks: a fuse_tasks=2 CTA reads
  the live count from reduce_info with its slots and runs two slots only
  when live tasks x KV heads x splits exceed two CTAs per CU; otherwise
  CTA b runs slot b. The host compiles the fusing kernel when the length
  bound, now within the sliding window and counting KV heads, allows it.
  Cold KV, G16 MTP4: window 4096 B3 x 32k 11.7 -> 6.7 us; 128K-table
  bound B3 x 8k 9.7 -> 8.0 us; two KV heads B8 x 32k 21.1 -> 19.6 us.
- Default plans merge in a cluster as on the FP8/BF16 path (partitions
  bounded by the length bound and window, up to 32 over 16-CTA clusters).
  Residency counts query splits. Single-token decode uses a cluster only
  with at most 16 tiles a sequence or clusters that fill the CUs: B1 x 8k
  keeps the reducer (5.5 us against 5.9 us). Cold KV: MTP4 B8 x 8k
  8.4 -> 7.1 us, MTP2 B32 x 8k 10.3 -> 9.4 us.
- gfx1250-strict (MI450 A0) refuses MXFP4 in pa_decode and
  compile_pa_decode_tile: it was not run there, nor checked against A0's
  S_CLAUSE erratum for scaled WMMAs.
- PaDecodeSchedule's MXFP4 refusal says the schedule is gfx950-only and
  points gfx1250 to gfx1250_tile_traits.
- Tests: fused cases take 256 sequences; new loose-bound fusing,
  windowed long-context (fuse_tasks == 1, cluster 16), decode cluster and
  reducer pins, and the gfx1250-strict refusal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 06:02

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

The LDS merge of a CTA's waves used to merge and store one M-tile at a
time. The stores' row checks and lane-masked max/sum stores split each
tile into its own basic blocks, so every tile's LDS loads waited behind
the previous tile's stores: four serial ~500-cycle merges for a 64-row
wave-pair CTA.

`merge_rows` now merges all M-tiles first, and `store_rows` stores them
afterwards. Only a part-filled M-tile checks its rows. All eight threads
of a row store its (equal) maximum and sum, so no exec mask is needed.
Per-wave partial stores drop their half-wave mask the same way.

Cold KV, MXFP4 (us): G16 x MTP4 B3 x 8k 6.96 -> 6.73, B3 x 32k 9.37 ->
9.17, B32 x 8k 11.64 -> 11.46; MTP4 with a 128K bound B3 x 8k 8.24 ->
8.00; MTP2 B8 x 32k 10.28 -> 9.76. Single-M-tile decode is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 04:55

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Latency-bound MXFP4 decode lost to FP8 mostly in the merge of its token-split
waves. Each wave held a 16 x 128 partial O over 64 tokens, and the CTA
merged the four through 32 KB of LDS and a barrier. An ablation that dropped
the V dequant entirely still lost B1 x 4k (4.7 against 4.0 us).

With wave dims (`run_dims`), wave w still scores its own 64 tokens. It now
dequantizes dim block w (32 dims) of all 256 tokens of the tile, and runs
its PV against every wave's P'', which the waves exchange through LDS once a
tile:

- Four tokens' 16-byte block slices pack into one E2M1 A operand, so the
  identity dequant stays at 32 WMMAs a wave, with one running S a wave.
- Each P'' is relative to its source wave's running maximum. Wave w
  therefore keeps one accumulator per (source wave, dim tile) and rescales
  it by that wave's alpha.
- The end exchanges the rows' (max, sum) and combines the accumulators in
  registers. Each wave stores its own 32 dims in the existing partial
  format.

At 522-532 VGPRs one CTA fits a CU, so the host uses dims for one-M-tile
clusters whose CTAs all run in one round:

- Single-token decode then takes the cluster instead of the reducer.
- Cluster runs apply to dims decode.
- Dims replace per-wave partials from 8-CTA clusters.

Cold KV, G16 decode (us, MXFP4 before -> after, FP8):

| Shape | before | after | FP8 |
|-------|-------:|------:|----:|
| B1 x 4k | 4.81 | 4.01 | 4.01 |
| B4 x 4k | 4.88 | 4.10 | 4.26 |
| B4 x 8k | 5.86 | 5.17 | 5.22 |
| B8 x 8k | 5.84 | 5.29 | 5.42 |
| B16 x 8k | 6.17 | 5.56 | 6.30 |

Throughput-bound decode keeps its path (B32 x 8k with dims: 10.5 against
7.7 us).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 06:23

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

G16 x MTP4 splits its 64 query rows over two 32-row CTAs. Each CTA
dequantizes the whole V for its half of the rows. An ablation that skips
the dequant saves 1.2 us at B32 x 8k (11.5 us).

When the call's clusters fit one round with one 3-4 M-tile CTA a CU, and
give each CTA at least 8 tiles, the host now runs each sequence and KV head
as one such CTA instead. It dequantizes V once, and cluster sizing then
counts one split. The host passes its query split to the compile, so the
kernel's default cannot disagree.

Cold KV (us, MXFP4 before -> after, FP8):

| Shape | before | after | FP8 |
|-------|-------:|------:|----:|
| MTP4 B64 x 8k (4-CTA clusters) | 17.35 | 16.00 | 17.21 |
| MTP4 B128 x 8k (2-CTA clusters, not the reducer) | 29.72 | 25.99 | 31.10 |
| 2 KV heads, B32 x 8k | 17.66 | 16.41 | 17.23 |
| 2 KV heads, B64 x 8k | 29.76 | 26.38 | 31.22 |
| 4 KV heads, B16 x 8k | 17.88 | 16.47 | 17.60 |
| 4 KV heads, B32 x 8k | 29.90 | 26.22 | 30.94 |

With 4 tiles a CTA the splits still win (B32 x 8k: 11.5 against 11.7 us),
so those calls keep them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 09: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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

… conflicts

The wave pairs' per-page V'' swap and the wave dims' P'' exchange stored
each lane's 8-dword WMMA operand at a 32-byte lane stride. That makes every
128-bit LDS store and load 2-way bank-conflicted.

They now store the operand as two 16-byte halves at a 16-byte lane stride,
in the same 1 KB slot (`lds_store_operand` / `lds_load_operand`).

Cold KV (us, MXFP4 before -> after):
- G16 decode B2 x 8k 5.18 -> 5.02 (FP8 5.00); B1 x 8k 5.01 -> 4.96;
  B4 x 8k 5.16 -> 5.11.
- G16 x MTP4 B3 x 225k 23.23 -> 23.02; B16 x 16k 12.50 -> 12.39.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 20, 2026 07:23

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

…lection tests

Remove `test_pa_decode_mxfp4_gfx1250_strict_refused` and
`test_pa_decode_mxfp4_is_per_token_kv`, as requested in review.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 20, 2026 07:37

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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

FlyDSL PA review (automated harness), round 4

Verdict: changes needed · head d371a58aac · base = merge-base db3b870ea1 (main afc300d7 has no newer PA commits)

This round covers rounds 3-7 of the PR (6e6de7f38 … d371a58aa): FP8 PV, wave pairs, wave dims, per-wave partials, whole-CTA MTP and the reducer bound. FP8/BF16 is unchanged on every arch I could check. MXFP4 has three correctness problems, though. One of them already fails the MI35X CI (gfx950).

Performance and correctness

arch machine verdict key numbers
gfx942 MI308X, 80 CUs PASS Geomean time ratio head/base: prod (104 cases) 1.000, unit (367) 1.002, grid (2016) 1.000, claims (FP8 rows) 1.000. No case lost on head.
The first pass flagged 5 grid cases at 3.5-4.5% over a 3.0% band. At 30 pairs they measure 0.981-1.009, and 0.981-1.008 with base and head swapped: noise.
ISA: all 236 kernels identical.
pytest: base 414 passed / 128 skipped, head 414 / 165, 0 new failures.
gfx1250 MI450 not verified on hardware The harness container on the MI450 host has been down for ~35 h, and the host's 4 GPUs were running other jobs.
Compile-only instead (ARCH=gfx1250 COMPILE_ONLY=1, every unit case plus the 104 prod cases, from both trees): all 280 base kernels (FP8/BF16 tiles, reducers, planner) compile to identical ISA in head. The 56 head-only kernels are all MXFP4 tiles.
The PR's cold-KV claims were not re-measured this round. Round 3 reproduced them at 31628751e.
gfx950 MI355X not verified on hardware The harness host was unreachable (ssh timeout).
Compile-only, same case list: 276 of 279 kernels are identical (all tiles, the planner, and the FP8/BF16 reducers). The 3 that differ are MXFP4 reducer rungs (np40 / np80 → np5 / np64), i.e. finding 1 below.
MI35X CI on 0f8a5533a failed test_pa_decode[mxfp4-short-bound-np2] ("Tensor-likes are not close", shard 0, 1 failed / 510 passed). The head has the same code, and its CI was still building when I wrote this.

Findings

  1. [blocker] The MXFP4 reducer now drops partitions when a context exceeds max_context_length. This is a gfx950 regression against main, and it already fails CI.

    • Since round 4 (24c5d6750), _pa_decode_mxfp4 passes max_partitions = min(plan max_partitions, capacity, seq_tiles) to the reducer, where seq_tiles comes from the length bound (L529, L774). Main used min(work_plan.max_partitions, capacity), with the comment "a task may own more tokens than it".
    • The plan, though, splits the real length. plan_pa_decode([1024], 1, max_partitions=2) gives the sequence 2 tasks; I ran the planner to check. A bound of 128 then selects the np1 reducer.
    • The reducer handles at most NP live partials. Called directly with 2 live partials (O = 0 and O = 1, equal max and sum), it returns 0.5 at max_partitions=2 and 0.0 at max_partitions=1 (shared reducer, run on gfx942).
    • This is exactly what mxfp4-short-bound-np2 tests ("the reducer must merge both partials, whatever the bound"). The pa_decode docstring still promises the same for MXFP4: "A real context longer than that bound is still fully attended".
    • Suggested fix: keep min(work_plan.max_partitions, capacity) for the MXFP4 reducer. If the FP8-style contract (contexts ≤ bound) is intended for MXFP4 too, change the docstring and the test together, and note it as a behaviour change on gfx950.
  2. [major] Per-wave partials can write past the scratch (gfx1250, MTP with clusters that shrank).

    • wave_partials (L611-617) guards only 4 * num_seqs * cluster_merge <= capacity. That guard assumes sequence s starts at slot s * cluster_merge.
    • Without cluster runs (any window, or no max_context_length), the cluster kernel takes first from the plan's reduce_info. store_wave then writes slot task_slot * 4 + warp (pipeline.py L4467), and the merge reads first * 4 onwards (pa_decode_kernel.py L1670).
    • When MTP shrinks the cluster below the plan's tasks per sequence, first runs ahead of s * cluster_merge.
    • Checked with the PR's own planner and host rules (256 CUs, default plan, capacity 512):
      • G16 × MTP8 with window 4096 at B10 × 4k compiles cluster_merge=8, wave_partials=True, query_splits=4. The plan gives every sequence 16 tasks, and the last sequence starts at slot 144, so its waves write slots up to (144 + 7) · 4 + 3 = 607 > 511.
      • B12 × 8k (G16 or G12 × MTP8) reaches slot 779.
    • With 1 KV head that is an out-of-bounds write. With more KV heads it overwrites the next head's partials.
    • Suggested fix: index wave partials by seq * cluster_merge + part, or require the plan's per-sequence count to equal the cluster size.
  3. [major] The whole-CTA and wave-pair rules can build CTAs of more than 64 rows, so MTP shapes the docstring supports now raise (gfx1250).

    • The whole-CTA rule (L536) checks only 40 < query_length * group. The pairs rule (L604) checks only > 40, after which gfx1250_tile_traits forces query_splits = 1.
    • Host-checked (256 CUs, default plan):
      • G16 × MTP6 at B3 × 32k and B8 × 32k (default split 2 × 48 rows): ValueError: wave_pairs requires one split of 33-64 MXFP4 rows.
      • G16 × MTP8 at B64 × 8k (whole rule, 128 rows): NotImplementedError: … at most 64 query rows.
      • G16 × MTP8 at B16 × 8k with ATOM's 128K-table bound: the same wave_pairs ValueError.
    • The docstring says MTP positions split by 1/2/4 until a CTA keeps ≤ 32 rows (≤ 64 allowed), so these should run. Both rules need query_length * group <= MXFP4_GFX1250_MAX_ROWS.
    • Add one MTP6 × G16 case and one MTP8 case: the suite currently stops at MTP5.
  4. [minor] Tokens before the window start still raise S_b.

    • In the masked tile, only tokens past the context get their V scales zeroed (pipeline.py L3666 / L4283). Tokens of the first tile that lie before the window start keep theirs. They then enter the wave's running S_b for the rest of the sequence, although their P is 0.
    • A large out-of-window V scale therefore costs every later in-window token of that 32-dim block mantissa bits (V'' flushes to 0 once the spread reaches about 2^19).
    • Zeroing those rows' scales as well would make the masked tile consistent.

Notes

  • Numerics on gfx1250 MXFP4. P is now E4M3 (FP8 PV) and the tests compare at 1.5e-2, against 5e-3 elsewhere, so gfx1250 and gfx950 MXFP4 no longer agree numerically. An end-to-end accuracy check (e.g. GSM8K on the MXFP4-KV model) before ATOM routes gfx1250 MXFP4 here would close this out. Not blocking.
  • Tests. Dropping test_pa_decode_mxfp4_gfx1250_strict_refused leaves the A0 refusal, which stays in the code, without a test. A one-line pytest.raises with get_gfx_runtime patched to gfx1250-strict would keep it covered. The per-token assertion still lives in the main case runner.
  • Review state. All seven earlier threads are resolved, thanks. #8365 (draft, gfx1250 NVFP4 MXFP8 output) touches the same five PA files, so whichever lands second needs a rebase.
  • Method. Paired base/head A/B on the same GPU, 3 memory layouts, ≥ 512 MB of KV rotated per graph. ATOM-style launches with explicit plan scratch. The noise band comes from an A/A run.

Comment thread aiter/ops/flydsl/pa_decode.py Resolved
Comment thread aiter/ops/flydsl/pa_decode.py Resolved
Comment thread aiter/ops/flydsl/pa_decode.py Resolved
Comment thread aiter/ops/flydsl/pa_decode.py Resolved

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

FlyDSL PA review (automated harness), round 4 addendum: gfx1250 on hardware

Verdict: changes needed (unchanged) · head d371a58aac · base = merge-base db3b870ea1 · MI450 (gfx1250, 256 CUs), FlyDSL 0.5.0

The round-4 review could not run gfx1250 on hardware. The MI450 harness container is back, so this addendum adds the hardware results for the same head.

  • FP8/BF16 is unchanged on gfx1250.
  • Findings 1-4 of round 4 stand. Finding 2 now crashes the GPU, and finding 3 reproduces as written.
  • There is one new performance finding (5).

Performance and correctness (gfx1250)

check result
FP8/BF16 vs base PASS.
2604 paired A/B cases. Geomean time ratio head/base: prod 0.988, unit 0.978, grid 1.005, claims (FP8 rows) 0.989. No case lost on head.
The first pass flagged 265 cases over a 2.5% band, mostly under 20 µs. At 30 pairs they measure a geomean of 0.988, and 1.007 with base and head swapped.
One case stays above the band in both orders: unit|fp8-torch.float16-per-tensor-plain-v-mtp4-g16-page128-varied, 6.3 µs, +3.7% / +7.4%. Its case definition and ISA are identical in both trees, so I count it as tiny-kernel noise: a head-vs-head control on this box spreads up to 7% below 6 µs.
ISA: all 433 base kernels (unit + prod) compile identically in head. The 56 head-only kernels are all MXFP4.
pytest: base 368 passed / 174 skipped, head 470 / 109, 0 new failures. The 37 added tests pass, and so do the four mxfp4-short-bound-* cases.
MXFP4 claims (head only; main refuses MXFP4 on gfx1250) 42 of the 44 claimed MXFP4-vs-FP8 ratios reproduce within 10%. MXFP4 is faster than FP8 in 34 of the 47 measured pairs.
Not reproduced: decode B128 × 8k measures 1.30× against 1.53× claimed (MXFP4 20.4 µs against 16.9 claimed; FP8 26.4 against 25.9).
Window decode B3 × 8292 measures 1.65× against 2.04× claimed. That gap comes from FP8, which is faster here (8.8 against 10.9 µs); MXFP4 matches (5.32 against 5.33).
MXFP4 against round 3 (31628751e, same box) Geomean 0.933 over 122 cases.
Slower, confirmed at 30 pairs and in swapped order:
- B1 × 128k with max_partitions=8: +30-33% (48.6 → 64.3 µs), with bf16 or e4m3 Q. See finding 5.
- e4m3 Q with one or two partitions: +6-10%. mxfp4-np1 11.1 → 12.2 µs, mxfp4-plan-free-e4m3-q 11.3 → 12.0, mxfp4-short-bound-reducer 69 → 76, B1 × 32k np2 30.5 → 33.1. At the same shapes bf16 Q changes by 1-2%. At np1 the compile flags are the same as in round 3, so the cost is in the e4m3-Q tile body.
Round-4 findings on hardware Finding 2: G16 × MTP8 with window 4096 triggers a GPU memory access fault in pa_decode_tile_kernel_kvmxfp4_qbf16_d128_bs128_gqa16_mtp8_sw4096_qs4_cluster8_wp at B10 × 4k and B12 × 8k. G12 × MTP8 at B12 × 8k faults too, as does B12 × 8k with 2 KV heads. With 2 KV heads at B10 × 4k it returns wrong values instead: 0.9-2.5% of the elements are off, max abs diff 0.06 against 0.015 allowed.
Finding 3: G16 × MTP6 at B3 / B8 × 32k, and G16 × MTP8 with the 128K bound at B16 × 8k, raise ValueError: wave_pairs requires one split of 33-64 MXFP4 rows…. G16 × MTP8 at B64 × 8k raises NotImplementedError: … at most 64 query rows a CTA.
Finding 1 is gfx950-only. The gfx1250 path passes mxfp4-short-bound-np2 and two probes with a bound below the context. MI35X CI on d371a58aa fails test_pa_decode[mxfp4-short-bound-np2] again (shard 0: 1 failed, 507 passed).

New finding

  1. [minor, perf] Wave dims are chosen for clusters whose CTAs run many tiles.
    • dims_cluster (L563) only checks that the clusters fit in one round, and wave_dims (L623) follows it whenever wave partials are off.
    • With a capped plan, B1 × 128k at max_partitions=8 gives an 8-CTA cluster with 128 tiles a CTA.
      • Head compiles cluster_merge=8, wave_dims=True; round 3 compiled cluster_merge=8 without dims.
      • The call goes from 48.6 to 64.3 µs (+32%). That holds for both Q dtypes and both data patterns, at 30 pairs and with the order swapped.
    • The default plan at the same shape doesn't change: it uses no cluster and measures 7.5 µs. B1 × 8k (a 16-CTA cluster, about 4 tiles a CTA) gains, as the comment says.
    • Limiting wave dims to clusters with few tiles a CTA (seq_tiles / cluster_merge) would keep the short-context gain without the long-CTA loss.

Notes

  • Speed of e4m3 Q. Only callers that pass an e4m3 query and few partitions see the +6-10%. The PR's tables use bf16 Q, where nothing regressed. It's worth a look if ATOM is going to quantize Q before the call.
  • Method. Same harness as round 4, on 2 of the MI450's 4 GPUs (the other two were running other jobs). Case builds were serialized per worker. Claims are head-only absolute times with a cold-KV rotation of at least 512 MB.

Comment thread aiter/ops/flydsl/pa_decode.py Resolved
- Reducer: take the plan's partition cap again. The plan splits the real
  length, so a bound below the context dropped partials (gfx950
  mxfp4-short-bound-np2).
- Cluster runs: the cluster's last CTA also runs the tiles past the
  runs, so a context longer than the bound is attended in full. Its run
  end is chosen before the context length's wait.
- Wave partials: slots start at seq * cluster_merge, the range the host
  bounds by the scratch. A shrunk MTP cluster wrote past it.
- Whole CTAs and wave pairs take at most 64 query rows.
- Masked tiles zero the V rows and scales of tokens before every row's
  window start, so they no longer raise S_b.
- Wave dims take at most 4 tiles a CTA (B1 x 128k, max_partitions=8:
  68.4 -> 52.6 us).
- Tests: ten cases, each failing before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 04:29

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@fsx950223

Copy link
Copy Markdown
Contributor Author

Thanks for the round-4 review and the MI450 addendum. All five findings are fixed in 4b0a62f21. The threads have the details, and the description has a "Round 8" section.

  1. [blocker] Reducer bound. Reverted: the MXFP4 reducer takes min(work_plan.max_partitions, capacity) again.
    • gfx1250 had the same gap in its cluster runs, which size each CTA's run from the bound. Your probes didn't reach them.
    • With a 4096 bound over an 8192 context, a 16-CTA decode or MTP4 cluster output 0 when only the tail carried V.
    • The cluster's last CTA now also runs the tiles past the runs.
  2. [major] Wave-partial slots. The cluster kernel takes its slots from seq * cluster_merge, the range the host bounds. G16 × MTP8 with window 4096 at B10 × 4k no longer faults, and with 2 KV heads it matches the reference.
  3. [major] Rows over 64. Both rules now require query_length * group <= MXFP4_GFX1250_MAX_ROWS.
  4. [minor] Tokens before the window. In masked tiles, run, run_pairs and run_dims now zero the V rows and scales of those tokens.
  5. [minor, perf] Wave dims on long runs. Dims take at most 4 tiles a CTA. B1 × 128k with max_partitions=8 goes 68.4 → 52.6 µs (round 3: 53.1).

Tests. There are ten new cases, and I ran each at d371a58aa, where each fails:

  • finding 1: the two cluster-runs cases output 0 against 0.5;
  • finding 2: the two MTP8 window clusters fault the GPU or return wrong rows;
  • finding 3: two cases raise ValueError;
  • finding 4: three window cases (wave dims, split CTAs, wave pairs) are off by 0.04–0.15;
  • finding 5: one dims pin compiled wave dims.

On MI450, the full file gives 480 passed / 109 skipped, and -k mxfp4 gives 113 passed / 17 skipped.

Cost.

  • Finding 1 puts the reducer back on round 3's rung. Decode B128 × 8k goes 20.2 → 21.3 µs on the same GPU (round 3: 21.8). B64 × 8k and smaller shapes don't change.
  • A select after the context length's wait cost 0.2 µs at decode B1 × 8k. The last CTA now picks its run end before the length arrives, so decode cluster runs keep their time.
  • Everywhere else, the cold decode and MTP2/3/4 sets compile the same kernels as at d371a58aa, and times agree within 1.5% on the same GPU.

Notes:

  • e4m3 Q with 1–2 partitions: reproduced. At B1 × 8k with one partition, bf16 takes 24.8 µs and e4m3 26.7 µs (round 3: 25.4 / 25.7).
    • Both tile loops run the same instructions, in a different order.
    • Each loop copies the next tile's first V-scale word into its loop-carried register with a v_mov, which waits for that load. LLVM places the copy after 7 dequant WMMAs in the e4m3 loop, against 19 in the bf16 loop.
    • ATT at B32 × 8k (one partition) puts that wait at 20.2k cycles a wave for e4m3, against 16.4k for bf16, out of 64.0k against 58.3k.
    • The bf16 loop also spends 28% of its cycles there. A load ring that needs no copy should help both, so I've left it as a follow-up. The gap is listed under Performance.
  • Decode B128 × 8k depends on the GPU.
    • MXFP4 takes 20.2–21.8 µs on GPUs 1–2 of our MI450 and 16.6–17.7 µs on GPU 3. FP8 takes 26.1–26.8 µs on all three.
    • The table now shows GPU 2 (21.32 µs, 1.23×), with a note.
  • Window decode B3 × 8292: I can't reproduce FP8 at 8.8 µs. Here it takes 10.6–11.0 µs on GPUs 1–3, with MXFP4 at 5.3–5.7 µs. Your number is now noted next to the table.
  • Intermittent abort: the near-null-address abort from the existing note is just as frequent before and after this round.
    • The -k mxfp4 subset aborted in 5 of 12 runs at d371a58aa and in 6 of 12 at 4b0a62f21, at a different case each time.
    • With launches serialized, it passed 8 of 8 runs.
    • The description has these numbers. It is still not root-caused.
  • Strict-refusal test: removing it was intentional; the A0 refusal stays in the code.
  • End-to-end accuracy: agreed, a GSM8K-style check should happen before ATOM routes gfx1250 MXFP4 here. It is outside this PR.
  • [FlyDSL] gfx1250 PA decode: MXFP8 (E8M0 group-32) output for o_proj #8365: noted; whichever lands second rebases.

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

FlyDSL PA review (automated harness), round 5

Verdict: the round-4 findings are fixed in code, and the MI35X PA tests pass; one question is open before approval · head 4b0a62f214 · base = merge-base db3b870ea1 (main bd1416a1 adds two commits to tensor_shim.py only, which this PR does not touch)

This round reviews 4b0a62f21 ("review round 4 fixes") on top of d371a58aa, the head that round 4 and its MI450 addendum measured.

Round-4 findings, checked against the code

# finding at 4b0a62f21
1 [blocker] MXFP4 reducer drops partials when a context exceeds max_context_length (gfx950 CI) Fixed. The reducer takes min(work_plan.max_partitions, capacity) again, main's value. The gfx1250 cluster runs had the same gap: now the last CTA's run end is 2**30, so task_end = tiles, and count = min(ceil(tiles / run_tiles), P) makes the merge read every live CTA. Working through contexts below, at and above the bound by hand (including a bound that is not a multiple of P), every tile runs exactly once.
2 [major] per-wave partials write past the scratch Fixed. With wave_partials, first = seq * P. store_wave writes slot 4 (seq P + part) + wave, and the merge reads count * 4 slots from first * 4, so writes and reads share one base. The highest slot is 4 B P - 1, below capacity by the host guard. MXFP4 never sets cluster_seqs > 1, which is the one merge call that doesn't scale by the wave count.
3 [major] whole-CTA / wave-pair rules build CTAs of more than 64 rows Fixed. Both rules now require 40 < query_length * group <= 64, which falls inside wave_pairs' own check (one split of 33-64 rows). The MTP6 and MTP8 × G16 shapes keep their default splits.
4 [minor] tokens before the window start raise S_b Fixed in run, run_dims and run_pairs. tile_low = first_upper - window - first, and first_upper is the CTA's smallest row bound (with query_begin). So only tokens that no row of the CTA can see are zeroed, and the score masks are unchanged.
5 [minor, perf] wave dims on CTAs with long runs Fixed as suggested (seq_tiles <= 4 * cluster_size).

There are ten new cases, one or more per finding, and the author reports that each one fails at d371a58aa. On MI35X, mxfp4-decode-runs-short-bound and mxfp4-decode-np8-long-cta also run, next to the existing mxfp4-short-bound-* cases. The others are gfx1250-only, so CI doesn't run them.

Verification

  • Harness hardware runs: none this round. All three harness containers were down:

    • gfx942: the MI308X host rebooted, and its container has exited.
    • gfx950: the MI355X cluster's login node times out on ssh.
    • gfx1250: the MI450 container exited after a host reboot.
  • By construction: the delta only touches MXFP4 code:

    • Gfx1250Mxfp4Pipeline (run, run_dims, run_pairs);
    • the gfx1250 tile kernel's const_expr(t.mxfp4) and const_expr(t.wave_partials) branches;
    • _pa_decode_mxfp4.

    FP8/BF16 kernels on every arch, and the gfx950 MXFP4 tile, are therefore the same code as at d371a58aa, which round 4 found ISA-identical to the base (gfx942 and gfx1250 on hardware, gfx950 compile-only). The only gfx950 change is the reducer rung, which is back to main's.

  • CI (MI35X): shard 0, the one that runs test_flydsl_pa_decode.py, passed on this head: 510 passed, 79 skipped, 0 failed. At d371a58aa it had 1 failure, mxfp4-short-bound-np2. So finding 1 is also fixed on gfx950 hardware. The other seven shards were still running when this was posted.

Open before approval

  1. The intermittent page-fault abort on MI450 is not root-caused. The description reports that -k mxfp4 aborted in 5 of 12 runs at d371a58aa and in 6 of 12 at 4b0a62f21, on no-retry TCP page faults at near-null addresses (0x8000, 0x1c000). With AMD_SERIALIZE_KERNEL=3 HIP_LAUNCH_BLOCKING=1 it passed 8 of 8.
    • A near-null base plus an offset usually means a read through a null or not-yet-written pointer. The timing dependence fits a read that races an allocation or a free.
    • One abort hit an FP8 case before any MXFP4 kernel had run in that process. That points away from this PR's kernels.
    • However, nobody has measured the rate at the merge-base. The harness has also hit GPU faults on this MI450 when two processes built cases at the same time (inside hipBLASLt, not pa_decode), so the box itself isn't clean.
    • Ask: run the same loop at db3b870ea (the suite; MXFP4 is skipped there) and at the head with -k "not mxfp4", and post the abort counts. A similar rate at the base makes it pre-existing, to be tracked as its own issue. A rate that appears only with this PR needs a root cause before merge.

Notes (non-blocking)

  • e4m3 Q at np1/np2 (+6-10%): reproduced and explained (where LLVM places the v_mov of the next tile's first V-scale word). It is listed under Performance as a follow-up. Fine with me.
  • Claims: decode B128 × 8k is now listed at 1.23×, against 1.53× before, in line with the 1.30× the addendum measured. The window B3 × 8292 FP8 difference is noted in the body.
  • gfx1250-strict refusal: it still has no test. The author says that is intentional, but a one-line pytest.raises with get_gfx_runtime patched would stop the refusal from being dropped silently.
  • E2E accuracy (GSM8K-style) before ATOM routes gfx1250 MXFP4: agreed, outside this PR.
  • Review state: the six open round-4 threads are all addressed in code. #8458, #8459 and #8462 (drafts, gfx1250 NVFP4) touch the same PA files, so whichever lands later needs a rebase.

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

FlyDSL PA review (automated harness), round 5 addendum: gfx1250 on hardware

Verdict: changes needed. The intermittent GPU page fault reproduces with this PR's tree and not with main's, and it is not limited to MXFP4. · head 4b0a62f214 · base = merge-base db3b870ea1 · MI450 (gfx1250, 256 CUs), ROCm 10.1, torch 2.11, FlyDSL 0.5.0

Round 5 could not run gfx1250 because the harness's MI450 container was down. It is back, so this addendum adds hardware results for the same head. The code findings of round 5 are unchanged.

Performance and correctness (gfx1250)

check result
FP8/BF16 vs main PASS.
All 2106 common cases give bit-identical outputs. The ISA of all 433 base kernels (unit + prod) is identical in head; the 62 head-only kernels are all MXFP4.
First pass: prod 1.002, unit 1.004, grid 1.016, claims (FP8 rows) 0.989. It flagged 543 cases over the 2.5% band.
Re-measured at 30 pairs, those 543 give 0.972, and 1.012 with base and head swapped. Four stay above the band in both orders, all under 6.5 µs: three fp8-bf16-per-tensor-plain-v-g6-d64-cluster4 grid points at +5-10%, and unit|fp8-fp16-per-token-transposed-v-default-cap at +3-4%. Their ISA, plan and output bits are the same as main's. A head-vs-head control on this box spreads up to 7% below 6 µs, so I count them as noise.
pytest base 368 passed / 174 skipped; head 480 / 109. 0 new failures, and the 47 added tests pass.
Round-4 findings Fixed on hardware.
The 11 review probes for findings 1-3 run on head. On d371a58aa, the same harness worker still hits an illegal address on the first finding-2 probe (G16 × MTP8, window 4096, B10 × 4k).
The new mxfp4-*-runs-short-bound, np8-long-cta, whole-capped, window4096-cluster and window-head-scales cases run on head, and their pytest versions pass.
MXFP4 vs round 4 (d371a58aa) 58 cases are measured on both heads (the rest come after the finding-2 crash on d371a58aa). Outputs are bit-identical, and the geomean is 1.003.
Decode B128 × 8k is +4.6% (21.0 → 22.0 µs, all three layouts; single pass).

The intermittent page fault (round 5's open question)

1. Run as asked: 0 aborts in 48 runs. Each loop ran alone on one GPU, with the 12 rounds interleaved:

loop aborts each run
-k mxfp4 at head 0 / 12 113 passed
full suite at main 0 / 12 368 passed
-k "not mxfp4" at head 0 / 12 367 passed
-k mxfp4 at d371a58aa 0 / 12 103 passed

2. The harness reproduces it, only with this PR's tree.

  • The harness launches ATOM-style: explicit scratch, a cold-KV rotation of at least 512 MB, and two worker processes alternating on one GPU.
  • The process dies with illegal memory access or Memory access fault … Page not present. The dmesg bursts I checked are no-retry page faults at low addresses:
tree the process imports process crashes about how many case runs fault addresses (dmesg)
this PR (4b0a62f21) 9 ~5800 (FP8/BF16 ~3600, MXFP4 ~2200) 0x6c000, 0x7000, 0x8000, 0x180000, 0x512000, …
main (db3b870ea) 0 ~3800 (FP8/BF16) —

(Case runs exclude the pytest loops above.)

  • One of the nine is an FP8 case: grid|fp8-torch.bfloat16-per-tensor-transposed-v-mtp5-g12-page128|b16|c1024, at address 0x7000, during the 30-pair re-measure.
    • Its kernels are ISA-identical to main's, and its outputs are bit-identical whenever it doesn't crash.
    • So the fault is unlikely to be in the MXFP4 tile body.
  • The other eight are MXFP4 claims cases. One was in the round-4 comparison run: w-mxfp4-q4-w4096-b3-c225380, which passed in the two other runs that day. Seven were in a dedicated loop over the 59 MXFP4 claims cases, head against head:
    • rounds 1-9: clean;
    • round 10: 1 crash;
    • round 11: 6 crashes;
    • round 12: cases started to time out (2040 s each).
  • The GPU stayed broken. After the processes were stopped, GPU 3 still did not answer a simple allocation, and dmesg keeps logging vmid:0 faults on it. The AMD_SERIALIZE_KERNEL=3 half of that loop never ran, so I can't confirm the description's "8/8 pass when serialized".

What it points to. It is intermittent, its signature is near-null, it gets more frequent as a process runs longer, and an FP8 case with main's ISA can hit it. That fits host-side state this PR changed for every dtype, more than a tile-kernel bug. Two candidates:

  • a kernel pointer argument that can be 0, for example an optional workspace passed as None, dereferenced on a path that is only sometimes taken;
  • a workspace, counter or flag read before anything writes it. Memory from torch.empty is reused, so what such a read sees depends on what the process allocated before.

Ask before merge:

  • Find the read.
    • Check every pointer the gfx1250 and common host paths pass that can be 0.
    • Check every scratch or plan buffer the kernels read before writing; zero it, or guard the read.
  • Then rerun a long loop of ATOM-style launches, with a cold-KV rotation and two processes on one GPU, at head and at main. The harness runs above can be shared on request.

Notes

  • Method. Same harness and box as the round-4 addendum, on 1-2 of the MI450's 4 GPUs; other users' jobs held the rest. Case builds were serialized per worker. The 30-pair re-measure and its swapped run each had a GPU of their own.
  • Not done this round.
    • The head-only claims were measured but not compared with the PR's table.
    • The B128 × 8k +4.6% would need a 30-pair re-measure on a healthy GPU.

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

FlyDSL PA review (automated harness), round 6

Verdict: no blocking issue. I withdraw the round-5 addendum's "changes needed": the MI450 page fault also happens with main's tree and no code from this PR, and every fault at this head that the runtime attributed to a kernel was in a hipBLASLt GEMM from the test's reference. One minor issue is noted inline. · head 4b0a62f214 (unchanged since round 5) · base = merge-base db3b870ea1 · also checked merged with current main e6d2d3100a (FlyDSL 0.5.3)

Since round 5 the PR has no new commits. On main, the FlyDSL pin moved from 0.5.0 to 0.5.3 (#8356, #8450, #8467), and tensor_shim.py and kernels_common.py changed. The PR merges with main without conflicts. Once merged, its gfx1250 MXFP4 kernels build with FlyDSL 0.5.3, which MI35X CI never exercises, so this round also tests the merged tree.

The MI450 page fault (round-5 addendum): not this PR

I reran the round-5 loop (two harness workers alternating on one GPU, the MXFP4 or FP8 claims group, 3 pairs a round), stopping each variant at its first crash:

GPU tree, cases first crash faulting kernel (runtime / dmesg)
GPU 1 this PR, MXFP4, rocBLAS preferred round 5 not named
GPU 1, next this PR, MXFP4, default (hipBLASLt) round 1 Cijk_Alik_Bljk_S_B_Bias_HA_S_SAV_UserArgs_MT32x32x16_MI16x16x1_… at 0xa000
GPU 0 (no fault loop had run on it) main db3b870ea only, FP8 only round 4 Cijk_Alik_Bljk_S_B_Bias_HA_S_SAV_UserArgs_MT32x32x16_MI16x16x1_… at 0x51ed000; dmesg: GC_UTCL2 no-retry fault, same address
GPU 0, afterwards this PR, MXFP4 round 1 not named
GPU 1, after its first crashes main FP8 / PR FP8 / PR MXFP4 with AMD_SERIALIZE_KERNEL=3 round 1 / 1 / 3 not named
  • The crash with main's tree, FP8 only and no PR code, settles it. That process imported db3b870ea, ran FP8 cases only, and faulted in the same hipBLASLt FP32 GEMM, at a low address, as round 5.
  • Every attribution points at hipBLASLt. Across round 5 and this round, the runtime named a kernel for five faults. Four were in that hipBLASLt FP32 batched GEMM, at low addresses (0x512000, 0xbf8000, 0xa000, and 0x51ed000 above), and none were in a pa_decode kernel of this head. The fifth was in the round-4 head's kernel, at a real address: finding 2, now fixed. The only FP32 batched matmul these processes run is the einsum in the test's _reference, which both trees share.
  • Neither serializing nor switching GEMM libraries prevents it.
    • AMD_SERIALIZE_KERNEL=3 HIP_LAUNCH_BLOCKING=1 also crashed in this loop (round 3). The description's 8/8 serialized passes were pytest runs, a lighter load.
    • TORCH_BLAS_PREFER_HIPBLASLT=0 (rocBLAS preferred) crashed in round 5. The runtime did not name a kernel for that crash.
  • Other users hit it too. The host's dmesg shows two other python3 processes with GPU page faults on GPUs 0 and 1 at 02:38–02:40Z, eight hours before these runs.
  • The PR's kernels write nothing outside their tensors.
    • What I checked: for 133 cases (all 70 MXFP4 claims and review probes, the 62 unit MXFP4 params, and round 5's crashing FP8 grid case), output, exp_sums, max_logits and temporary_output were views inside buffers with 1 MiB of canary bytes on each side.
    • Result: no canary byte changed. Outputs are bit-identical whether those tensors start as zeros or as NaN, so no unwritten scratch is read, and every case passes the test's reference check.
  • So round 5's reading was wrong. I took the different crash counts between the trees as a PR effect. They most likely came from how often a process built cases with large reference GEMMs. This is an MI450 / ROCm 10.1 hipBLASLt problem to track separately. No ask on this PR.

Verification

arch result
gfx942 (MI308X, 80 CUs; first hardware run at this head) PASS.
Geomean head/base: prod 1.000, unit 1.001, grid 1.000, claims 1.000 (FP8 rows; MXFP4 is skipped on gfx942 as designed). Every timed case gives bit-identical outputs (104 prod, 278 unit, 1674 grid, 47 claims).
The first pass flagged 6 cases at +2.6–3.8%, all 9–13 µs. Re-measured at 30 pairs in both orders, they are within ±1.1%.
ISA of the unit kernels: 236/236 identical. A/A band 2.5% (spread 0.7%).
pytest: 414 passed on both sides; the 47 added tests skip.
Merged with main (FlyDSL 0.5.3): 414 passed against main's 414, 0 failures.
gfx1250 (MI450, 256 CUs), merged with main at FlyDSL 0.5.3 PASS.
pytest: merged 480 passed, 0 failed (main: 368 passed). The 47 added tests pass.
Claims, head at 0.5.0 against the merged tree at 0.5.3: all 117 cases give bit-identical outputs. Geomean MXFP4 1.001 (70 cases), FP8 0.992. The first pass flagged three small MXFP4 decode cases at +3.5–4.5%; at 30 pairs in both orders the merged tree is not slower.
FP8 prod, main against merged (both 0.5.3): geomean 0.999, all 104 cases bit-identical, none slower.
Claims against the PR table: MXFP4 measured / PR geomean 1.04 (45 of 56 within +10%), FP8 1.06. On geomean over the 44 MXFP4/FP8 twin cases, MXFP4 is 1.21× faster, exactly the table's 1.21×. MXFP4 is slower in 10 of them, as the table also shows. The largest absolute gap is decode B128 × 8k: 21.1 µs measured against 16.9 µs listed.
FP8/BF16 against main at this head was covered by the round-5 addendum (bit-identical, ISA 433/433).
gfx950 (MI355X) Not verified on hardware. ssh to the cluster's login node timed out on every attempt this round.
Compile-only cross-check on the MI308X box (unit + prod cases): 279/279 kernels have identical ISA at head and base, MXFP4 included.

Code review

  1. [minor] Plan-free MXFP4 with a window near INT32_MAX zero-fills visible rows (inline at pa_decode_kernel.py L1565). Reproduced on MI450; details in the inline comment.

Areas read with nothing found:

  • context 0 in every branch: plan-free, cluster runs/non-runs, wave dims/partials, fused pairs;
  • stale plan slots under fused pairs: the planner zero-fills [total, capacity), and loads clamp to capacity - 1;
  • 64-bit partial, output and K/V offsets at 128K–512K tokens;
  • block-table prefetches, which are clamped;
  • cache keys: every new codegen field is in Gfx1250Traits.

Review state

  • Six of my earlier threads (round 4) are fixed in code but still unresolved, and unresolved threads block the merge.
  • #8289, #8365, #8458, #8459 and #8600 touch the same PA files. Whichever lands second needs a rebase.

@coderfeli
coderfeli merged commit 3fd4259 into main Nov 25, 2026
82 of 83 checks passed
@coderfeli
coderfeli deleted the fsx/pa-gfx1250-mxfp4-kv branch November 25, 2026 14:38
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