Skip to content

[FlyDSL] feat(flydsl): fuse sparse PA output quantization - #7401

Merged
lirui927 merged 10 commits into
ROCm:mainfrom
lirui927:fuse/f4-pa-out-quant
Nov 17, 2026
Merged

lirui927 merged 10 commits into
ROCm:mainfrom
lirui927:fuse/f4-pa-out-quant

Conversation

@lirui927

@lirui927 lirui927 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Consumer: ROCm/ATOM#2949 (MiniMax-M3 sparse attention passes the FP8 output and scale straight to o_proj).

What this PR does

MiniMax-M3's sparse attention output feeds an FP8 o_proj. Today that takes two launches: pa_decode writes BF16, and dynamic_per_token_scaled_quant reads it back to produce FP8 plus a per-token scale. With this PR, the gfx1250 FlyDSL sparse PA writes the FP8 output itself, from the final values in registers.

  1. FP8 per-token output in the PA epilogue. pa_decode gains two optional arguments: quantized_output (OCP FP8, same layout as output) and output_scale (FP32 [tokens, 1]).
    • Values are rounded to BF16 in registers and quantized with the standalone kernel's math. So the FP8 bytes and scales are bitwise equal to PA followed by the standalone quant.
    • Fused scope. gfx1250, one KV head, any GQA size, head_dim, page size, MTP length and sliding window, in all four gfx1250 pipelines. The epilogue quantizes when the plan writes the one-partition direct output or a cluster merge with one sequence per cluster (cluster_seqs == 1), including the step-split and run-split clusters from [FlyDSL] gfx1250 PA decode: wider page-local softmax steps, shared clusters and wave-pair MTP4 for MiniMax-M3 #7619.
    • Fallback. Every other case writes BF16 and then runs the standalone quant, with identical bytes: several KV heads per rank, sinks or the reducer, the last-arriver merge, clusters shared by several sequences, and the query-split BF16 D1024/GQA16/MTP4/page128 tile. The fallback fills the padded rows (below) with zero_()/fill_(1.0) after the quant.
    • store_output=False skips the BF16 store.
    • Calls without the new arguments keep the existing dispatch.
  2. Padded bucket rows. quantized_pad_rows=N writes the N rows past the real tokens as FP8 zeros with descale 1.0, so a token-graph o_proj over the padded bucket reads inert rows. The fused epilogue writes them in the PA launch, so it needs no fill launches.

Benefit

Workload: MiniMax-M3 sparse attention. GQA 16, head_dim 128, page 16, one KV head, FP8 KV and BF16 query. Decode rows have 2048 selected tokens. In direct prefill, row i has min(i + 1, 2048).

Hardware and method: one MI455X (gfx1250), exclusive, in the rocm/fw-bringup:gfx1250-minimax-m3-20261112 image with FlyDSL 0.5.0. Each variant is captured as a CUDA graph of 50 calls, and the three variants are interleaved back to back over 9 repeats. Values are the median per call in µs, with [min-max] across repeats. Measured at 54500a2. The later commits change only the D1024/GQA16/MTP4 dispatch, tests and comments, not these shapes.

Baseline: pa_decode followed by dynamic_per_token_scaled_quant.

rows mode PA + quant (µs) fused, BF16 kept (µs) fused, FP8 only (µs)
4 decode, cluster16 step split 4.73 [4.70-4.80] 3.47 (-27%) [3.45-3.48] 3.41 (-28%) [3.39-3.42]
16 decode, cluster16 step split 5.37 [5.30-5.44] 3.61 (-33%) [3.59-3.65] 3.58 (-33%) [3.56-3.60]
64 decode, cluster8 step split 6.19 [6.16-6.24] 4.84 (-22%) [4.83-4.86] 4.74 (-23%) [4.73-4.76]
2517 direct prefill 62.78 [61.95-64.33] 64.07 (+2%) [63.61-65.49] 61.93 (-1%) [61.15-63.56]
4536 direct prefill 139.79 [126.65-142.81] 140.73 (+1%) [129.78-144.48] 135.58 (-3%) [125.57-139.05]

In every row the fused path selected the fused epilogue, and its FP8 bytes and descales matched PA + quant bit for bit. Decode, where the removed launch is a large share of the time, gains 22-33%. Prefill is within noise: -1% to -3% with FP8 only, +1% to +2% with BF16 kept. The descale exchange costs about what the removed quant kernel did there. The win is mainly the one launch fewer per layer in the prefill token graph, plus the padded-row fills. These prefill rows use a heavier length profile than the earlier description's table, so the absolute times are not comparable with it.

The 7-13% slowdown in the Nov 4 close comment was measured with the first epilogue. That version re-read the BF16 output from global memory and synced three times. The register epilogue measured here, now part of eb8bd71, replaced it.

The query-split BF16 D1024/GQA16/MTP4/page128 tile is not fused on purpose. Unsplit, it spills: with FP8 output, PA + quant on the split tile takes 295-1576 µs, against 1679-9122 µs for the fused unsplit tile (5.8x; 1-64 sequences at 2048 tokens and 4 at 8192, one MI455X, interleaved CUDA graphs).

Testing

On MI455X (gfx1250): python3 -m pytest -q op_tests/test_flydsl_pa_decode.py: 336 passed, 159 skipped (the skips are arch-gated cases such as gfx950-only MXFP4). gfx1250 coverage is manual only, because CI is MI35X.

  • test_pa_decode cases tagged quant run the FP8 output. They cover:
    • the M3 decode and cluster shapes (cluster8 and cluster16 step splits);
    • GQA 6-32, head_dim 64-256, pages 16/128, MTP 4/5 and a sliding window;
    • the fallbacks: several KV heads, the last-arriver merge, shared clusters (cluster2-shared) and the query-split D1024 tile (head1024-mtp4-g16-page128).
  • For each case, the test poisons the outputs, then checks:
    • FP8 bytes and scales against PA + the standalone quant, bit for bit;
    • the BF16 output, or that it is untouched with store_output=False;
    • that padded rows are zero with scale 1;
    • that the fused kernel is selected where it applies;
    • graph replay with new query values.
  • test_pa_decode_quant_empty_long_query: an empty sequence with query_length 129 (BF16 KV, GQA 1, D256, direct path) writes all of its descales. It fails without the fix.
  • Invalid-argument cases check that pa_decode refuses, before any kernel compiles: only one of quantized_output/output_scale, store_output=False without the FP8 output, a negative or bool quantized_pad_rows, pad rows without the FP8 output, and (gfx1250) a quantized_output missing its pad row, a BF16 quantized_output, a [rows] output_scale and an FP16 output_scale.
  • On gfx942/gfx950 (MI35X CI), the same cases assert that the FP8 output raises NotImplementedError. This check was not run here, because no gfx950 GPU was available.

