Skip to content

[Triton/Gluon] Retune unified attention configs for gfx950 - #4918

Merged
brunomazzottiamd merged 1 commit into
ROCm:mainfrom
nidal567:gfx950-unified-attn-selector-retune
Aug 25, 2026
Merged

brunomazzottiamd merged 1 commit into
ROCm:mainfrom
nidal567:gfx950-unified-attn-selector-retune

Conversation

@nidal567

@nidal567 nidal567 commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

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_SIZE is 64, and below that, it collapses to 4 bytes per lane and hands a ds_bpermute address shuffle off every copy. The shipped selector of the old wrapper for unified_attention sets TILE_SIZE from 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:

  • 30 on the sliding-window (2D) path
  • 21 on the non-windowed (3D) path

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 a is_gfx950_retune()
guard:

  • 2D: pin TILE_SIZE = 64 instead of min(64, next_power_of_2(block_size)). This is what brings back the
    16 B/lane buffer_load_dwordx4 ... lds copy. With a wide copy the old pipeline depth and occupancy hint no
    longer fit, so num_stages goes 3 → 2 and waves_per_eu 2 → 1.
  • 3D: drop the occ multiplier on target_num_prgms, which was inflating the target and over-segmenting the
    KV split. What is left is target_num_prgms / num_2d_prgms — for decode just 1024 / (B * KVH) — giving
    4, 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.
  • 3D: set MIN_SEGMENTS = 1 (was min(8, MAX_SEGMENTS)). The old floor clamps a split of 4 or 2 back up to 8
    and silently cancels the change above.
  • 3D: trigger reduce_num_warps on num_segments <= 2 instead of == MIN_SEGMENTS. With the floor at 1 that
    equality never fires, and the B*KVH >= 512 group would lose the 1-warp reduce it previously got at
    num_segments == 8. A small segment count is the real condition, not equality with floor.

The scope is deliberately narrow - is_gfx950_retune() requires DEVICE_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_k in {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=1 on 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 -v to ensure all tests pass

Config 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_eu pairing was validated across all 54 2D shapes before being generalized.

Test Result

scope before (regression / ok / improvement) after geomean vs current geomean vs Triton-3.4
2D sw=128 11 / 24 / 19 0 / 0 / 54 1.433x 1.447x
3D sw=none 17 / 2 / 35 0 / 1 / 53 1.308x 1.414x
All 108 28 / 26 / 54 0 / 1 / 107 1.369x 1.430x
  • All 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_eu change, 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.

    • Pytest output: 1088 passed, 1056 skipped, 804 warnings in 247.61s (0:04:07)
  • Caveats: the 3D B=1 slice 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. 3D B=1 is 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)

shipped and final tests were measured back-to-back in the same session.

You can find the results here in this excel link

Submission Checklist

@nidal567
nidal567 requested a review from a team August 21, 2026 19:07
@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 4918 --add-label <label>

PR title tags:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf] and op tags like [MLA] are left untouched. Add the no-auto-title label to opt this PR out of title tagging.

@github-actions github-actions Bot changed the title Retune unified attention configs for gfx950 [Triton/Gluon] Retune unified attention configs for gfx950 Aug 21, 2026
@nidal567 nidal567 self-assigned this Aug 21, 2026

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

I have two requests:

  1. Simplify the Boolean logic of your new function.
  2. Use better function and variable names. Retune isn't future proof and can be ambiguous.

@nidal567
nidal567 force-pushed the gfx950-unified-attn-selector-retune branch from 550a56b to f64559f Compare August 24, 2026 20:44

@brunomazzottiamd brunomazzottiamd 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!

@brunomazzottiamd
brunomazzottiamd merged commit 35c652e into ROCm:main Aug 25, 2026
76 checks passed
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]>
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]>
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.

2 participants