Skip to content

[Triton/Gluon] [PERF] Optimize Triton unified attention prefill and decode - #4761

Merged
azaidy merged 12 commits into
ROCm:mainfrom
vorapolsiloai:perf/unified-attention-triton-opt
Sep 9, 2026
Merged

azaidy merged 12 commits into
ROCm:mainfrom
vorapolsiloai:perf/unified-attention-triton-opt

Conversation

@vorapolsiloai

@vorapolsiloai vorapolsiloai commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • skip per-element causal and bounds masking for fully visible prefill tiles in the Triton 2D unified-attention kernel
  • restrict the fast path to gfx950, head size 128, FP8 Q/FP8 KV, query length at least 256, non-windowed, non-shuffled prefill
  • preserve current-main dispatch and launch configurations, including the gfx950 tuning merged in [Triton/Gluon] Retune unified attention configs for gfx950 #4918; this PR no longer overrides decode routing or launch configs
  • select the eligible family through the gfx950 JSON configuration introduced by [Triton/Gluon] Refactor Unified Attention #5088, with exact safety checks kept compile-time in the kernel and the refactored wrapper unchanged

Integration context

The PR branch is rebased onto AITER main at
5e4a8119,
including #5088 and
#4918. The kernel patch is unchanged
from the benchmarked candidate. A 480-case configuration and effective-gate
comparison confirmed that the JSON migration preserves all existing launch
parameters and enables the fast loop only for the benchmarked shape family.

The end-to-end comparison used two derivatives of the same pinned Image C
parent (sha256:653c62aad83496c96748cd28151810f13757509120f548a389d555527957fbb4).
The baseline derivative installed the two unified-attention source files from
35c652ed; the candidate installed those files from this PR at c4638c76.
All other image contents, model files, runtime flags, and workload inputs were
held fixed.

Performance validation

Tested on MI355X/gfx950 with Qwen3-VL-235B-A22B-Instruct-MXFP4. Servers were
NUMA-pinned to disjoint GPUs, clients were launched synchronously, and results
used same-GPU or same-pair crossover placement. Full-node GPU utilization and
temperatures were sampled throughout the runs.

  • TP1, 60k input / 600 output, concurrency 32: +9.10% median output throughput; 8.34% lower duration; 9.25% lower mean TTFT; 7.91% lower mean TPOT across four same-GPU comparisons
  • TP2, 60k input / 600 output, concurrency 32: +5.64% median output throughput; 5.33% lower duration; 5.98% lower mean TTFT; 5.17% lower mean TPOT across two same-pair comparisons
  • TP1, 8k input / 1k output, concurrency 128: +2.35% median output throughput; 2.30% lower duration; 4.51% lower mean TTFT; 2.14% lower mean TPOT across four same-GPU comparisons
  • TP2, 8k input / 1k output, concurrency 256: +1.62% combined median output throughput; 1.59% lower duration; 2.30% lower mean TTFT; 1.53% lower mean TPOT across two seeds and two same-pair placements. Three of four pair-seed comparisons were positive; the remaining comparison was -0.54%, so no repeatable short-context regression was observed.

Latest-head E2E revalidation (2026-09-03)

After the review and rebase changes, the four published E2E workloads were
re-run against the same frozen baseline and Image C parent. The candidate was
the current PR head c3fe5b8217ed584aabc3cf1a36749d23cd7f7e5c; the baseline
remained 35c652ed3bd34e5d5828954e1545babc9255a69a. Two-round same-GPU
or same-pair crossover placement was used on GPUs 0–3.

  • TP1, 60k input / 600 output, concurrency 32: +8.45% median output throughput; 7.79% lower duration; 8.27% lower mean TTFT; 7.69% lower mean TPOT (-0.65 percentage points versus the previously published +9.10% throughput result)
  • TP2, 60k input / 600 output, concurrency 32: +7.00% median output throughput; 6.54% lower duration; 7.48% lower mean TTFT; 6.40% lower mean TPOT (+1.36 percentage points versus the previously published +5.64% throughput result)
  • TP1, 8k input / 1k output, concurrency 128: +2.46% median output throughput; 2.40% lower duration; 5.06% lower mean TTFT; 2.20% lower mean TPOT (+0.11 percentage points versus the previously published +2.35% throughput result)
  • TP2, 8k input / 1k output, concurrency 256: +1.98% combined median output throughput; 1.94% lower duration; 3.12% lower mean TTFT; 1.84% lower mean TPOT across seeds 16 and 24 (+0.36 percentage points versus the previously published +1.62% throughput result)

All 28 measured client arms returned status 0 and completed the expected
prompt counts. Every workload passed the regression guardrails, so the frozen
old candidate diagnostic was not needed. One TP2 short pair/seed comparison
was negative (-1.61%), but it did not repeat on that physical pair and the
combined median remained positive. Test GPUs stayed healthy, with sampled
junction temperatures below 59 C.

An instrumented serving request confirmed that the production path reaches the
2D prefill kernel with head size 128, FP8 Q, FP8 KV, no sliding window, no
shuffled cache, and the guarded fast path enabled.

Rebase and benchmark provenance

  • Frozen benchmark baseline: 35c652ed3bd34e5d5828954e1545babc9255a69a
  • Benchmarked candidate: c4638c761293b92ba41dad628c71b77e2131dc4e
  • Current rebase base: 5e4a8119cc2a6b578667102b75b4f321852dfd8c
  • Original optimization source: 389fb3d32494729561f981ba5d0be898dc189644

Test plan

  • rebase onto AITER main at 5e4a8119cc2a6b578667102b75b4f321852dfd8c
  • preserve the [Triton/Gluon] Refactor Unified Attention #5088 wrapper, select the eligible family in the gfx950 JSON config, and retain exact safety checks in the kernel
  • preserve [Triton/Gluon] Retune unified attention configs for gfx950 #4918 and gfx1151 dispatch/config behavior
  • git diff --check upstream/main...HEAD
  • validate 480 config combinations; existing launch parameters remain unchanged
  • existing full unified-attention correctness suite on gfx950 — 1,088 passed, 1,056 skipped
  • paired unified-attention microbenchmarks — 21 shapes × 3 alternating repetitions; 1.018× overall geomean with no regression greater than 2%
  • TP1 and TP2 end-to-end serving crossover at 8k/1k and 60k/600
  • latest-head E2E revalidation at c3fe5b821 — all four published workloads passed regression guardrails
  • upstream CI rerun on the current rebased head

CI note

CI is rerunning after rebasing onto the merged #5088 refactor. The previous
pre-refactor head passed all required checks.

Made with Cursor

@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
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: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 4761 --add-label <label>

@vorapolsiloai
vorapolsiloai force-pushed the perf/unified-attention-triton-opt branch from 86520e9 to b11a42f Compare August 18, 2026 14:02
@vorapolsiloai
vorapolsiloai marked this pull request as ready for review August 18, 2026 14:03
@vorapolsiloai
vorapolsiloai requested a review from a team August 18, 2026 14:03
@github-actions github-actions Bot changed the title [PERF] Optimize Triton unified attention prefill and decode [Triton/Gluon] [PERF] Optimize Triton unified attention prefill and decode Aug 18, 2026
@vorapolsiloai

vorapolsiloai commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Two failed MI35X standard-test shards are unrelated to this PR's unified-attention changes and need a maintainer rerun:

  • shard 3: Docker could not pull rocm/pytorch:rocm7.2.4_ubuntu24.04_py3.12_pytorch_release_2.10.0 because registry-1.docker.io returned a TLS handshake timeout, so no test ran;
  • shard 4: unchanged op_tests/test_moe_2stage.py exhausted GPU memory while expanding FP4 reference weights (48.19 GiB requested with 41.02 GiB free).

The PR's local full unified-attention suite passed 1,088 tests (1,056 skipped). I attempted the job rerun API, but fork authors do not have the required repository permission. Could a maintainer please rerun those failed shards?

@zufayu
zufayu requested a review from vgokhale August 19, 2026 01:24
@cagrikymk
cagrikymk self-requested a review August 25, 2026 19:48
@cagrikymk

Copy link
Copy Markdown
Contributor

@vorapolsiloai Thank you for the contribution!

Could you trim the comments a bit? They are bulky and hard to read. If the code somehow explains the logic, comments should be minimal.

Also, besides the e2e to tests, can you run broader unit benchmarks? To highlight we dont regress other cases? I guess your new configs are well conditioned overall. If so, you can just focus on the cases you modified.

@vorapolsiloai
vorapolsiloai force-pushed the perf/unified-attention-triton-opt branch 2 times, most recently from 7d88ad6 to c4638c7 Compare August 26, 2026 07:00
@vorapolsiloai

Copy link
Copy Markdown
Contributor Author

@cagrikymk Thanks for the feedback. I've updated the PR:

  • Removed the comments introduced by this PR and made the fast-path guard self-describing.
  • Rebased over main@35c652ed, including [Triton/Gluon] Retune unified attention configs for gfx950 #4918.
  • Removed the overlapping decode-routing and launch-config overrides. The remaining optimization is limited to guarded gfx950 FP8-Q/FP8-KV prefill.

Validation:

  • Full correctness suite: 1,103 passed, 1,056 skipped
  • Unit benchmarks: 21 shapes × 3 alternating repetitions, 1.018× geomean, with no paired regression greater than 2%
  • Added boundary/control coverage for query length, dtype, sliding window, shuffled cache, head size, block size, cached prefixes, and GQA

