Repository navigation
[Triton/Gluon] Retune unified attention configs for gfx950 - #4918
Merged
brunomazzottiamd merged 1 commit intoAug 25, 2026
Merged
Conversation
Contributor
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
PR title tags: |
brunomazzottiamd
requested changes
Aug 24, 2026
brunomazzottiamd
left a comment
Contributor
There was a problem hiding this comment.
I have two requests:
- Simplify the Boolean logic of your new function.
- Use better function and variable names. Retune isn't future proof and can be ambiguous.
nidal567
force-pushed
the
gfx950-unified-attn-selector-retune
branch
from
August 24, 2026 20:44
550a56b to
f64559f
Compare
brunomazzottiamd
previously approved these changes
Aug 25, 2026
nidal567
force-pushed
the
gfx950-unified-attn-selector-retune
branch
from
August 25, 2026 14:25
f64559f to
c76ca13
Compare
brunomazzottiamd
approved these changes
Aug 25, 2026
vorapolsiloai
added a commit
to vorapolsiloai/aiter
that referenced
this pull request
Aug 26, 2026
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]>
9 of 10 tasks
vorapolsiloai
added a commit
to vorapolsiloai/aiter
that referenced
this pull request
Aug 28, 2026
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]>
vorapolsiloai
added a commit
to vorapolsiloai/aiter
that referenced
this pull request
Sep 1, 2026
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]>
vorapolsiloai
added a commit
to vorapolsiloai/aiter
that referenced
this pull request
Sep 2, 2026
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]>
vorapolsiloai
added a commit
to vorapolsiloai/aiter
that referenced
this pull request
Sep 2, 2026
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]>
azaidy
pushed a commit
that referenced
this pull request
Sep 9, 2026
…ecode (#4761) * unified_attention: decode/prefill launch-config tuning + prefill causal-mask-skip kernel optimization * unified_attention: narrow gfx950 prefill fast path Restrict mask skipping to benchmark-supported FP8 prefill shapes and add boundary-focused coverage, preserving current-main decode and config behavior after #4918. * unified_attention: remove fast-path comments Keep the optimized loop self-documenting and avoid adding commentary beyond existing upstream code. Co-authored-by: Santosh Hiremath <[email protected]> * unified_attention: remove redundant fast-path tests The existing gfx950 matrix already exercises the optimized default path. * unified_attention: move fast-path gate to gfx950 config Keep the refactored wrapper clean while preserving the benchmarked scope. * unified_attention: simplify fast-path gating Use one standard positive config entry and keep exact safety checks compile-time in the kernel. * unified_attention: make unmasked split config-driven 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. * unified_attention: compile out disabled split loop Nest the unmasked loop under its constexpr flag so untuned configurations retain only the original masked loop and avoid unnecessary resource usage. * unified_attention: reject split loop with shuffled cache Prevent unsafe tuning configurations from running the unshuffled split loop against shuffled KV data. --------- Co-authored-by: Mohsen Saffari <[email protected]> Co-authored-by: Santosh Hiremath <[email protected]> Co-authored-by: Mehmet Cagri <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
On gfx950, Triton 3.8 enables direct-to-LDS async copy by default, and for this kernel that default backfires. The lowering only stays vectorized when
TILE_SIZEis 64, and below that, it collapses to 4 bytes per lane and hands ads_bpermuteaddress shuffle off every copy. The shipped selector of the old wrapper forunified_attentionsetsTILE_SIZEfrom the kv-cache block size, so any deployment running block 16 or 32 gets the slow form.That shows up as 51 regressions across 108-shape GPT-OSS decode suite against the Triton-3.4.0 reference:
No issues with code-gen, no issues with the kernel or compiler flag
TRITON_HIP_USE_ASYNC_COPY=1. We tune for the right config selection to get the desired results through the wrapper file for GPT-OSS.Technical Details
All changes are in
select_2d_config/select_3d_config. Four parts, each behind ais_gfx950_retune()guard:
TILE_SIZE = 64instead ofmin(64, next_power_of_2(block_size)). This is what brings back the16 B/lane
buffer_load_dwordx4 ... ldscopy. With a wide copy the old pipeline depth and occupancy hint nolonger fit, so
num_stagesgoes 3 → 2 andwaves_per_eu2 → 1.occmultiplier ontarget_num_prgms, which was inflating the target and over-segmenting theKV split. What is left is
target_num_prgms / num_2d_prgms— for decode just1024 / (B * KVH)— giving4, 2, 32, 16 across the four (batch, kv-head) groups. Those are the values we measured as optimal, from a
formula already implicit in the code rather than a lookup table.
MIN_SEGMENTS = 1(wasmin(8, MAX_SEGMENTS)). The old floor clamps a split of 4 or 2 back up to 8and silently cancels the change above.
reduce_num_warpsonnum_segments <= 2instead of== MIN_SEGMENTS. With the floor at 1 thatequality never fires, and the
B*KVH >= 512group would lose the 1-warp reduce it previously got atnum_segments == 8. A small segment count is the real condition, not equality with floor.The scope is deliberately narrow -
is_gfx950_retune()requiresDEVICE_ARCH == "gfx950". No other architectures are affected.Test Plan
Performance: 108-shape GPT-OSS decode suite (bf16 Q + fp8 e4m3 paged KV,
head_dim=64,seqlen_q=1, B in {1,32,64}, block in {16,32,64},seqlen_kin {1k,4k,8k}, sliding window in {none,128}). Wrapper-level A/B between two real checkouts. No per-shape config overrides, so the selector itself produces every config.TRITON_HIP_USE_ASYNC_COPY=1on both arms.rocprofv3 --kernel-trace --stats, 200 launches per run, median of the 3 reps chosen for stable average number.Correctness: both configs run on identical seeded inputs in one process, compared against an fp8-matched fp32 paged-attention reference; reported as proposed-vs-default error, not only error-vs-reference. Includes a no-op shape per path (config identical on both arms) as a determinism control. Also run
pytest op_tests/triton_tests/attention/test_unified_attention.py -vto ensure all tests passConfig justification: each retuned value was bracket-swept on both sides to confirm it is a measured local optimum rather than a fitted value, and the 2D
num_stages/waves_per_eupairing was validated across all 54 2D shapes before being generalized.Test Result
sw=128sw=noneAll regressions eliminated (0 after), no status degrades, and the selector collapses 108 shapes onto 7 distinct constexpr signatures.
3 of 108 are slower than the same-session baseline, all 3D
B=1:B1_tp8_QH8_KVH1_D64_BLK16_SWnone_SK1024+3.20% (6.555 -> 6.765 us, still −21.3% vs reference), plus +0.24% and +0.15% on two shapes where the selector emits a byte-identical config on both arms (inside the +/-1.5% null-control noise floor). Only the +3.20% case is a real loss.Correctness: 2D is bitwise identical to the shipping config on the shapes where only
num_stages/waves_per_euchange, confirming those knobs are scheduling-only. 3D error vs the reference is equal to the default on 15/17 shapes and one bf16 ULP larger on 2/17, never worse; proposed-vs-default agrees to <= 1.0 ULP everywhere.1088 passed, 1056 skipped, 804 warnings in 247.61s (0:04:07)Caveats: the 3D
B=1slice measured ~12% faster than the archived baseline (sanity ratio 0.877, outside the window on the fast side), so its vs-reference figures are optimistic by roughly that margin - its same-session delta is unaffected. 3DB=1is also where gains are thinnest (median −1.6% overall, −8.9% on the 12 shapes whose config actually changes, no-op at block 64).Per-shape results (108 shapes)
shippedandfinaltests were measured back-to-back in the same session.You can find the results here in this excel link
Submission Checklist