Not covered

  • Fusing several KV heads per rank. It is structural: a token's scale needs every KV head's values, which are in different CTAs. Those calls use the fallback.
  • Clusters shared by several sequences. These are batches with more sequences than 15 clusters per 16 CUs, and they use the fallback.
  • Dense-attention output quantization.
  • Empty sequences whose tokens have 128 values or fewer (GQA 1-2 at D64, GQA 1 at D128). For those widths the standalone quant floors the amax at 1e-10, giving descale 2.2e-13 and FP8 zeros. The fused path gives descale 0 and 0xFE bytes, the standalone's result from 256 values up. Both dequantize to 0, but they are not bitwise equal.
  • gfx942/gfx950, where the new arguments raise.
  • End-to-end MiniMax-M3 numbers are in the stacked launch-cache PR ([FlyDSL] perf(flydsl): launch a repeated gfx1250 pa_decode call without re-checking it #7869).

PR Self-Review

Reviewed revision

5c68d29

Behavior and intent

On gfx1250, pa_decode gains an optional per-token FP8 output (quantized_output, output_scale, store_output, quantized_pad_rows) for MiniMax-M3's FP8 o_proj. Before, this took PA plus a separate dynamic_per_token_scaled_quant launch that read the BF16 output back. The output is quantized in the tile epilogue when there is one KV head, the tile has no query split, and the plan writes the one-partition direct output or a cluster merge with cluster_seqs == 1. Other plans fall back to PA + the standalone quant. Both paths give the same bytes. Calls without the new arguments are unchanged; gfx942/gfx950 raise NotImplementedError for them.

Validation and unverified scope

Validated on one MI455X (gfx1250) in rocm/fw-bringup:gfx1250-minimax-m3-20261112: python3 -m pytest -q op_tests/test_flydsl_pa_decode.py, 336 passed, 159 skipped. Perf: see Benefit (decode -22..-33%, prefill within noise).

Remains unverified: gfx942/gfx950 (the refusal check runs only in MI35X CI), multi-GPU and end-to-end runs (#7869), gfx1250 in CI (no runner).

PR-specific question

What would the changed op test fail on before this PR, and why does no existing test cover it? Before this PR, pa_decode has no quantized_output/output_scale, so every quant-tagged case fails on the call. That covers the M3 decode and cluster shapes, the fallbacks (multi-KV-head, last-arriver, cluster2-shared, head1024-mtp4-g16-page128) and test_pa_decode_quant_empty_long_query. On gfx942/gfx950, the case that expects NotImplementedError fails for the same reason. No existing canonical test checks a fused PA FP8 output against dynamic_per_token_scaled_quant, because the feature is new.

Changed op tests

op_tests/test_flydsl_pa_decode.py: this is the canonical PA decode test. The FP8 output is added there rather than in a new file. quant tags on existing cases, such as the M3 cluster8/cluster16 step splits and cluster2-shared, and on one new short case, head1024-mtp4-g16-page128, run _check_quant_output. Each tag pins the expected path, "fused" or "fallback", the way cluster/cluster_steps pin the pipe policy. It checks the FP8 bytes and scales against PA + quant bit for bit, the BF16 store or its skip, the padded rows, that the dispatch takes the pinned path (so a plan that silently stops fusing fails), and graph replay. test_pa_decode_quant_empty_long_query covers the descales of an empty sequence longer than a CTA. That failed before the fix. _INVALID_CASES entries cover the new argument errors, including either FP8 tensor without the other and a wrong shape or dtype of quantized_output or output_scale. On gfx942/gfx950 the same cases check that the FP8 output is refused. No existing test covers the FP8 output, because the feature is new.

lirui927 pushed a commit to lirui927/aiter that referenced this pull request Nov 4, 2026
Reverts 4c56e4d and 15777c9 (ROCm#7401). Exclusive single-GPU
A/B: the fused PA is 7-13% slower than PA plus the standalone quant at
decode rows 4/16/64 and prefill rows 2517/4536; the epilogue costs more
than the kernel it removes.
See wuhuikx/LLM-Booster#393 (issuecomment-6622356568).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
lirui927 pushed a commit to lirui927/ATOM that referenced this pull request Nov 4, 2026
Reverts fff6a74 (ROCm#2949), the ATOM side of the F4 fusion whose
aiter kernel (ROCm/aiter#7401) is removed from the integration stack: in
an exclusive single-GPU A/B the fused PA is 7-13% slower than PA plus the
standalone quant. Keeps F5: the sparse attention still passes the
registered AR alias (out=) to o_proj and exposes supports_out. Drops the
F4 unit test, including the F4+F5 alias case added with F5.
See wuhuikx/LLM-Booster#393 (issuecomment-6622356568).

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

lirui927 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Closing after exclusive single-GPU A/B failed the performance gate. Fused PA quant is 7-13% slower than base PA + standalone quant across decode rows 4/16/64 and prefill rows 2517/4536; correctness is bitwise, but the fused epilogue costs more than the kernel it removes. Evidence: wuhuikx/LLM-Booster#393 issuecomment-6622356568. Removed from integration.

@lirui927 lirui927 closed this Nov 4, 2026
@lirui927 lirui927 reopened this Nov 4, 2026
@lirui927
lirui927 force-pushed the xiaobingsuper/m3-mi455-perf-stack branch from 2c8902d to 3499407 Compare November 10, 2026 07:46
lirui927 pushed a commit to lirui927/ATOM that referenced this pull request Nov 10, 2026
Reverts fff6a74 (ROCm#2949), the ATOM side of the F4 fusion whose
aiter kernel (ROCm/aiter#7401) is removed from the integration stack: in
an exclusive single-GPU A/B the fused PA is 7-13% slower than PA plus the
standalone quant. Keeps F5: the sparse attention still passes the
registered AR alias (out=) to o_proj and exposes supports_out. Drops the
F4 unit test, including the F4+F5 alias case added with F5.
See wuhuikx/LLM-Booster#393 (issuecomment-6622356568).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lirui927
lirui927 force-pushed the fuse/f4-pa-out-quant branch 2 times, most recently from 3733697 to ddd2ed0 Compare November 12, 2026 04:46
@lirui927
lirui927 changed the base branch from xiaobingsuper/m3-mi455-perf-stack to main November 12, 2026 04:46
@lirui927
lirui927 force-pushed the fuse/f4-pa-out-quant branch from dd64ed8 to 990e750 Compare November 12, 2026 08:44
@lirui927
lirui927 marked this pull request as ready for review November 12, 2026 08:50
@lirui927
lirui927 requested a review from a team November 12, 2026 08:50
@github-actions github-actions Bot changed the title feat(flydsl): fuse sparse PA output quantization [FlyDSL] feat(flydsl): fuse sparse PA output quantization Nov 12, 2026
@aiter-bot

aiter-bot commented Nov 12, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 5c68d296db8e · mode shadow

Author self-review accepted. Readiness report:

Author answers

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

Behavior and intent

On gfx1250, `pa_decode` gains an optional per-token FP8 output (`quantized_output`, `output_scale`, `store_output`, `quantized_pad_rows`) for MiniMax-M3's FP8 `o_proj`. Before, this took PA plus a separate `dynamic_per_token_scaled_quant` launch that read the BF16 output back. The output is quantized in the tile epilogue when there is one KV head, the tile has no query split, and the plan writes the one-partition direct output or a cluster merge with `cluster_seqs == 1`. Other plans fall back to PA + the standalone quant. Both paths give the same bytes. Calls without the new arguments are unchanged; gfx942/gfx950 raise `NotImplementedError` for them.

Validation and unverified scope

Validated on one MI455X (gfx1250) in `rocm/fw-bringup:gfx1250-minimax-m3-20261112`: `python3 -m pytest -q op_tests/test_flydsl_pa_decode.py`, 336 passed, 159 skipped. Perf: see Benefit (decode -22..-33%, prefill within noise).

Remains unverified: gfx942/gfx950 (the refusal check runs only in MI35X CI), multi-GPU and end-to-end runs (#7869), gfx1250 in CI (no runner).

PR-specific question

What would the changed op test fail on before this PR, and why does no existing test cover it? Before this PR, `pa_decode` has no `quantized_output`/`output_scale`, so every quant-tagged case fails on the call. That covers the M3 decode and cluster shapes, the fallbacks (multi-KV-head, last-arriver, `cluster2-shared`, `head1024-mtp4-g16-page128`) and `test_pa_decode_quant_empty_long_query`. On gfx942/gfx950, the case that expects `NotImplementedError` fails for the same reason. No existing canonical test checks a fused PA FP8 output against `dynamic_per_token_scaled_quant`, because the feature is new.

Changed op tests

`op_tests/test_flydsl_pa_decode.py`: this is the canonical PA decode test. The FP8 output is added there rather than in a new file. `quant` tags on existing cases, such as the M3 cluster8/cluster16 step splits and `cluster2-shared`, and on one new short case, `head1024-mtp4-g16-page128`, run `_check_quant_output`. Each tag pins the expected path, `"fused"` or `"fallback"`, the way `cluster`/`cluster_steps` pin the pipe policy. It checks the FP8 bytes and scales against PA + quant bit for bit, the BF16 store or its skip, the padded rows, that the dispatch takes the pinned path (so a plan that silently stops fusing fails), and graph replay. `test_pa_decode_quant_empty_long_query` covers the descales of an empty sequence longer than a CTA. That failed before the fix. `_INVALID_CASES` entries cover the new argument errors, including either FP8 tensor without the other and a wrong shape or dtype of `quantized_output` or `output_scale`. On gfx942/gfx950 the same cases check that the FP8 output is refused. No existing test covers the FP8 output, because the feature is new.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

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.

Comment thread aiter/ops/flydsl/pa_decode.py Resolved
@lirui927
lirui927 requested a review from fsx950223 November 13, 2026 09:04

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Action required before merge (5)

  1. Comment the raw cvt_pk_fp8_f32 call, or reuse the shared helper. aiter/ops/flydsl/kernels/pa_decode/op_merge.py:463 (_store_fp8). The FlyDSL AGENTS.md rule requires a comment at each raw rocdl call naming the missing typed API. The nearby comment only describes the saturation. Either add the same note fp8_quant_gfx1201.py:184 carries (no typed packed-FP8 conversion in FlyDSL), or extend kernels/quant_utils.py:emit_f32_to_fp8 with the old-word/word_sel arguments and call it here.
  2. Reconcile the perf evidence with your own Nov 4 close comment. That comment says an exclusive single-GPU A/B found the fused PA quant 7-13% slower at the same rows 4/16/64/2517/4536. The table now shows 23-27% faster. In the description, name the commit that changed the result (presumably 083bb8bd2f, quant from registers) and confirm the new numbers come from the same exclusive back-to-back A/B at this head.
  3. Answer the aiter-bot PR Self-Review. It is still WAITING ON AUTHOR. The description lacks Reviewed revision (3b3b556), Behavior and intent, Validation and unverified scope, PR-specific question and Changed op tests.
  4. Give CI something to run. Every new check sits behind case["quant"] and arch == "gfx1250" (op_tests/test_flydsl_pa_decode.py:2025). CI is MI35X only, so none of this PR's code runs in CI. Add a gfx942/gfx950 case that asserts pa_decode(..., quantized_output=..., output_scale=...) raises NotImplementedError (aiter/ops/flydsl/pa_decode.py:804). Also state in the description that gfx1250 coverage is manual only (251 passed on MI455X).
  5. Fix two inaccurate messages.
    • op_merge.py:418 and :561 say the first partition's pmax entry of a row is read only by its owner wave. In fact the padding rows of other waves, clamped to t.rows - 1 at op_merge.py:310-311, also load it before the cluster barrier. The result is harmless because those rows are discarded, but the comment should say so.
    • pa_decode.py:839 says "contiguous query/output tensors", but the check also covers quantized_output.

Reviewed at 3b3b556. Earlier asks already fixed: the new test file is folded into test_flydsl_pa_decode.py, and the fused condition is widened to any GQA, D, page size and MTP (fsx950223).

@fsx950223 fsx950223 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 3b3b556 and the complete six-file merge-base diff. No concrete blocking defect was identified. Essential validation remains unavailable: the fused epilogue targets gfx1250, which is not configured, and the targeted gfx950 regression attempt stopped at import because the container has FlyDSL 0.4.0 while this commit requires ≥0.5.0. MI35X CI passed the existing PA suite, but the new quantization assertions are gated to gfx1250. Independent gfx1250 correctness, graph replay, and targeted performance validation are needed before approval.

Validation:

  • PASS on local: git -C checkout rev-parse HEAD; parse all six changed Python files with ast.parse
    HEAD matched the supplied SHA; all changed files parsed successfully. Evidence saved in local-validation.log.
  • FAIL on dzm-mi355-gpu34-dev / allocation 9581 / fsx950223_pr_review_gfx950: srun --overlap --jobid=9581 --ntasks=1 --cpus-per-task=1 podman exec -i fsx950223_pr_review_gfx950 flock -w 30 /workspace/gpu.lock bash -s < remote-test.sh
    Verified gfx950 and idle devices, then used an isolated exact-head source archive and AITER compilation directory. Import exited 1: Unsupported flydsl version: expected >=0.5.0, got 0.4.0. The planned timeout 240 python3 -m pytest -q op_tests/test_flydsl_pa_decode.py -k 'test_pa_decode and bf16-decode' did not execute. Logs: gfx950-env.log, gpu-activity.log, gfx950-test.log.
  • PASS on hjbog-srdc-39.amd.com / sixifang_dev: docker exec sixifang_dev python3 -c 'import torch,flydsl; print(torch.cuda.get_device_properties(0).gcnArchName); print(flydsl.__version__,flydsl.__file__)'
    Verified gfx942 and FlyDSL 0.4.0 inside the container. Log saved in gfx942-env.log.
  • SKIP on gfx942 / gfx1250: Targeted PA correctness and output-quantization tests
    gfx942 has the same unsupported FlyDSL dependency and cannot validate the gfx1250 fused implementation. No gfx1250 test environment is configured.

Remaining validation:

  • The author's reported 251 passing gfx1250 tests and performance measurements were not independently reproduced.
  • CI logs show the PA suite passed on MI35X; new output-quantization assertions did not run on that architecture. Detailed CI and review evidence are preserved in the task directory.
  • The gfx950 architecture-rejection check and unchanged-path GPU regression remain unexecuted because the exact-head import failed. No global dependencies were upgraded.

Automated Codex review of commit 3b3b5566633f.

@fsx950223 fsx950223 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 3b3b556 and the complete six-file merge-base diff. Found an unwritten output-scale tail for empty sequences with MTP lengths above 128. Independent gfx1250 validation remains unavailable.

[P2] Write all empty-sequence scales when query_length exceeds 128 — aiter/ops/flydsl/kernels/pa_decode/op_merge.py:626

store_empty writes at most one scale per thread, but BLOCK_THREADS is 128 and tokens is the unrestricted query_length when zero_output handles an empty sequence. For example, gfx1250 BF16 KV, GQA 1, head_dim 64, page size 16, query_length=129, max_partitions=1 and context lengths [129, 0] select the fused direct path. The empty sequence's final scale is never written, although its FP8 values are written. A scale buffer poisoned with NaN therefore leaves the last token's descale NaN, causing downstream dequantization or o_proj to produce NaNs instead of an inert output. Use a block-strided loop for scale stores and cover an empty sequence with query_length > BLOCK_THREADS.

Validation:

  • PASS on local: git -C checkout rev-parse HEAD; parse all six changed Python files with ast.parse
    HEAD matched the supplied SHA; all six files parsed. Saved in head-sha.txt and local-validation.log.
  • PASS on local: AST inspection and enumeration of store_empty scale writers for BLOCK_THREADS=128 and tokens=129
    Confirmed the final guard is tid < tokens with one store per thread; scale row 128 has no writer. Source-level reproduction saved in empty-scale-repro.log and review-notes.txt.
  • FAIL on dzm-mi355-gpu34-dev / allocation 9589 / fsx950223_pr_review_gfx950: srun --overlap --jobid=9589 --ntasks=1 --cpus-per-task=1 podman exec -i fsx950223_pr_review_gfx950 flock -w 30 /workspace/gpu.lock bash -s < remote-import.sh
    Verified gfx950 inside the container. Isolated exact-head source and JIT cache were used. Import resolved to that source but exited 1: expected FlyDSL >=0.5.0, got 0.4.0. The targeted pytest command did not execute. Log: gfx950-import.log.
  • PASS on hjbog-srdc-39.amd.com / sixifang_dev: docker exec sixifang_dev python3 -c 'import torch,flydsl; print(torch.cuda.get_device_properties(0).gcnArchName); print(flydsl.__version__,flydsl.__file__)'
    Verified gfx942 and FlyDSL 0.4.0 inside the container. Log: gfx942-env.log.
  • SKIP on gfx942 / gfx950 / gfx1250: Targeted PA correctness, architecture rejection, fused quantization and graph-replay tests
    Configured hosts lack the required FlyDSL version; no gfx1250 environment is configured. No GPU correctness or performance result is claimed.

Remaining validation:

  • The reported defect is established by source-level bounds analysis; it was not reproduced on gfx1250 hardware.
  • The author's reported gfx1250 correctness and performance results were not independently reproduced.
  • CI metadata shows failing MI35X test shards. Read-only log requests returned empty logs, so their causes could not be attributed to this diff. New quantization assertions are gated to gfx1250.
  • Remote setup retries encountered archive permission errors and a missing amdsmi activity-probe dependency; detailed logs are preserved in the task directory.

Automated Codex review of commit 3b3b5566633f.

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

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

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

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

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lirui927
lirui927 requested a review from valarLip November 16, 2026 14:52
lirui927 pushed a commit to lirui927/ATOM that referenced this pull request Nov 16, 2026
MiniMax-M3's sparse attention wrote a BF16 output that o_proj then quantized
to per-token FP8 in a launch of its own, once per sparse layer and step. With
ROCm/aiter#7401 FlyDSL's pa_decode can write that FP8 output and its FP32
descales itself (fused into its direct and eight-CTA cluster merges, after
the merge otherwise), skip the BF16 store, and write rows past the queries as
FP8 zeros with a unit descale.

- MiniMaxM3SparseAttention hands o_proj the PA's FP8 rows and descales
  (Attention.forward_quantized -> unified_attention_with_output_quant_base)
  when o_proj consumes per-token FP8, checked at forward because online
  quantization re-quantizes o_proj at load.
- The gate needs gfx1250, ATOM_PA_FLYDSL, one KV head, GQA16, head_dim 128,
  ATOM's own Attention outside Ulysses SP (whose head exchange runs in
  forward), a non-MXFP4 KV cache, and an aiter pa_decode that takes all four
  kwargs (_flydsl_output_quant_api). Otherwise nothing changes: the PA
  writes BF16 and o_proj quantizes it.
- sparse_pa_per_row never takes ASM for it; prefill rows with a split
  other than eight run one partition per token (the fused direct kernel),
  decode rows keep their split. The rows the sparse impl pads past its
  metadata (a DP step) are the PA's inert pad rows.

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

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Action required before merge (3)

  1. Get the MI35X Standard Tests green at this head. All 8 shards at 45b6c77 failed before any test ran: Docker Hub returned toomanyrequests: You have reached your unauthenticated pull rate limit. This is not caused by the PR, but these shards are the only CI that runs the new gfx942/gfx950 NotImplementedError check, so they need a green rerun.
  2. Drop the inspect.signature filter in _check_quant_output. op_tests/test_flydsl_pa_decode.py:2295-2306 filters the compile kwargs through inspect.signature(gfx1250_tile_traits) and repeats the fused predicate from aiter/ops/flydsl/pa_decode.py:1201-1205. Put the predicate in one small helper in pa_decode.py (num KV heads, one-partition direct or cluster_seqs == 1 cluster, query_splits == 1). Call it from the host dispatch and from the test, and remove import inspect. Then the test cannot drift from the dispatch, and nothing is filtered silently.
  3. Clear the aiter-bot self-review check. The section is now in the description at 45b6c77 (thanks), but the bot still reports FAIL — validation answer must explicitly state what remains unverified. Reword the second paragraph of ### Validation and unverified scope so it starts "Remains unverified: gfx942/gfx950 …, multi-GPU and end-to-end runs (#7869), gfx1250 in CI (no runner)".

Nits:

  • The _check_quant_output docstring (test_flydsl_pa_decode.py:2288-2290) leaves out the cluster_seqs == 1 condition.
  • No test covers the new argument errors at pa_decode.py:600-617: only one of quantized_output/output_scale, store_output=False without them, and a negative or bool quantized_pad_rows, or pad rows without the FP8 output. These could be a few _INVALID_CASES entries.

Re-reviewed at 45b6c77. Already fixed: the pa_decode docstring now matches the dispatch (one KV head, no query split, one-partition direct or cluster_seqs == 1), and the fallback's pad-row fill is documented; the query-split D1024/G16/MTP4 tile now falls back to the split tile + standalone quant instead of forcing query_splits=1 (pa_decode.py:1204, new head1024-mtp4-g16-page128 quant case); cluster2-shared is tagged quant; the redundant stride check is removed; the description names eb8bd718; earlier: cvt_pk_fp8_f32 comment, perf reconciliation, gfx942/gfx950 refusal test, pmax/contiguity messages, empty-sequence descales (fsx950223 P2).

… the test

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

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>
lirui927 pushed a commit to lirui927/ATOM that referenced this pull request Nov 16, 2026
MiniMax-M3's sparse attention wrote a BF16 output, which a per-token FP8
o_proj then quantized in a launch of its own. With ROCm/aiter#7401, FlyDSL's
pa_decode writes the FP8 rows and their FP32 descales itself.

`Attention.per_token_fp8_out`, which already hands o_proj an `(out, scale)`
pair under Ulysses SP, now also covers an impl whose kernel writes that pair
(`supports_output_quant`, False on the base impl), through the new op
`unified_attention_fp8`. The sparse impl sets it on a GPU without gluon (its
sparse PA is FlyDSL's on every call), over an FP8 KV cache and with one KV
head per rank. The PA skips the BF16 store and writes rows past the queries
as FP8 zeros with a unit descale. The plan stays as it was; aiter picks the
fused epilogue where that plan allows and quantizes after the merge
elsewhere, with the same bytes.

Needs aiter with #7401: ATOM calls its kwargs without probing for them.

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

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Action required before merge (2)

  1. Get the MI35X Standard Tests green at d410eb6. Attempt 1 of "Aiter Test" at this head was cancelled during the wheel build, so the Test Gate failed and aiter-bot still says NOT READY. Attempt 2 is running, but all 8 MI35X shards are still queued. These shards are the only CI that runs the new gfx942/gfx950 NotImplementedError check and the new _INVALID_CASES entries, so they must pass before merge.

  2. Make the fused-path assertion independent of fuses_quant_output. Sharing the predicate between the dispatch (aiter/ops/flydsl/pa_decode.py:1218) and the test fixed the inspect.signature filter (thanks). Two problems remain:

    • _check_quant_output (op_tests/test_flydsl_pa_decode.py:2316-2328) rebuilds tile_options by deleting a hand-written list of seven compile kwargs. That list is a second copy of how pa_decode.py:1236-1251 builds them.
    • :2362 then checks that the dispatch's quant_output equals fuses_quant_output on the same inputs. That always holds, so the check is tautological. If a plan falls back when it should fuse, the bytes stay identical and nothing fails. That is the silent perf regression this assertion exists to catch.

    Fix: pin the path in the case, as _check_pipe_policy (:1831) already does for cluster/cluster_steps: e.g. "quant": "fused" or "quant": "fallback". Assert compile_kwargs[-1].get("quant_output", False) == (case["quant"] == "fused"), and delete the reconstruction. If fuses_quant_output is then used only by the dispatch, make it private (_fuses_quant_output).

Nits (non-blocking):

  • The FP8 shapes in pa_decode.py:478-479 (same shape/strides as output, [num_seqs * query_length, 1]) and in the docstring at :513-516 leave out the quantized_pad_rows extra rows that :865-884 requires.
  • The store_empty docstring (kernels/pa_decode/op_merge.py:611-614) says "FP8 zeros". With descale 0, an empty sequence gets 0xFE bytes, as the description says, not zeros.
  • _INVALID_CASES covers output_scale without quantized_output (scale-only), but not the reverse (quantized_output without output_scale).

Re-reviewed at d410eb6. Already fixed: the inspect.signature filter and the hand-copied predicate are gone, and the dispatch and test now share fuses_quant_output (dispatch unchanged: one_partition_output == direct_output and num_partitions == 1, pa_decode.py:1105). aiter-bot accepts the self-review answers ("Remains unverified: ..."). The _check_quant_output docstring names cluster_seqs == 1. Five new _INVALID_CASES cover the new argument errors before compile, on every arch. The branch merges cleanly into current main. Earlier: docstring/dispatch match, query-split fallback, cluster2-shared quant, cvt_pk_fp8_f32 comment, perf reconciliation, gfx942/gfx950 refusal test, pmax/contiguity messages, empty-sequence descales (fsx950223 P2).

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

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

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

@fsx950223 fsx950223 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head f19082f and the complete six-file merge-base diff. No new blocking defect was established. The previously reported empty-sequence scale tail is addressed by the block-strided store loop and a query_length=129 regression test. Essential GPU validation remains incomplete: no gfx1250 environment is configured, gfx942 import fails on the installed FlyDSL version, and gfx950 allocation discovery timed out. Independent fused-output correctness, graph replay, and targeted performance validation are still needed before approval.

Validation:

  • PASS on local: git -C checkout rev-parse HEAD; AST-parse all six changed Python files; enumerate empty-scale loop writers for 129 tokens
    HEAD matches the supplied SHA; all six files parse; the revised loop covers all 129 scale rows. Logs: head-sha.txt, local-validation.log.
  • PASS on hjbog-srdc-39.amd.com / sixifang_dev: docker exec sixifang_dev python3 -c 'import torch,flydsl; print(torch.__version__); print([(i,torch.cuda.get_device_properties(i).gcnArchName) for i in range(torch.cuda.device_count())])'; docker exec sixifang_dev rocm-smi --showuse
    Verified gfx942 inside the container; all eight devices reported 0% utilization. Log: gfx942-discovery.log.
  • FAIL on hjbog-srdc-39.amd.com / sixifang_dev: docker exec -i sixifang_dev flock -w 30 /tmp/codex-pr-review-7401-20261117-f19082f/gpu.lock bash -s < remote-test.sh
    Exact-head source and isolated compilation caches were used with HIP_VISIBLE_DEVICES=0. Import resolution pointed to the intended checkout, but import exited 1: expected FlyDSL >=0.5.0, got 0.4.0. The planned timeout 240 python3 -m pytest -q op_tests/test_flydsl_pa_decode.py -k 'test_pa_decode and bf16-decode' did not execute. Log: gfx942-test.log.
  • FAIL on dzm-mi355-gpu34-dev: ssh -o BatchMode=yes -o ConnectTimeout=10 -o RequestTTY=no -o ControlMaster=no -o ControlPath=none -o RemoteCommand=none dzm-mi355-gpu34-dev "squeue -h -u zhiming_ding_qle -o '%i|%N|%t'"
    SSH connection to aac16.amd.com:22 timed out before allocation discovery. Log: gfx950-discovery.log.
  • SKIP on gfx1250: Targeted fused quantization correctness, padded-row, graph-replay, and performance tests
    No configured gfx1250 test environment is available. The author's reported MI455X results were not independently reproduced.

Remaining validation:

  • No GPU correctness test completed on this revision; gfx942/gfx950 cannot validate the gfx1250 fused epilogue.
  • CI metadata showed successful and failed MI35X shards with the workflow still in progress. Retrieved shard logs do not establish completion of the changed PA suite or gfx1250 coverage.
  • Detailed source, review feedback, CI evidence, commands, and test logs are preserved in the task directory.

Automated Codex review of commit f19082f60c39.

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Action required before merge (1)

  1. Re-run the failed "Aiter Test" and "OPUS Test" jobs at f19082f. Five of the eight MI35X Standard Tests shards (1, 2, 3, 4, 6) and OPUS Tests (MI35X) died before any test ran. Docker Hub returned toomanyrequests (unauthenticated pull rate limit, exit 125). This is infra, not this PR. The shard that runs op_tests/test_flydsl_pa_decode.py (shard 5) passed: 452 passed, 39 skipped. That run includes the gfx942/gfx950 NotImplementedError check and the new _INVALID_CASES. The Aiter Test Gate is still red, so aiter-bot reports NOT READY and the merge is blocked until a re-run goes green.

Nit (non-blocking):

  • aiter/ops/flydsl/pa_decode.py:525 says clusters are shared at "more than 15 sequences per 16 CUs". The trigger at :1120 is ceil(num_seqs / cluster_seqs) * num_kv_heads > CUs * 15 // 16, so it counts sequences times KV heads. Suggested wording: "more than 15 sequence-KV-head pairs per 16 CUs".

@fsx950223: your CHANGES_REQUESTED review (@3b3b556) is still standing. Its P2 (descales of an empty sequence longer than a CTA) is fixed in op_merge.py and covered by test_pa_decode_quant_empty_long_query. Please re-review.


Re-reviewed at f19082f. Already fixed: each quant case now pins "quant": "fused" / "fallback", and _check_quant_output asserts quant_output == (case["quant"] == "fused") with no tile-option reconstruction. Each pin matches the dispatch: kv_heads 2, the budget-1 last-arriver merge, cluster_seqs == 2 and the D1024 query split fall back; direct and cluster_seqs == 1 cluster plans fuse. The predicate is now private _fuses_quant_output. The FP8 shape comments and docstring name quantized_pad_rows. The store_empty docstring now says 0xFE for descale 0 and FP8 zeros for descale 1. The new fp8-only invalid case raises before compile on every arch. Earlier: shared predicate, inspect.signature removed, self-review answers, docstring/dispatch match, query-split fallback, cluster2-shared, refusal test, empty-sequence descales.

@lirui927

Copy link
Copy Markdown
Contributor Author

Replies to the re-reviews since 54500a2. The head is now 3758a8b.

Re-review at 54500a2 → 45b6c77

  • 1. PR Self-Review. I added the section with the bot's five headings. Its content is copied from the description. ### Changed op tests explains op_tests/test_flydsl_pa_decode.py.

  • 2. pa_decode docstring. It now gives the exact condition from the dispatch. The epilogue quantizes when there is one KV head, the tile does not split its query rows, and the plan writes either the one-partition direct output or a cluster merge with cluster_seqs == 1. Everything else falls back: several KV heads, the last-arriver merge, shared clusters, the reducer (sinks included) and the query-split D1024 tile. The pad-row sentence now says that the fallback writes those rows with zero_()/fill_(1.0) after the standalone quant, and that only the fused path writes them in the PA launch. On ATOM#2949: its comment says aiter fuses only "direct + eight-CTA cluster" merges. That is wrong, because aiter also fuses cluster2/4/16 with cluster_seqs == 1. Its decode rule (8 partitions with a budget of 8 * rows for up to 240 rows) also caps the plan at 8 slots per row. Up to 16 rows on 256 CUs, that turns the fused cluster16 step split into cluster8.

  • 3. Shared-cluster fallback. cluster2-shared is now tagged "quant": True. It runs with FP8 and BF16 KV, checks the FP8 bytes and scales against PA + quant, and checks the padded rows and graph replay. It also asserts that the fallback was selected.

  • 4. D1024 split. The and not quant_output override is gone, so the tile keeps query_splits=4. quant_after_output now also requires gfx1250_tile_traits(...).query_splits == 1. The kernel's own check still refuses a split tile with quant_output. The new BF16 case head1024-mtp4-g16-page128 ("quant": True) covers the shape. The test's fused/fallback expectation now includes the query split.
    Measured on one MI455X with BF16 KV, D1024, GQA 16, MTP4, page 128 and one partition (direct). The old path is the unsplit tile with the fused epilogue (54500a2). The new path is the split tile plus the standalone quant. Each variant is a CUDA graph of 20 calls, interleaved over 9 repeats; values are the median µs per call, FP8 only:

    seqs x ctx old fused (µs) new split + quant (µs)
    1 x 2048 1679 295 (-82%)
    4 x 2048 1719 297 (-83%)
    16 x 2048 1923 333 (-83%)
    64 x 2048 2452 416 (-83%)
    4 x 8192 9122 1576 (-83%)

    With BF16 kept the result is the same (1740 vs 295 at 1 x 2048). The spread is within 1% except for the 8192 row, which is within 5%. FP8 bytes and scales are bitwise equal between the two paths. So keeping the split is about 5.8x faster, and 54500a2 regressed this shape with FP8 output.

  • Nit, stride check. Removed. The shape check makes quantized_output equal output plus the pad rows, and the contiguity check that follows covers the strides. The two can differ only on size-1 dims, which the kernel never strides over.

  • Nit, 083bb8bd. The description now names eb8bd71.

  • MI35X Standard Tests. These will run on the new head. I have no gfx950 GPU here, so the refusal check and the new head1024-mtp4-g16-page128 case were not run on gfx942/gfx950 locally.

Re-review at 45b6c77 → d410eb6

  • 1. MI35X Standard Tests. I requested a rerun of the shards that failed on the Docker Hub pull rate limit. That is an infra issue, not a PR change; the gfx942/gfx950 NotImplementedError check runs in those shards.
  • 2. Fused predicate. aiter/ops/flydsl/pa_decode.py now has one helper, fuses_quant_output(tile_options, cluster_merge=..., cluster_seqs=...): one KV head, the one-partition direct output or a cluster merge with cluster_seqs == 1, and gfx1250_tile_traits(**tile_options).query_splits == 1. The host dispatch and _check_quant_output both call it. The test passes the plain launch's compile arguments minus the compile-only keys it names, so a new argument makes the traits call raise instead of being dropped. The inspect.signature filter and import inspect are gone. The dispatch is unchanged: every quant-tagged case selects the same fused or fallback path as at 45b6c77.
  • 3. Self-review check. The second paragraph of ### Validation and unverified scope now starts "Remains unverified: gfx942/gfx950 (the refusal check runs in MI35X CI), multi-GPU and end-to-end runs ([FlyDSL] perf(flydsl): launch a repeated gfx1250 pa_decode call without re-checking it #7869), gfx1250 in CI (no runner)".
  • Nit, docstring. _check_quant_output now names the cluster_seqs == 1 condition.
  • Nit, argument errors. Five _INVALID_CASES entries cover them: output_scale without quantized_output, store_output=False without the FP8 output, quantized_pad_rows of -1 and of True, and pad rows without the FP8 output. Each must raise before any kernel compiles.

Re-review at d410eb6 → f19082f

  • Fused-path assertion (item 2): each quant case now pins its path, "quant": "fused" or "quant": "fallback", like cluster/cluster_steps in _check_pipe_policy. _check_quant_output asserts compile_kwargs[-1].get("quant_output", False) == (case["quant"] == "fused"). The hand-written kwarg list and the call to the predicate are deleted. The pins match the previous run's recorded dispatch: 70 fused; 12 fallback (cluster2-shared ×9, head1024-mtp4-g16-page128, mtp4-g16-page128-cluster, mtp4-g16-page128-merge). test_pa_decode_quant_empty_long_query is pinned fused. To check that the pin catches a wrong path, I temporarily flipped decode to "fallback": the assertion fails. The predicate is used only by the dispatch now, so it is private again: _fuses_quant_output.
  • Nits:
    • The FP8 shape comments (pa_decode.py:478-479) and the docstring now include the quantized_pad_rows extra rows.
    • The store_empty docstring now says that descale 0 gives 0xFE bytes and descale 1 (padded rows) gives FP8 zeros.
    • New _INVALID_CASES entry fp8-only: quantized_output without output_scale.
  • CI (item 1): waiting for the MI35X shards at the new head.

MI455X: python3 -m pytest -q op_tests/test_flydsl_pa_decode.py: 332 passed, 159 skipped (one more than before: fp8-only). black and ruff are clean.

Re-review at f19082f → 3758a8b

  • Shared-cluster note: pa_decode.py:525 now says "more than 15 sequence-KV-head pairs per 16 CUs", matching the trigger at :1120.
  • MI35X CI: OPUS Test at f19082f could not be retried any more, so this push starts a fresh run of every job. I'll rerun any shard that hits the Docker Hub rate limit again.

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Action required before merge (3)

  1. Re-run the seven failed MI35X Standard Tests shards at 3758a8b. Shards 0 and 2–7 of run 43998817059 stopped at the Docker Hub toomanyrequests pull limit (exit 125) before any test ran. This is infra, not the PR. Only shard 1 ran to the end, and it does not include op_tests/test_flydsl_pa_decode.py, so the gfx942/gfx950 refusal check has not run at this head. Its last pass was shard 5 at f19082f (452 passed). The Aiter Test Gate is red and aiter-bot reports NOT READY. OPUS Tests now pass.
  2. Keep the quant-unit width in one place. math.gcd(query_group_size, 16) is written twice: traits.py:1675 (LDS size in total_bytes) and op_merge.py:436 (Gfx1250OutputQuant.unit). These two must agree, or the LDS reservation and the quant layout drift apart. Add a quant_unit property next to quant_offset (traits.py:1667) and use it in both places. That also lets op_merge.py drop its new import math.
  3. Cover the new FP8 shape and dtype guards in _INVALID_CASES. pa_decode.py:866-888 rejects a wrong quantized_output shape or dtype and a wrong output_scale shape or dtype. None of these four checks is tested, while the argument-combination checks next to them are. Add one case for each, for example a missing pad row, BF16 quantized_output, a [rows] scale, and an FP16 scale. Each must raise before compile.

@fsx950223: your CHANGES_REQUESTED review (@3b3b556) still blocks the PR. Your COMMENTED review at f19082f found no new blocking defect, and the P2 empty-sequence descale issue is fixed (op_merge.py store_empty, test_pa_decode_quant_empty_long_query). Please re-review or dismiss it.


Re-reviewed at 3758a8b (full diff). Already fixed: the pa_decode.py:525 note now says "more than 15 sequence-KV-head pairs per 16 CUs", which matches the trigger at :1121. Earlier rounds: per-case "quant": "fused"/"fallback" pins with a non-tautological assertion; private _fuses_quant_output; quantized_pad_rows shape docs; store_empty 0xFE/zeros docstring; fp8-only invalid case; shared predicate; inspect.signature removed; self-review; D1024 query-split fallback; cluster2-shared; refusal test; empty-sequence descales. No API probing in the diff.

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

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fsx950223
fsx950223 dismissed their stale review November 17, 2026 06:25

out of date

@lirui927

Copy link
Copy Markdown
Contributor Author

Thanks. Addressed in c4152a4:

  • Quant unit in one place (item 2): new PaDecodeTraits.quant_unit (gcd(query_group_size, 16)) next to quant_offset. total_bytes and Gfx1250OutputQuant.unit both use it, and op_merge.py no longer imports math. The generated ISA is unchanged: FlyDSL ASM dumps of the quant cases are byte-identical before and after (453 of 453 kernels).
  • FP8 operand guards (item 3): four new _INVALID_CASES entries: fp8-missing-pad-row (shape), bf16-quantized-output (dtype), rows-output-scale ([rows] scale) and fp16-output-scale (dtype). Each runs with quantized_pad_rows=1 and must raise before compile_pa_decode_tile is called. They run on gfx1250 only, because gfx942/gfx950 refuse the FP8 output earlier.
  • CI (item 1): the MI35X Standard Tests re-run at 3758a8b passed once the Docker Hub limit cleared. This push starts a fresh run at c4152a4; I'll re-run any shard that hits the limit again.

MI455X: python3 -m pytest -q op_tests/test_flydsl_pa_decode.py: 336 passed, 159 skipped (was 332) (the four new cases account for the extra passes). black and ruff are clean.

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Action required before merge (2)

  1. Fix the new quant_unit comment: it is not the scale group. traits.py:1675 says "Rows sharing one FP8 output scale group". But one scale covers a whole token (query_group_size rows), and gcd(GQA, 16) is the number of rows behind one LDS partial maximum. The two differ for any GQA that is not a divisor of 16: GQA 12 → unit 4, GQA 32 → unit 16. Suggested wording: "Rows behind one per-wave LDS maximum (a token is query_group_size // quant_unit of them); sizes the maxima region at quant_offset."
  2. Name the padding unit in the cluster-grid comment. pa_decode_kernel.py:1317 says "One cluster per P padded FP8 rows", but P is defined nowhere. The code below it pads in units of t.cluster_merge, so write that name in the comment instead of P.

Both items are comment-only and non-blocking. Everything else checks out at this head: CI is green (all 8 MI35X Standard shards and OPUS; test_flydsl_pa_decode.py passed in shard 5), aiter-bot reports READY FOR HUMAN REVIEW, and the PR merges cleanly into current main.


Re-reviewed at c4152a4 (full diff). Already fixed: the quant-unit width now has one definition, Gfx1250Traits.quant_unit, used by total_bytes and Gfx1250OutputQuant.unit, and op_merge.py no longer imports math. The four FP8 operand guards (pa_decode.py:870-888) now have _INVALID_CASES (fp8-missing-pad-row, bf16-quantized-output, rows-output-scale, fp16-output-scale); each reaches its own guard before compile and runs on gfx1250 only. The MI35X CI re-run is green. Earlier rounds: :525 wording; fused/fallback pins; private _fuses_quant_output; pad-row docs; store_empty docstring; fp8-only case; shared predicate; inspect.signature removed; self-review; D1024 query-split fallback; cluster2-shared; refusal test; empty-sequence descales (fsx950223's P2). No API probing in the diff.

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

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

Copy link
Copy Markdown
Contributor Author

Thanks @valarLip. Both comment fixes are in 5c68d296:

  • traits.py quant_unit: the comment now says it is the number of rows behind one per-wave LDS maximum (a token is query_group_size // quant_unit of them) and that it sizes the maxima region at quant_offset; it no longer calls it the scale group.
  • pa_decode_kernel.py cluster grid: "P" is replaced by t.cluster_merge, the unit the grid pads in.

Comment-only: the AST of both files is identical to c4152a4, so the generated kernels are unchanged. black and ruff pass. No GPU run was needed for this change.

@lirui927
lirui927 requested a review from valarLip November 17, 2026 12:20

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM

Both comment nits from the last round are fixed in 5c68d29, and that commit touches nothing else (2 files, comment lines only). The quant_unit comment (traits.py:1675-1677) now describes the rows behind one per-wave LDS maximum, which matches op_merge.py store_cta indexing and total_bytes. The cluster-grid comment (pa_decode_kernel.py:1317-1318) now names t.cluster_merge, which matches grid_x = (sequences + ceil(pads / cluster_merge)) * cluster_merge and one pad row per CTA. A full re-review of the whole diff found nothing else to change. The PR still merges cleanly into current main.

CI: the code is byte-identical to c4152a4, where all 8 MI35X Standard shards and OPUS passed. The re-run at this head is still queued (wheel build); merge waits on it as usual.


Re-reviewed at 5c68d29 (full diff). Already fixed: quant_unit comment, undefined P in the cluster-grid comment (this round); single Gfx1250Traits.quant_unit, _INVALID_CASES for the four FP8 operand guards, MI35X re-run (r35); and all earlier asks (:525 wording, fused/fallback pins, private _fuses_quant_output, pad-row docs, store_empty docstring, fp8-only case, shared predicate, inspect.signature removed, D1024 query-split fallback, cluster2-shared, refusal test, empty-sequence descales). No API probing in the diff.

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Approved at 5c68d29; all test jobs green (only the py3.12 wheel build is still queued).

@lirui927
lirui927 merged commit d6ea3d1 into ROCm:main Nov 17, 2026
fsx950223 added a commit that referenced this pull request Nov 18, 2026
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]>
lirui927 pushed a commit to lirui927/ATOM that referenced this pull request Nov 19, 2026
MiniMax-M3's sparse attention wrote a BF16 output, which a per-token FP8
o_proj then quantized in a launch of its own. With ROCm/aiter#7401, FlyDSL's
pa_decode writes the FP8 rows and their FP32 descales itself.

`Attention.per_token_fp8_out`, which already hands o_proj an `(out, scale)`
pair under Ulysses SP, now also covers an impl whose kernel writes that pair
(`supports_output_quant`, False on the base impl), through the new op
`unified_attention_fp8`. The sparse impl sets it on a GPU without gluon (its
sparse PA is FlyDSL's on every call), over an FP8 KV cache and with one KV
head per rank. The PA skips the BF16 store and writes rows past the queries
as FP8 zeros with a unit descale. The plan stays as it was; aiter picks the
fused epilogue where that plan allows and quantizes after the merge
elsewhere, with the same bytes.

Needs aiter with #7401: ATOM calls its kwargs without probing for them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
valarLip pushed a commit to ROCm/ATOM that referenced this pull request Nov 20, 2026
* perf(minimax-m3): let the sparse PA write o_proj's per-token FP8 input

MiniMax-M3's sparse attention wrote a BF16 output, which a per-token FP8
o_proj then quantized in a launch of its own. With ROCm/aiter#7401, FlyDSL's
pa_decode writes the FP8 rows and their FP32 descales itself.

`Attention.per_token_fp8_out`, which already hands o_proj an `(out, scale)`
pair under Ulysses SP, now also covers an impl whose kernel writes that pair
(`supports_output_quant`, False on the base impl), through the new op
`unified_attention_fp8`. The sparse impl sets it on a GPU without gluon (its
sparse PA is FlyDSL's on every call), over an FP8 KV cache and with one KV
head per rank. The PA skips the BF16 store and writes rows past the queries
as FP8 zeros with a unit descale. The plan stays as it was; aiter picks the
fused epilogue where that plan allows and quantizes after the merge
elsewhere, with the same bytes.

Needs aiter with #7401: ATOM calls its kwargs without probing for them.

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

* perf(minimax-m3): give the FP8-output sparse PA a plan budget of six workgroups per CU

With aiter's default budget, two workgroups per CU, a sparse PA call whose
rows x split pass it gets fewer partitions than the split asks for and a
slower merge, which for the FP8 output also quantizes in a launch of its own.
Six per CU keeps the split. One MI455X, FP8 KV, 2048-token windows, us per
call (median of 7, interleaved, CUDA graphs), default -> six per CU:
decode rows 72 9.12 -> 6.08, 96 9.85 -> 8.12, 160 11.43 -> 8.35,
240 14.45 -> 11.11, 384 22.16 -> 14.84; within 1% at 1-64 and 128 rows.

This replaces the earlier forced plans (one partition per prefill row, one
cluster of eight per decode row up to 240 rows): those were 18-23% slower
than aiter's own plan at 1-16 decode rows.

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

* fix(minimax-m3): correct the FP8-output comments; tighten the pad-row tests

The sparse prefill/decode comments said the FP8 path writes no BF16. The
BF16 `output` is still allocated and only fixes the layout; on plans aiter
cannot fuse, pa_decode writes a BF16 intermediate and then runs the
standalone quant. Say so.

Tests: the FP8 case of the row-rule test fills `quantized_output` with a
sentinel, so the zero pad rows must come from the PA call. The GPU bitwise
test runs the FP8 output through the decode/prefill entry points, so the
prefill pad rows are checked on the GPU too.

`_attention_fp8_fake` is now `attention_fp8_fake`: two ops share it.

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

* docs(minimax-m3): name the FP8-output budget and the tested entry points

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

* test(minimax-m3): pin the gate that turns the FP8 attention output on

Build Attention.__init__ with a stub impl and check per_token_fp8_out:
without SP it follows the caller's request and the impl's
supports_output_quant; under SP it follows the head exchange and ignores
the impl. Reverting the gate to the SP-only formula fails this test.

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

* perf(minimax-m3): keep the feature-off attention calls as on main

A layer without the FP8 output now makes exactly the calls it made before:
- PagedAttentionImpl.forward passes the FP8 output pair to forward_impl only
  through its **kwargs, and forward_impl keeps the plain 8-argument backend
  call when there is no pair.
- run_pa_decode checks the pair inside its FlyDSL branch and binds it there,
  so the FlyDSL call keeps its plain argument list; the guard refusing an FP8
  output before gluon stays. Its three new parameters sit before the `*`:
  a missing keyword-only default costs CPython a dict lookup on every call.

Docs: the FP8-output sparse PA is native ATOM only, without Ulysses SP; the
vLLM/SGLang bridges never take it. Docstrings name `unified_attention_fp8`
and the optional pair in the dispatch_backend contract. Tests pin that the
backend and FlyDSL get no extra kwargs without the pair.

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

* perf(minimax-m3): give the FP8 attention output entries of its own

Without an FP8 output, every call now runs main's code:
`PagedAttentionImpl.forward`, `run_pa_decode`, `sparse_pa_per_row` and both
sparse asm wrappers are main's again.

- `unified_attention_fp8` calls `impl.forward_impl` with the pair directly,
  so `forward` needs no `if kwargs:`.
- The sparse PA writing FP8 is `sparse_pa_fp8_per_row`, FlyDSL only: it
  plans with the FP8 budget and calls aiter's `pa_decode` with the pair, as
  the MXFP4 sparse PA calls FlyDSL itself. `_sparse_decode` /
  `_sparse_prefill` branch once on the pair and otherwise call the asm
  wrapper as on main. `run_pa_decode` loses its three slots, the FlyDSL-side
  bind and the gluon-side guard (dead: the pair exists only on GPUs without
  gluon).
- Drop the FP4-KV `NotImplementedError` (the gate admits an FP8 KV only)
  and ATOM's pair check (aiter validates the pair).

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

* perf(minimax-m3): read the FP8 plan budget after the captured-plan return; run the tests on CPU CI

- `_flydsl_prepare_explicit_plan` reads the workgroup budget after the
  `existing_plan` early return, so a captured dense plan pays nothing for it.
- `_sparse_decode` / `_sparse_prefill` branch on the FP8 output first: it
  gets `torch.empty_like(q[:rows])` as its layout, and the BF16 output and
  its pad-row memset are allocated only on the other branches, as before.
- `sparse_pa_fp8_per_row`: say when aiter fuses the quant into the PA launch
  and when it stores BF16, then quantizes and fills the pad rows after.
- docs: the FP8 budget's larger decode-plan scratch.
- tests: load the modules under `atom_without_aiter` so the CPU CI lane runs
  the file; a sentinel FP8 buffer for the dummy run; the call-site walks cover
  `sparse_pa_fp8_per_row` in decode and prefill.

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

---------

Co-authored-by: lirui927 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants