Repository navigation
[FlyDSL] gfx1250 PA decode: wider page-local softmax steps, shared clusters and wave-pair MTP4 for MiniMax-M3 - #7619
Conversation
…le lookup Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ble lookup Co-Authored-By: Claude Opus 5.5 <[email protected]>
…om context lengths Sequence-indexed grids read context_lengths[seq] alongside reduce_info and split the visible tiles exactly as plan_pa_decode does, instead of chaining reduce_info -> work_info -> block table before the first page DMA. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…A cluster A sequence with more tasks than the cluster has CTAs splits its tiles over the cluster's CTAs, the planner's split for that count. Dense decode at 8K with 32 partition bounds now merges on chip instead of launching the reducer (bs32: 11.0 -> 9.2 us FP8, 14.2 -> 12.3 us BF16). Error against an FP32 reference is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t output Deriving one-partition tasks from context lengths shortened short grids but cost many-row sparse prefill (4096 rows) 1-2.5%; only cluster grids derive their tiles now. Co-Authored-By: Claude Opus 5.5 <[email protected]>
One D128 query tile over page16 caches now stages two pages per wave, so each softmax exchange and its three barriers cover 128 tokens instead of 64. LDS keeps the pages page-major: V is then the 128-token page layout and K operands read each page's 16-token block. MiniMax-M3 FP8 sparse shapes: decode 4/64/128/256 rows 1.18x/1.11x/1.21x/1.26x, verify 1.18x, prefill 1024/4096 rows 1.26x/1.04x. Error against an FP32 reference is unchanged within 1% except 4 rows with e^N(0,1) token magnitudes (5.6e-2 -> 6.3e-2), as P normalizes V scales over 128 tokens. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… small grids Each wave stages two BF16 page16 pages, page-major, when the grid needs at most two CTAs per CU; the 128-token stage then halves softmax exchanges. Larger grids (sparse prefill) keep 64-token stages for occupancy. MiniMax-M3 BF16 sparse decode 4/64/128/256 rows 1.17x/1.06x/1.11x/1.13x, verify 1.17x, prefill unchanged; error against FP32 unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
One D128 FP8 query tile over page128 caches stages two pages per step when the grid has at most one CTA per CU, or two per CU with about three or more tiles per CTA. P still normalizes each page by its own V scales: waves 0-1 own page 0's tokens and waves 2-3 page 1's, and the second page's K128 PV is rescaled to the first page's factor, so error against an FP32 reference is unchanged. PV and V-scale reductions take any multiple of 128 tokens, and tail scales loop over the CTA's threads. MiniMax-M3 FP8 dense decode bs1/4/8 at 8K 1.11x/1.17x/1.17x, bs3 220K 1.03x, others unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… one-CTA grids With at most one CTA per CU, one D128 BF16 query tile over page128 caches stages two pages per step (each in the one-page LDS layout), halving the softmax exchanges per token. MiniMax-M3 BF16 dense decode bs1/4/8 at 8K 1.06x/1.07x/1.05x; error against FP32 unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… one-CTA grids With at most one CTA per CU, each wave stages four BF16 page16 pages per step. BF16 P needs no per-step normalization, so the wider step leaves results within BF16 rounding of the 128-token step. MiniMax-M3 BF16 sparse decode 4 rows 1.05x, verify 12 rows 1.03x, others unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ional Co-Authored-By: Claude Opus 5.5 <[email protected]>
Two-page FP8 steps (page128 pairs and 128-token page16 steps) quantized P against the whole step's maximum and V factor, and rescaled the second page by the first page's factor. A first half whose logits trail by 14 rounded its P to zero in E4M3, and a V-scale range of 1e40 overflowed the page ratio to inf, where one-page steps gave the reference. Each half (waves 0-1, waves 2-3) now quantizes P with its own maximum and V factor, runs its own PV, and the halves combine in FP32 with weights exp2(m_h - m) * f_h / max(f0, f1), all at most one. The FP8 page16 step stays 64 tokens on grids beyond four CTAs per CU, where the split costs more than the saved exchange. Adds the two review cases as regressions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
gfx1250 keeps 15 clusters resident per 16 CUs, so batches with more than 240 split sequences per KV head fell back to the separate reducer. Such batches now put 2, 4, ... sequences in one cluster of P * k CTAs (up to 16): each sequence still merges its own P partials, every CTA reaches the cluster barrier, and a padded last cluster's CTAs only sync. MiniMax-M3 sparse decode at 256 rows (2 partitions) runs one kernel: FP8 1.11x, BF16 1.12x, bit-identical to the reducer. A 243-row test pins the shared clusters with graph replays; 2000 NaN-poisoned replays match eager. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Four FP8 D128 query tiles over page128 caches gave each wave one tile and the whole page, so every wave read all of K and V from LDS. Wave pairs now share two tiles and each wave covers half of every page: each K or V operand feeds two WMMAs (K128 QK, K64 PV), halving LDS reads, and a pair merges its two online-softmax states once through the page buffer the last page left unused. P keeps the page's V normalization; error against an FP32 reference is unchanged within 1%. MiniMax-M3 FP8 verify 3x4 at 8K 1.07x, 214K 1.05x (ATOM-style calls: 1.02x, 1.05x). Co-Authored-By: Claude Opus 5.5 <[email protected]>
… small grids Double-buffered steps issued a task's second stage only after the first stage landed, so two-step sparse tasks paid two copy latencies in series. On grids with at most one CTA per CU, the prologue now issues both stages and step 0 waits only for its own copies (same-wave TDM copies complete in order; scale copies only accompany whole stages). Fuller grids and page128 pairs keep the old order, where the earlier copy's contention cost more. MiniMax-M3 sparse decode 4 rows: FP8 1.03x, BF16 1.02x; verify 12 rows: FP8 1.05x; outputs bit-identical. Co-Authored-By: Claude Opus 5.5 <[email protected]>
One-partition plans write output directly from one CTA per sequence. Sparse prefill rows see min(row + 1, 2048) tokens, so in grid order the short rows ran first and the full-length rows formed the last wave. CTAs now take sequences in reverse order. MiniMax-M3 sparse prefill: FP8 1024 rows 1.06x, BF16 4096 rows 1.04x, the others unchanged; bit-identical. Co-Authored-By: Claude Opus 5.5 <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
NOT READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
There was a problem hiding this comment.
🟡 Changes recommended
Changes are needed because FP32 ratio underflow can erase finite attention contributions, and direct helper calls without max_context_length can raise TypeError.
2 open issues
What changed in this PR
This PR builds on #7079 to reduce FlyDSL paged-attention decode latency on gfx1250, focusing on MiniMax-M3 decode, verification, and prefill shapes.
Changes:
- Widens FP8/BF16 softmax steps and introduces FP8 wave-pair processing with earlier query loads.
- Extends in-kernel partition merging, shares clusters across sequences, and reverses direct-output sequence order to favor longer sparse-prefill rows.
- Adds numerical and shared-cluster regression cases plus a benchmark harness that reuses correctness-test inputs.
| File | Description |
|---|---|
op_tests/test_flydsl_pa_decode.py |
Adds page-local scaling and shared-cluster cases; exposes reusable test setup. |
op_tests/op_benchmarks/flydsl/bench_pa_decode.py |
Adds a correctness-checked FP8/BF16 latency benchmark with JSON output. |
aiter/ops/flydsl/pa_decode.py |
Expands cluster-merge eligibility and passes shared-cluster settings. |
aiter/ops/flydsl/kernels/pa_decode/traits.py |
Defines wider-step and early-staging scheduling policies. |
aiter/ops/flydsl/kernels/pa_decode/pipeline.py |
Implements wider softmax steps, wave pairs, and revised staging. |
aiter/ops/flydsl/kernels/pa_decode/op_merge.py |
Separates cluster synchronization from sequence merging. |
aiter/ops/flydsl/kernels/pa_decode/op_lds.py |
Adds multi-page staging and separates query loading from storage. |
aiter/ops/flydsl/kernels/pa_decode_kernel.py |
Selects grid-dependent policies and implements shared-cluster launches. |
Review effort: Balanced
* Two-page FP8 steps took the accumulator factor from the half with the larger V factor. When that half is negligible after softmax weighting (logits 0 and 128, V scales 1e32 and 1e-16), the dominant half's ratio of 1e-48 rounded to zero and the output was lost. The accumulator now takes the factor of the half with the larger weighted factor, and each half's coefficient is (weight * factor) / chosen factor, at most one, so no ratio overflows either. * The two-page FP8 grid heuristic negated max_context_length, whose documented default is None, and raised TypeError for grids between one and two CTAs per CU. Without a bound it keeps one-page steps. Adds both as regressions; outputs and error against FP32 are unchanged on the MiniMax-M3 shapes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Fixed the two open findings from #7579 (@fsx950223, Copilot) in 2149ba6:
|
There was a problem hiding this comment.
🔵 Needs a closer look
Runtime plan selection independently probes gcnArchName instead of using the required get_gfx_runtime() helper, leaving it inconsistent with the shared runtime/AOT-replay architecture contract.
3 open issues
Review effort: Balanced
fsx950223
left a comment
There was a problem hiding this comment.
Reviewed exact head 1816c76. The two-page FP8 path introduces a multi-step accumulator-rescaling overflow. Targeted gfx942 regression tests passed, but gfx1250 execution remains unverified and gfx950 testing was unavailable because all devices were busy.
[P2] Include accumulated history when selecting the wide-step V factor — aiter/ops/flydsl/kernels/pa_decode/pipeline.py:2167
For gfx1250 FP8 D128/page128 decode with one partition, 512 tokens, cached V=1, page logits [0, 80, 80, 80], and per-token V scales [1e32, 1e-16, 1e-16, 1e-16], selecting the factor solely from the current halves makes the second wide step overflow. The first step retains a nonzero accumulator (~1.03e-30) normalized by ~2.23e29; the second selects ~2.23e-19 while corr=1, so the subsequent corr * state[-1] * vnorm becomes infinity. A scalar FP32 reproduction of the source recurrence confirms this overflow, whereas the base's one-page recurrence returns approximately 0.000601617, matching the reference. GPU execution remains unverified. Preserve a factor that also accounts for weighted history, or apply the rescaling without an overflowing intermediate, and add a multi-step regression.
Validation:
- PASS on
local:git -C checkout rev-parse HEAD
Verified 1816c76; supplied base is also the merge-base. Complete diff saved in complete.diff. - PASS on
local:python3 scalar_rescale.py
Exit 0. Reproduced head-only FP32 history coefficient and accumulator overflow; base output 0.0006016171537339687 versus reference 0.0006016171292819052. Script and output preserved in scalar_rescale.py and scalar-rescale.log. - PASS on
hjbog-srdc-39.amd.com / sixifang_dev:flock -w 30 /tmp/codex-pr-review-7619-1816c762-20261113/gpu.lock timeout 300 /opt/venv/bin/python -m pytest -q op_tests/test_flydsl_pa_decode.py -k 'cluster2-gqa32 or cluster2-plain-v or cluster16-steps-kv2 or invalid-select'
Exit 0: 24 passed, 1 skipped, 453 deselected in 22.02s. Confirmed idle device 0 is gfx942 and imports resolve to isolated exact-head source and task-local FlyDSL 0.5.0. Plain BF16 V positive case skipped as unsupported. Environment and command saved in gfx942-final-command.sh; output in gfx942-final.log. - SKIP on
dzm-mi355-gpu34-dev / fsx950223_pr_review_gfx950:srun --overlap --jobid=9581 --ntasks=1 --cpus-per-task=1 podman exec -i fsx950223_pr_review_gfx950 rocm-smi --showuse --showpids
Discovered active allocation 9581 and verified gfx950 inside the configured container. All eight devices reported 100% utilization with existing processes; no GPU tests launched. Logs saved in gfx950-allocation.log, gfx950-probe.log, and gfx950-activity.log. - SKIP on
gfx1250:Multi-step FP8 overflow GPU reproduction
No configured gfx1250 environment. The scalar recurrence comparison does not constitute target GPU validation.
Remaining validation:
- The blocking finding is supported by source tracing and scalar FP32 evaluation, not gfx1250 GPU execution.
- gfx942 tests exercise shared host code and existing architecture paths, not the new gfx1250 pipelines or their performance.
- Available CI statuses were inspected and saved in ci-results.json; the run-log request returned no log text, so CI test counts were not independently verified.
- No end-to-end serving or performance benchmark was run.
Automated Codex review of commit 1816c7628377.
Two-page FP8 steps took the accumulator factor from the current halves only. When a later step's factor fell far below the factor the history was normalized by, while the softmax maximum held (corr = 1), the history coefficient corr * state[-1] * vnorm overflowed: page logits 0, 80, 80, 80 with per-token V scales 1e32, 1e-16, 1e-16, 1e-16 gave inf on page128 pairs and 128-token page16 steps, where one-page steps give the 6.0e-4 reference. The accumulator now takes the factor of the largest weighted factor among the two halves and the history (corr times its factor), so every coefficient, the history's included, is at most one. P quantization keeps each half's own factor. Both cases give the reference, as do logits 80, 80, 80, 80, which also overflow one-page steps. test_pa_decode outputs are unchanged except one-ulp FP16 differences in six FP8 per-token page16 cases. Co-Authored-By: Claude Opus 5.5 <[email protected]> Co-authored-by: Cursor <[email protected]>
As requested in review, remove test_pa_decode_two_page_steps_keep_page_scales and test_pa_decode_value_factor_below_floor, and the test module's pointer to bench_pa_decode.py, which 385386d removed together with the two-page fix. Co-Authored-By: Claude Opus 5.5 <[email protected]> Co-authored-by: Cursor <[email protected]>
|
@fsx950223 All three points are addressed in 385386d and 8512f23. [P2] Include accumulated history when selecting the wide-step V factor (385386d) Confirmed on gfx1250 before the fix. Your case (page128, page logits 0/80/80/80, per-token V scales 1e32/1e-16/1e-16/1e-16) gave non-finite values for every output at 1816c76. The same pattern on 128-token page16 steps did too. Main's one-page steps give the 6.0e-4 reference. The two-page accumulator now takes the factor of the largest weighted factor among the two halves and the history ( Logits 80/80/80/80 with the same scales now also work on two-page steps (1.0014). On main, one-page steps still overflow in that case; that predates this PR and is unchanged here. Following your inline comments, the PR no longer adds standalone tests, so I verified this case with a script rather than adding a regression test. Removals: Validation on gfx1250 (MI450, FlyDSL 0.5.0):
|
As requested in review, remove test_pa_decode_tile_without_context_bound. Co-Authored-By: Claude Opus 5.5 <[email protected]> Co-authored-by: Cursor <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
A scalar FP32 reproduction exposes potential output-erasing underflow in a specific BF16/FP8 decode configuration, requiring human assessment because GPU behavior remains unverified.
2 open issues
1 resolved since last review
Review effort: Balanced
#7700 and this branch each add an import at the same line of pa_decode/pipeline.py; keep both. The rest merges cleanly: #7700 changes the gfx942/gfx950 PA decode classes and this branch the gfx1250 ones. Co-authored-by: Cursor <[email protected]>
…cies main now carries #7700 (at bdabd08) and #7709 (at ce737ce, including its own resolution against #7700) as squash merges, plus #7619's gfx1250 pa_decode changes. Every conflict in op_lds.py, pipeline.py, traits.py, pa_decode_kernel.py, pa_decode_plan.py, pa_decode.py and the test takes main's side, so the stack's older #7700/#7709 heads and their merge resolutions are superseded. On top of main the branch keeps only #7701 (02dc5d1, unchanged) and this PR's three commits. The STREAM_KV commit's flag rename now also renames main's named cache key fields: PaDecodeCacheKey.gfx942_busy -> busy_grid and gfx942_two_per_cu -> two_per_cu. Every consumer other than STREAM_KV stays gated on "gfx94". Two hunks of this PR's commits were already on main through #7709's resolution and drop out of this PR's diff: DUAL_GROUP's "not STREAM_KV" and the _zero_rows kv_query axis follows SPLIT_MAJOR. The merged tree is identical to main + #7701's five commits + this PR's three commits cherry-picked. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
pa_decode gains optional quantized_output / output_scale (OCP FP8 plus one FP32 descale per token), store_output and quantized_pad_rows. On gfx1250 with one KV head, the one-partition direct output and cluster merges write the FP8 output from the final values in registers; other plans write BF16 and run the standalone per-token quant. Rebased onto main after #7619 as one commit. The epilogue now also covers step-split (cluster_steps) and run-split (cluster_runs) clusters and the reversed direct-output order; clusters shared by several sequences (cluster_seqs > 1) fall back to the standalone quant. Squashes the PR's commits 5d72374..3b3b556: - feat(flydsl): fuse sparse PA output quantization - test(flydsl): cover production PA plan capacity - perf(flydsl): quantize sparse PA output from registers - fix(flydsl): fall back to the standalone quant for other PA output modes - perf(flydsl): write a padded bucket's FP8 rows in the sparse PA quant launch - refactor(flydsl): share the cluster sync and a thread's token slice in the PA quant epilogue - test(flydsl): run the sparse PA FP8 output test from CI, time it, and trim it - refactor(flydsl): fold the FP8 output tensors into pa_decode's existing checks - feat(flydsl): widen the fused PA FP8 output to any GQA, D, page and MTP - test(flydsl): fold the PA FP8 output test into test_flydsl_pa_decode.py Co-Authored-By: Claude Opus 5.5 <[email protected]>
* feat(flydsl): fuse sparse PA output quantization pa_decode gains optional quantized_output / output_scale (OCP FP8 plus one FP32 descale per token), store_output and quantized_pad_rows. On gfx1250 with one KV head, the one-partition direct output and cluster merges write the FP8 output from the final values in registers; other plans write BF16 and run the standalone per-token quant. Rebased onto main after #7619 as one commit. The epilogue now also covers step-split (cluster_steps) and run-split (cluster_runs) clusters and the reversed direct-output order; clusters shared by several sequences (cluster_seqs > 1) fall back to the standalone quant. Squashes the PR's commits 5d72374..3b3b556: - feat(flydsl): fuse sparse PA output quantization - test(flydsl): cover production PA plan capacity - perf(flydsl): quantize sparse PA output from registers - fix(flydsl): fall back to the standalone quant for other PA output modes - perf(flydsl): write a padded bucket's FP8 rows in the sparse PA quant launch - refactor(flydsl): share the cluster sync and a thread's token slice in the PA quant epilogue - test(flydsl): run the sparse PA FP8 output test from CI, time it, and trim it - refactor(flydsl): fold the FP8 output tensors into pa_decode's existing checks - feat(flydsl): widen the fused PA FP8 output to any GQA, D, page and MTP - test(flydsl): fold the PA FP8 output test into test_flydsl_pa_decode.py Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(flydsl): write every descale of an empty sequence longer than a CTA store_empty wrote one descale per thread, so an empty sequence with query_length above BLOCK_THREADS (128) left the rest of its descales unwritten (reported by fsx950223). Stride the descale stores over the block like the FP8 zeros. A BF16 GQA-1 D256 case with query_length 129 and an empty second sequence checks it against NaN-poisoned descales. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(flydsl): check that gfx942/gfx950 refuse the PA FP8 output The quant-tagged pa_decode cases checked the FP8 output on gfx1250 only, so MI35X CI ran none of it. There they now assert that quantized_output and output_scale raise NotImplementedError. Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs(flydsl): correct the PA FP8 output's comments and contiguity message - Name the missing typed API at the raw cvt_pk_fp8_f32 call, as the other FlyDSL kernels do. - Padding rows clamped to the last row also load a row's first pmax entry before the cluster barrier, harmlessly; the comments said only the owner wave reads it. - The contiguity error also covers quantized_output. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(flydsl): keep the D1024 MTP4 query split under the PA FP8 output The spilling BF16 D1024/GQA16/MTP4/page128 tile kept query_splits=1 when the FP8 output was requested, so its direct output could quantize in the epilogue. It now keeps its measured four-way query split, and pa_decode quantizes after the output with the standalone per-token kernel whenever the selected tile splits its query rows. With FP8 output on one MI455X, that is 1679 -> 295 us at one sequence of 2048 tokens and 9122 -> 1576 us at four of 8192. The pa_decode docstring now states exactly when the epilogue quantizes: one KV head, no query split, and the one-partition direct output or a cluster merge with one sequence per cluster. It also states that the fallback writes the padded rows after the standalone quant. The stride check that the contiguity check implies is removed. The test runs cluster2-shared with the FP8 output, and adds the D1024 shape. Co-Authored-By: Claude Opus 5.5 <[email protected]> * refactor(flydsl): share the PA FP8 output's fused-path predicate with the test pa_decode now decides with one helper, fuses_quant_output, whether the gfx1250 tile quantizes the FP8 output in its epilogue: one KV head, the one-partition direct output or a cluster merge with cluster_seqs == 1, and no query split. The host dispatch and _check_quant_output both call it, so the test no longer repeats the predicate or filters the compile arguments through inspect.signature. The dispatch is unchanged. The BF16 invalid-input cases now also cover the FP8 output's argument errors: an output_scale without quantized_output, store_output=False without the FP8 output, a negative or bool quantized_pad_rows, and pad rows without the FP8 output. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(flydsl): pin the PA FP8 output's fused or fallback path per case The quant tag on each case now names the path the dispatch must take, "fused" or "fallback", and _check_quant_output asserts the launch's quant_output against it. The test no longer rebuilds the tile options or calls the dispatch's predicate, so a plan that stops fusing fails instead of matching itself. The predicate is private to the dispatch again. Also: _INVALID_CASES covers quantized_output without output_scale, the FP8 shape comments and docstring include the quantized_pad_rows rows, and the store_empty docstring states that descale 0 gives 0xFE bytes. Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs(flydsl): count sequence-KV-head pairs in the shared-cluster note Co-Authored-By: Claude Opus 5.5 <[email protected]> * pa_decode: share the FP8 output quant unit and test its operand guards Add PaDecodeTraits.quant_unit, the gcd(GQA, 16)-row group that shares one FP8 output scale, and use it both for the LDS maxima in total_bytes and in Gfx1250OutputQuant, so the reservation and the layout cannot drift apart. Cover the gfx1250 quantized_output and output_scale shape and dtype checks in _INVALID_CASES: a missing pad row, a BF16 quantized_output, a [rows] output_scale and an FP16 output_scale each raise before compilation. Co-Authored-By: Claude Opus 5.5 <[email protected]> * pa_decode: clarify the quant-unit and padded-cluster comments quant_unit is the row count behind one per-wave LDS maximum, not the FP8 scale group; the padded cluster grid pads in t.cluster_merge rows. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: lirui927 <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Conflicts in op_softmax.py, traits.py, pa_decode_kernel.py, pa_decode.py, pa_decode_tuning.py and test_flydsl_pa_decode.py, all where main and this PR add fields or arguments side by side. Kept main's code and added causal on top: - traits.py: causal is a named PaDecodeCacheKey field, which main now builds by keyword, and the last Gfx1250Traits field, since gfx1250_tile_traits passes the earlier ones by position. - pa_decode_kernel.py: causal reaches compile_gfx1250_pa_decode through Gfx1250Traits, and ROCm#7619's wave-pair pipelines keep this PR's causal_rows gate. - pa_decode.py: causal goes into tile_options, which feeds the cluster steps probe, _fuses_quant_output and compile_pa_decode_tile. - op_softmax.py: this PR's causal-aware slack, with TILE_TOK renamed to KV_COMPUTE_BLOCK. - The test file keeps both case lists. _check_pipe_policy builds one set of schedule kwargs for the MTP4 pin and main's pipe and NHD pins. Main's BF16_MTP_FUSED, FP8_MTP4_LEAN and NHD paths take their row bounds from context.py's offsets, so causal=False reaches them unchanged. With main's planner fallback for torch builds without shared_memory_per_block (ROCm#7205), the non-causal cases also pass on torch 2.9.1. Signed-off-by: Rebecca Lee <[email protected]>



Summary
Follow-up to #7079 on gfx1250 PA decode, tuned on MiniMax-M3 attention shapes (H16/KV1/D128). This replaces #7579 (same commits, reopened from the author's account).
On gfx1250, every MiniMax-M3 sparse attention call (decode, MTP verify, prefill) runs FlyDSL
pa_decode(pa_fwd_asmdoes not support gfx1250), and dense layers use it withATOM_PA_FLYDSL=1. The PR has three parts.Wider softmax steps, kept page-local
A single query tile's step exchanges maxima, sums and P through LDS behind three CTA barriers, so short and sparse tasks spend much of their time on that exchange. Steps now cover more tokens where the grid allows it;
compile_pa_decode_tilechooses the width from the grid size it already receives.exp2(m_h - m) * f_h / F, where F is the factor of the largest weighted factor among the two halves and the history (corrtimes its factor), so no coefficient exceeds one from step to step.Merges and grids
context_lengths, read alongsidereduce_info, instead of chaining reduce_info → work record → block table.readfirstlane, and asched_barrierfollows the preloads: only the active branch reads the ids, and the compiler had otherwise sunk or scheduled their loads after the length's wait (ATT showed the round trip still there).plan.capacityfits. Both step-split forms need tiles that take 128-token steps: two query tiles, plain BF16 V and grids beyond two (BF16) or four (FP8) CTAs per CU keep plan-derived clusters.max_context_lengthbound of at most four 256-token tiles per CTA (dense decode up to 16K at P = 16) take fixed runs too: CTA p takes tiles [p·run, (p+1)·run), where the host sizesrunfrom the bound and passes it as a kernel argument. Their first page ids load with the context length (FP8 and BF16; asched_barrierkeeps the scalar loads ahead of the length's wait). Rows at the bound split exactly as the planner splits them, so outputs on MiniMax-M3 dense shapes are bit-identical; shorter rows use fewer CTAs. ATT, FP8 dense bs1 8K: first KV copy issues at cycle 2211 instead of 2564.Pipelines
Performance
Measured on gfx1250 (256 CUs) on one GPU, base
zhiding512/pa_benchmark(6752572). Base and head runs alternate, and each case reports the minimum of two runs of the median of three rounds. Each round takes the minimum of five 10-call CUDA graphs with 5 replays.get_recommended_splits(rows, 1)cap, 2048 top-k tokens, a page16 pool of 4096 pages, andmax_context_length=2048. FP8 caches use per-token scales.max_context_length = max(lengths).The table is at 8d0ba96. 54dbb59 then adds the
sched_barrierto step-split clusters of fewer than 16 CTAs: FP8 sparse decode at 4, 64 and 128 rows gains a further 2.4–4.5%, BF16 at 64 rows 2.1% (interleaved A/B, bit-identical). The #7619 review fixes (5474b27, 1a039b2) measure neutral: geomean 0.9995× over the 84-point MiniMax-M3 matrix against 54dbb59. After merging main (FlyDSL 0.5.0), e1eb72f against main e9efac0 on the same harness (3 interleaved runs per side): geomean 1.13× over the table's 34 cases (FP8 dense 1.13×, FP8 sparse 1.26×, BF16 dense 1.03×, BF16 sparse 1.14×) and over all 84 points, with 67 points faster and one slower (BF16 dense decode bs1 8K, 0.6%). Main itself times faster than the table's base (FP8 dense decode bs1 8K: 5.20 µs against 7.20 µs), so the margins are smaller than in the table. The two-page history fix (385386d) measures neutral against 1816c76: geomean 0.999× over the 84 points, with ATOM-style FP8 sparse decode at 128 rows 2.6% slower.bench_pa_decodematrix at 8d0ba96, two alternating runs per side: 1.18× over 189 cases (FP8 1.20×, BF16 1.08×). The worst cases (FP8mtpand BF16 MTP4 page128, 0.96–0.99×) sit within the base's own 3–4% run-to-run spread, and earlier back-to-back reruns timed them equal. The matrix'scluster8andcluster16cases grew their batches in this PR. Review later removed the harness from the PR.max_context_length, block tables padded to 256K tokens) always take the reducer. There, dense gains at 8d0ba96 are 1.04× overall: FP8 1.08× and BF16 1.01×.PR Self-Review
Reviewed revision
3a0ffdc
Behavior and intent
The PR changes how gfx1250 FP8 and BF16 PA decode tile kernels schedule work (step width, wave pairing, cluster sharing and splitting, prologue order, CTA order), and how many task slots small gfx1250 decode plans reserve. Outputs are unchanged in meaning: these are scheduling changes for the same attention.
The existing behavior left time on fixed overheads. Each 64- or 128-token step paid a cross-wave softmax exchange, the four FP8 MTP4 query tiles each read the whole page from LDS, batches above 240 split sequences took a second reducer launch, prologues chained dependent loads, and long sparse-prefill rows ran last.
Two #7619 review fixes sit on top.
pa_decoderequests step-split clusters only for tiles that take 128-token steps; other tiles raisedValueError. The FP8 per-token pipelines carry the floored V factor through step rescaling, the half merge and the epilogue; below the 1e-20 floor of P normalization the output was 0.09–0.5× of the reference, including on one-page paths that predate this PR. e1eb72f merges main, which pins FlyDSL 0.5.0 and passes torch dtypes tocompile_pa_decode_tile(#7388). 3a0ffdc merges main again for #7700 (gfx942/gfx950 PA decode); its one conflict was two imports added at the same line.A third review fix (385386d) lets two-page steps keep the history's V factor. Taking the factor from the current halves alone overflowed the history coefficient to infinity when a later step's factor fell far below an earlier one while the maximum held. Review also removed the benchmark harness and the standalone tests (385386d, 8512f23, 511e69b).
Validation and unverified scope
Validated on gfx1250 (MI450, 256 CUs, PyTorch 2.11.0+rocm10.1) on one GPU.
At 3a0ffdc (511e69b merged with main b0c5c02, which adds #7700), with FlyDSL 0.5.0 (main's pin):
python -m pytest -q op_tests/test_flydsl_pa_decode.py: 306 passed, 159 skipped, as at 511e69b.test_pa_decodecases produce byte-identical outputs at 3a0ffdc and 511e69b, and the 260 kernels they compile have identical gfx1250 ISA: the merge changes no gfx1250 kernel.At 511e69b (8512f23 minus one compile test), with FlyDSL 0.5.0 (main's pin):
python -m pytest -q op_tests/test_flydsl_pa_decode.py: 306 passed, 159 skipped; the tests removed in review had 13 cases.test_pa_decodecases produce byte-identical outputs. Six FP8 per-token, FP16-query page16 cases differ by one FP16 ulp, at most 1.5e-5.test_pa_decode_two_page_steps_keep_page_scales,test_pa_decode_value_factor_below_floorandtest_pa_decode_tile_without_context_bound) pass with the fix, run before their removal.At 1816c76 (e1eb72f plus a test-only fix), with FlyDSL 0.5.0 (main's pin):
python -m pytest -q op_tests/test_flydsl_pa_decode.py: 319 passed, 159 skipped. The skipped cases are all MXFP4 or gfx950-only.test_pa_decodecases produce byte-identical outputs at e1eb72f and at the pre-merge head 1a039b2, both on FlyDSL 0.5.0: merging main changes no output.test_flydsl_pa_decode.py427 passed, 50 skipped, 1 failed. The failure wasbf16-cluster2-plain-v, a case this PR added: gfx942 and gfx950 reject plain BF16 V caches, and 1816c76 skips positive plain-V BF16 cases there. MI35X CI at 1816c76: 427 passed, 51 skipped.At 1a039b2, with FlyDSL 0.4.1:
test_pa_decodecases that run at both revisions produce byte-identical outputs at 1a039b2 and 54dbb59.At earlier heads, with FlyDSL 0.4.1 (54dbb59: 291 passed, 159 skipped):
max_context_length=Nonecrash in the wide-step grid heuristic, and the accumulator factor underflowing for a dominant half with a tiny V scale) are fixed in 2149ba6; review later removed their regression tests.Unverified:
max_context_length; they were checked at 8512f23 by script and by the removed tests.default-capat 54dbb59 (4 of 12288 elements, 0.0053) andcluster2-sharedat 1816c76 (7 of 497664 elements, 0.0060). Neither recurred in 4000 relaunches per case (alone or with three test shards loading the same GPU), 150 from-scratch reruns, NaN- or random-poisoned partial scratch, or five more full-suite runs.PR-specific question
Do two-page FP8 steps keep the accuracy of one-page steps? Each half quantizes P against its own maximum and V factor. The halves and the history combine in FP32 with weights
w * f / F, where F is the factor of the largest weighted factor among them, so no coefficient exceeds one and only negligible terms can underflow. Error against FP32 matches base on the tested shapes. The extreme-scale review cases give the reference at 8512f23: a 1e40 V-scale range, E4M3 P underflow, a dominant half with a 1e-16 V scale against 1e32, a V factor below the 1e-20 floor, and a 1e48 factor drop between steps. Review removed their standalone tests, so they were checked by script.Changed op tests
op_tests/test_flydsl_pa_decode.py:cluster16-steps(new_COMMON_CASESentry; 11 rows with empty, 1-, 129- and 257-token rows, graph capture): pins the 16-CTA step-split clusters.cluster8doubles its batch past that threshold and, likecluster2-shared, now pins the fixed runs of steps.cluster16quadruples its batch.cluster4-wide-table(new; a 129-page table): pins plan-derived clusters for tables wider than 16 steps.cluster2-gqa32(new_COMMON_CASESentry; GQA32 page16 decode with empty and short rows),cluster8-wide-grid(new_COMMON_CASESentry; 160 rows at a budget of 2048, so the grid passes two CTAs per CU for BF16 and four for FP8) andcluster2-plain-v(new BF16 entry; GQA16 with plain V): pin plan-derived clusters (cluster_steps=False) for tiles that take 64-token steps. At 54dbb59 all three raiseValueError. No existing step-split candidate had two query tiles, plain BF16 V or a budget past two slots per CU.cluster16-steps-kv2(new; two KV heads, GQA 8, empty, partial-step and full rows, graph capture): keeps each head's step partials and preloaded page ids apart.cluster16-runs-page128(new, FP8 and BF16; 8 rows with empty, 1-, 129-token, partial-tile and bound-length rows, graph capture),cluster16-runs-page128-kv2(FP8; two KV heads, a nine-tile bound, so a 9-CTA cluster) andcluster9-runs-page128-bs1(BF16; one row, the one-CTA-grid two-page step): pin page128 fixed runs.test_pa_decode_merge_alignment: the one-row D128 cluster case now expects a 16-CTA step-split cluster.cluster2-shared(new_COMMON_CASESentry; 243 sequences, 2 partitions, graph replays): the only case with more than 240 split sequences, so the only one that exercises shared clusters, including a padded last cluster and empty rows. It pinscluster_seqs == 2._check_pipe_policydrops the newcluster_seqs,cluster_stepsandcluster_runskeys before callingPaDecodeSchedule.select, and checkscluster_stepsandcluster_runswhen a case pins them._PA_DECODE_CASESand_run_pa_decode_case(6752572, for the benchmark harness that review removed):test_pa_decode's parameter list moves to module level and its body into a helper that also returns the validatedlaunchandcheckclosures, inputs and plan. The refactor leaves case IDs and checks unchanged (diff -wshows only the move, docstrings and the addedreturn).🤖 Generated with Claude Code