Fresh E2E crossover results against post-#4918 main:

  • TP1 60k/600: +9.10% output throughput
  • TP2 60k/600: +5.64%
  • TP1 8k/1k: +2.35%
  • TP2 8k/1k: +1.62% combined median across two seeds and two GPU-pair placements; three of four comparisons were positive, with the remaining comparison at −0.54%

Instrumentation also confirmed that the production workload reaches the 2D prefill kernel with FP8 Q/FP8 KV and enables the guarded fast path.

I replaced the stale pre-rebase performance results in the PR description. Black, Ruff, dependency checks, and all eight MI35X Triton shards pass; the remaining red gate jobs failed in check-orchestration steps rather than test shards.

@vorapolsiloai
vorapolsiloai force-pushed the perf/unified-attention-triton-opt branch 2 times, most recently from b458405 to 0a20fb8 Compare September 1, 2026 18:59
@vorapolsiloai
vorapolsiloai force-pushed the perf/unified-attention-triton-opt branch from 0a20fb8 to 65ec200 Compare September 2, 2026 07:05
@vorapolsiloai vorapolsiloai mentioned this pull request Sep 2, 2026
3 of 4 tasks
msaffari-amd and others added 6 commits September 2, 2026 14:45
Restrict mask skipping to benchmark-supported FP8 prefill shapes and add boundary-focused coverage, preserving current-main decode and config behavior after ROCm#4918.

Co-authored-by: Cursor <[email protected]>
Keep the optimized loop self-documenting and avoid adding commentary beyond existing upstream code.

Co-authored-by: Santosh Hiremath <[email protected]>
Co-authored-by: Cursor <[email protected]>
The existing gfx950 matrix already exercises the optimized default path.

Co-authored-by: Cursor <[email protected]>
Keep the refactored wrapper clean while preserving the benchmarked scope.

Co-authored-by: Cursor <[email protected]>
Use one standard positive config entry and keep exact safety checks compile-time in the kernel.

Co-authored-by: Cursor <[email protected]>
@vorapolsiloai
vorapolsiloai force-pushed the perf/unified-attention-triton-opt branch from 90649bf to 110cefd Compare September 2, 2026 14:46
Rename the flag around the optimization it controls and leave workload selection to architecture configs so future tuned families can opt in without kernel changes.

Co-authored-by: Cursor <[email protected]>
vorapolsiloai and others added 2 commits September 2, 2026 16:42
Nest the unmasked loop under its constexpr flag so untuned configurations retain only the original masked loop and avoid unnecessary resource usage.

Co-authored-by: Cursor <[email protected]>
Prevent unsafe tuning configurations from running the unshuffled split loop against shuffled KV data.

Co-authored-by: Cursor <[email protected]>
@alexnails

alexnails commented Sep 2, 2026 •

Copy link
Copy Markdown

Hey I think we have two PRs that are somewhat close to each other, see my comment #5158 (comment)

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

LGTM!

@azaidy
azaidy merged commit 337f15b into ROCm:main Sep 9, 2026
98 of 100 checks passed
alexnails added a commit to alexnails/aiter that referenced this pull request Sep 29, 2026
… to shuffled KV

Follow-up to ROCm#4761, which split the 2-D prefill tile loop into an unmasked
bulk pass plus a masked tail pass behind SPLIT_UNMASKED_LOOP. That change
carried the bulk pass as a second inline copy of the tile body, and the copy
implemented only the per-token cache layout, so shuffled KV was excluded by
static_assert.

- Factor the tile body into _attention_tile(MASKED: tl.constexpr), called by
  both loops. One body, so future masking/scaling changes cannot drift apart
  between them, and the shuffled-cache branch comes along for free: the
  static_assert excluding shuffled KV is dropped.
- Clamp the bulk bound into [tile_start, tile_end]. context_len goes negative
  when a sequence carries more query tokens than cached keys, and the floor
  division would otherwise hand the masked loop a negative first tile.
- tl.static_assert that the unmasked pass never sees a sliding window, and
  strip SPLIT_UNMASKED_LOOP in the wrapper for windowed and decode calls
  whatever the table says: the bulk pass drops the window bound along with the
  causal one, so an entry missing its SW sibling would otherwise be silently
  wrong rather than slow.
- Add FUSE_QK_SCALE, an opt-in config key that folds qk_scale into the exp2
  argument. Refused for softcap / ALiBi / qq-bias inside the kernel and for a
  non-positive softmax_scale in the wrapper, since the folded maximum relies
  on scaling being monotone.

The tuned table is unchanged: the existing SPLIT_UNMASKED_LOOP entry keeps
its behaviour and no new entries are enabled here.

Tests force the config keys per case, check each shape really reaches the 2-D
kernel, compare split against stock elementwise within a few bf16 ULP, and
cover bf16 and fp8, with and without sinks, head_size 64 and 512, a ragged
batch with negative context_len, and shuffled KV.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants