Repository navigation
[Triton/Gluon] [PERF] Optimize Triton unified attention prefill and decode - #4761
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
86520e9 to
b11a42f
Compare
|
Two failed MI35X standard-test shards are unrelated to this PR's unified-attention changes and need a maintainer rerun:
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? |
|
@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. |
7d88ad6 to
c4638c7
Compare
|
@cagrikymk Thanks for the feedback. I've updated the PR:
Validation:
Fresh E2E crossover results against post-#4918 main:
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. |
b458405 to
0a20fb8
Compare
0a20fb8 to
65ec200
Compare
…al-mask-skip kernel optimization
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]>
90649bf to
110cefd
Compare
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]>
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]>
|
Hey I think we have two PRs that are somewhat close to each other, see my comment #5158 (comment) |
… 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]>
Summary
Integration context
The PR branch is rebased onto AITER
mainat5e4a8119,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 atc4638c76.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.
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 baselineremained
35c652ed3bd34e5d5828954e1545babc9255a69a. Two-round same-GPUor same-pair crossover placement was used on GPUs 0–3.
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 thecombined 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
35c652ed3bd34e5d5828954e1545babc9255a69ac4638c761293b92ba41dad628c71b77e2131dc4e5e4a8119cc2a6b578667102b75b4f321852dfd8c389fb3d32494729561f981ba5d0be898dc189644Test plan
mainat5e4a8119cc2a6b578667102b75b4f321852dfd8cgit diff --check upstream/main...HEADc3fe5b821— all four published workloads passed regression guardrailsCI note
CI is rerunning after rebasing onto the merged #5088 refactor. The previous
pre-refactor head passed all required checks.
Made with Cursor