Skip to content

[HIP] Optimize wide-pool H64 fused attention decode with KV32 and tail splitting on MI355X - #8983

Merged
zufayu merged 8 commits into
ROCm:mainfrom
yzhou103:mi355x-h64-kv32-tail-split
Dec 4, 2026
Merged

zufayu merged 8 commits into
ROCm:mainfrom
yzhou103:mi355x-h64-kv32-tail-split

Conversation

@yzhou103

@yzhou103 yzhou103 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Optimize wide-pool H64 two-source MXFP8 decode on MI355X. The direct path uses a 32-row KV tile for eligible calls between 257 and 768 queries. Callers at the 256- and 512-query boundaries can explicitly split the KV work for the tail using a compact workspace.

Implementation

  • Use a double-buffered LDS layout and a 48-query permutation for the eligible raw-Q path. The kernel addresses CSR data and writes outputs using the original query ID. The 768-query specialization has additional workload ordering.
  • For an eligible compact workspace, the main launch writes the bulk queries' final outputs directly and partitions only the remaining queries. A second launch merges tail softmax statistics, incorporates the attention sink, and writes the inverse-RoPE MXFP8 output and scales.
  • Support 4 parts at T=257–264, 8 parts at T=513–520, 4 parts at T=521–560, and 2 parts at T=561–600. The contiguous FP32 workspace is [T - bulk, parts, 64, 516]. The existing full-size split workspace has its own layout check. The op test covers compact workspaces, both RoPE position widths, variable CSR lengths and wide KV row addresses.

MI355X results

Whole-call measurements on 65d8ba1

The comparison base is b495628a. On a single MI355X, we alternated base, previous PR head (cf37e238), and current head across three independent processes per revision and index pattern. Each process rotated six inputs, measured nine timed rounds after graph warmup, and reused its output buffers. Both KV sources have full lengths (512 + 128), H64/D512, with a 9M-row prefix pool. Random indices use int32 positions, and request-local indices use int64 positions. Times are medians in microseconds per complete fused call, including both launches for compact tails, with workspace allocation outside timing.

T Rand base Rand head auto Rand head compact Req base Req head auto Req head compact
144 35.33 35.27 — 30.98 30.95 —
256 40.51 40.47 — 34.99 34.91 —
257 69.67 57.86 51.53 63.54 55.82 49.66
264 69.42 58.63 52.35 64.11 56.60 50.45
336 69.72 59.77 — 65.49 58.45 —
384 70.83 60.65 — 66.75 59.36 —
448 73.16 62.94 — 67.72 60.27 —
512 77.04 66.95 — 68.92 61.47 —
513 104.62 93.96 74.48 96.89 91.41 70.52
528 104.52 94.21 79.32 97.55 91.46 74.99
576 104.71 93.50 88.73 98.02 91.58 84.33
582 105.13 93.60 89.40 98.27 91.41 84.96
600 105.23 94.12 91.41 98.42 91.22 86.12
640 106.35 94.77 — 99.20 91.53 —
768 113.07 100.45 — 101.42 92.88 —

We also replayed captured CSR indices and positions with seeded Q and KV, using three processes per route and input. T=582 is cropped from native T=768 recordings.

T Captured input Base auto (µs) Head auto (µs) Head compact (µs)
582 GSM8K, variable KV 86.51 83.39 78.28
768 GSM8K, variable KV 90.53 81.84 —
582 GSM8K, full KV 89.12 85.70 79.24
768 GSM8K, full KV 92.44 86.32 —
582 Short prompt 45.38 29.33 36.76
768 Short prompt 47.30 31.45 —

The wrapper commit limits default flag allocation to eligible full-workspace H64 two-way reductions. A direct or compact T=582 eager call on a fresh stream now allocates 0 bytes of default flags (previously 524,288 bytes). With a T=66 full-workspace split, capturing after a direct-only warmup takes the separate reduction. Warming the two-way reduction on the capture stream retains a single dispatch. In the T=66 request-local replay control, current-head latencies were 27.21 µs after direct-only warmup and 24.71 µs after two-way warmup.

The current and previous heads matched on all 198 full output-and-scale digest checks for the first input bank. The new allocation regression and 48 H64 pair-reduction cases passed. Four-rank serving results below are from earlier revisions; the current-head measurements above cover the operator and graph replay.

Earlier operator and model measurements

Each full query uses 512 prefix rows and 128 window rows, H64/D512, with a 9-million-row MXFP8 prefix pool and separate data and group32 scale planes. The table reports microseconds per complete fused call using request-local indices, int64 positions, four rotating inputs, warm HIP graph replay and the median of three independent processes. Both launches and the final quantized writeback are included in the compact results. Workspace allocation precedes capture.

Queries KV length beyond bulk Candidate direct Candidate compact
257 Full 54.62 48.30
513 Full 91.42 70.58
513 Empty 61.02 67.49
528 Full 91.39 75.44
528 Empty 91.14 68.07

The T=528 direct permutation assigns ten of its last sixteen CTAs to rows in the first 512 queries. The useful split therefore depends on the query lengths and on the direct workgroup order. Callers opt in explicitly.

For an independent reference, the existing OPUS attention with separate Q RoPE/quantization and inverse-RoPE/output quantization took 100.59 us at T=513 and 99.78 us at T=528 with full KV. These measurements start from raw BF16 Q and ready-to-read KV and end at the quantized output. Window updates and the output projection are outside the timing scope.

Extending the two-way split through 600 queries

On MI355X, a sweep of every T from 577 through 600 compared direct execution with opt-in two-way splitting. All 24 sizes improved in each of three independent processes on full-length request-local indices, full-length random indices, and two captured GSM8K CSR inputs. The sweep used an experimental upper limit of 640. By T=624, the random full-length and variable-length GSM8K inputs were roughly tied. The submitted upper limit is 600.

At T=582, paired graphs on the submitted build gave the following complete operator times in microseconds (one process per input, median of nine timing rounds). The model CSR inputs are the first 582 queries of T=768 recordings, with captured indices and positions and seeded Q/KV values.

Input Direct Two-way compact
Full-length, request-local indices 91.06 84.77
GSM8K, variable-length KV 83.17 78.19
Short prompt 29.41 36.89

The default path remains direct for this shape. To select the two launches at T=582, pass num_splits=2 and a contiguous FP32 workspace of shape [70, 2, 64, 516]. Choose the route using the actual workload.

Direct KV32 path

In a separate same-card A/B against AITER 1c8b96fd, the wide-pool KV32 direct implementation reduced median latency at T=336 from 70.07 to 59.57 us, at T=448 from 73.14 to 61.84 us, and at T=768 from 113.20 to 98.04 us. These runs used random indices, int32 RoPE positions, six rotating input sets and automatic split selection. The compact-tail results above use request-local indices and int64 positions.

Validation

  • On the submitted 600-query build, 34 MI355X wide-pool cases passed with int32 and int64 positions, including compact workspace acceptance at T=600 and rejection at T=601. Across four input profiles, 36 output-and-scale hashes matched the sweep build on shared routes. The largest sampled per-query relative L2 error against the FP32 reference in this final-build comparison was 2.82%. The 577-600 extension has operator-level coverage. Four-rank end-to-end model validation for this extension is still outstanding.
  • On merge commit ccc75a1378f82a566f465ed40b8388a8aa1b5a58, after merging main at b495628a41568ea3b0289c6c7076f59a6e4c8211, all seven HIP translation units were rebuilt. On MI355X (gfx950), the merged Python wrapper and rebuilt library passed 3,219 operator contract cases, including 26 wide-pool H64 cases and 48 H64 pair-reduction cases, followed by the public decode sweep at T=257, 513, 561 and 576. The wide-pool tests exercise compact tail workspaces with int32 and int64 positions. The pair-reduction tests compare full-workspace results with and without flags and exercise graph replay. The subsequent formatting commit changed only line wrapping in the op test, with identical Python AST. The rebuilt library SHA-256 is 0f8d4a8ef8e588c06beb4a898cb0a60e55c5c5003c1c6e42accea8248623ecd4.
  • The measurements in the first results table, the direct KV32 comparison, and the four-rank model measurements are from the pre-merge implementation. Its seven changed source files matched the tested files by SHA-256 and the tested fused library SHA-256 was db924ab5f67a3758e9f34597122b78ee426f4e6f363259645f89e255cf94d14f.
  • The compact-path operator sweep covered variable CSR lengths, empty tails, int32/int64 positions and graph replay. The worst sampled per-tail-query relative L2 error against the FP32 reference was 0.02913 at the 512 boundary. The bulk output and scale bytes matched direct execution in the checked cases.
  • In a separate four-rank model experiment, an opt-in ATOM caller replayed both direct and compact graphs at T=516, 528 and 576. Two uninstrumented GSM8K runs scored 1232/1319 and 1223/1319, compared with 1223/1319 and 1227/1319 for the prior direct baseline. The serving measurements do not establish a repeatable GSM8K throughput improvement.

The ATOM caller is tracked separately from this operator change. Its underlying fusion integration is ROCm/ATOM#2903.

Testing and documentation

  • Updated the operator contract tests and the public operator docstring.
  • Ran correctness checks and performance benchmarks on MI355X (gfx950).
  • No new third-party dependencies.

Breaking changes

None. Existing callers can continue to use automatic split selection or a full-size workspace.

PR Self-Review

Reviewed revision

65d8ba1476e8c5f79d23659d3bf6a861cdcc15d6 against b495628a41568ea3b0289c6c7076f59a6e4c8211. The latest commit updates the Python wrapper and the allocation contract test.

Behavior and intent

A full additional query at the CU boundary can put a long serial KV walk on the critical path. The compact launch distributes that tail query's KV tiles across workgroups and accounts for the sink once in the final reduction.

Validation and unverified scope

Before the merge, the gfx950 operator script completed 3,171 contract cases. That public-entry-point run included python op_tests/test_fused_norm_rope_attn_rope_cast.py -b 513 528 576 -H 64 --topk 512 --window 128 --pool-rows 2048 --modes unprepared --stages decode --layout separate --splits 0. The wide-pool contract cases allocate their own buffers above the 4 GiB data-offset boundary. MI250X and MI300X were outside the hardware test scope.

PR-specific question

Automatic dispatch selects the eligible direct kernel. Compact tail splitting requires explicit splits and a matching FP32 workspace. Empty and full tails have different cost crossovers, as shown in the paired results above.

Changed op tests

op_tests/test_fused_norm_rope_attn_rope_cast.py adds H64 wide-pool decode coverage with variable CSR row counts, both RoPE position widths and compact split thresholds. It compares bulk output and scale bytes with the direct path and checks tail outputs against the reference.

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

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

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

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

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

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

@yzhou103
yzhou103 marked this pull request as ready for review December 1, 2026 06:37
@yzhou103
yzhou103 requested review from a team and a balanced review from Copilot December 1, 2026 06:37
@github-actions github-actions Bot added the HIP label Dec 1, 2026
@aiter-bot

aiter-bot commented Dec 1, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision e941267d0bd5 · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — validation answer must explicitly state what remains unverified (or say none with a reason)

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The gfx950 assembly and manual pipeline changes require GPU-specialist review, and no head-matched validation report was supplied to substantiate MI355X correctness or performance.

No open issues 🎉

What changed in this PR

This PR optimizes AITER’s fused H64 MXFP8 attention decode on MI355X for large KV pools. It adds a direct KV32 path and explicit compact tail splitting while preserving existing automatic split selection and full-size workspaces.

Changes:

  • Adds 32-row KV tiles, double-buffered shared memory, and query reordering for eligible direct calls.
  • Adds compact tail-only splitting and reduction at supported query counts near the 256- and 512-query boundaries.
  • Documents workspace requirements and extends tests for split thresholds, variable CSR lengths, wide KV addresses, and both position widths.
File Description
op_tests/​test_fused_norm_rope_attn_rope_cast.py Adds wide-pool direct and compact-tail correctness coverage.
csrc/​kernels/​mla/​fused_norm_rope_attn_rope_cast/​fused_norm_rope_attn_rope_cast.cu Adds eligibility checks, workspace validation, and dispatch.
csrc/​kernels/​mla/​fused_norm_rope_attn_rope_cast/​dispatch.hpp Defines compact-tail thresholds and launcher declarations.
csrc/​kernels/​mla/​fused_norm_rope_attn_rope_cast/​attention_64rows_reduce.cu Adds tail reduction using existing reducers.
csrc/​kernels/​mla/​fused_norm_rope_attn_rope_cast/​attention_32rows.cuh Adds direct-to-shared-memory KV loading and packed-scale handling.
csrc/​kernels/​mla/​fused_norm_rope_attn_rope_cast/​attention_32rows.cu Implements query ordering, tail partitioning, and specialized launches.
aiter/​ops/​fused_norm_rope_attn_rope_cast.py Documents compact workspace shapes and eligibility requirements.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings December 1, 2026 07:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The gfx950 LDS pipeline and compact softmax changes require human assessment of MI355X correctness and performance evidence, with head-matched validation unavailable and T=577–600 end-to-end testing still outstanding.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings December 1, 2026 08:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The gfx950 LDS pipeline and compact-tail softmax changes need MI355X expert review and runtime validation, with no independently verified head-matched report and outstanding end-to-end coverage for T=577–600.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings December 2, 2026 02:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The gfx950 assembly scheduling and compact-tail reductions lack independent, exact-head GPU correctness/performance validation and maintainer confirmation, while end-to-end validation of the 577–600-query extension remains outstanding.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings December 3, 2026 11:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The compact launcher lacks regression coverage for graph replay with changing or empty tail CSR rows, leaving its partial-write and merge behavior unverified across supported 2/4/8 splits.

1 open issue

Review effort: Balanced

@shay-li77

Copy link
Copy Markdown
Contributor

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

aiter-bot — queued behind 7 review(s); expect to start in about 73 min. The box reviews up to 4 PRs at a time.

Copilot AI balanced review requested due to automatic review settings December 4, 2026 02:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The new gfx950 pipeline and compact-tail reductions require head-matched MI355X correctness, graph-replay, and latency checks unavailable here, with four-rank T=577–600 validation still outstanding.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@aiter-bot

Copy link
Copy Markdown

⚠️ aiter-bot — this review could not complete: a problem with the review pipeline itself (bot logic / prompts), not with this PR.

the worker did not finish within AITER_AGENT_TIMEOUT=2400s; the backend answered normally -- raise it in the runner .env

@zufayu — please take a look.

Re-comment @aiter-bot review once it is resolved.

@zufayu
zufayu merged commit 66da045 into ROCm:main Dec 4, 2026
66 checks passed
zufayu added a commit that referenced this pull request Dec 4, 2026
…runcated watchdog read, size the agent timeouts for the 4-lane pool (#9201)

* [CI] review-bot: read WORK out of a binary fetch log, retry a stalled watchdog read, size the agent timeouts for the 4-lane pool

Three failure modes from the 2026-12-04 outage (6 failed runs, 01:24-03:02):

- run_one.sh extracted WORK= from the tee'd fetch log with a bare grep, so a PR
  with binary artifacts (OPUS .co blobs put NULs in that log) made grep answer
  "binary file matches" instead of the match -- a fetch that SUCCEEDED was
  reported as "fetch produced no WORK dir" on every retry (#8283/#7979/#7983).
  grep -a reads the log as text.

- watchdog.py caught only HTTPError, so a 30s socket timeout crashed the
  watchdog with a bare TimeoutError and failed a run whose review had already
  published a green card (#9178). A stalled GET is now retried (3 attempts,
  5s backoff); a POST is never retried, because a retried comment can land
  twice, and a failed POST degrades to 0, which the caller already warns about.

- AITER_AGENT_TIMEOUT=2400s was sized for one review at a time; the 4-lane
  pool serves four through the same GLM endpoint and workers measured 25-40+
  min under that load, so 2400s timed out live while the backend answered
  normally (#8983/#8541). Defaults now 3300s/agent and 6900s/run (115 min,
  still under the job's timeout-minutes of 120; check_prompts.py asserts it).

watchdog_test.py gains real-socket transport checks (the retry lives below the
_get/_post seam its fakes replace) with a mutation guard; _fetchfail_test.sh
gains the binary-log case. selftest: 156 green / 0 red.

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

* watchdog: retry a truncated response body, not just a stalled read

A response that dies mid-body raises http.client.IncompleteRead -- an
HTTPException, not an OSError -- so the OSError-only retry net added for
the 2026-12-04 stall let it escape unretried and unnamed: the same
bare-traceback crash one layer up, and _post's RuntimeError guard could
not degrade it either. Name the family in the catch so a truncated GET is
retried like a stalled one and a truncated POST degrades to 0.

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

---------

Co-authored-by: zufayu <[email protected]>
Co-authored-by: Claude Code <[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.

7 participants