Skip to content

[Triton/Gluon] Refactor Unified Attention - #5088

Merged
cagrikymk merged 24 commits into
mainfrom
farlukas/unified-attention-refactor
Sep 2, 2026
Merged

cagrikymk merged 24 commits into
mainfrom
farlukas/unified-attention-refactor

Conversation

@farlukas

Copy link
Copy Markdown
Collaborator

Motivation

The unified attention kernels currently rely on if-else-based heuristics and every kernel (2d, 3d, and reduce) for each arch launches from the same main unified_attention wrapper which will result in the function growing for every new arch support, making it harder to maintain and read.

Technical Details

  • Created a new shared _UAParams class that can be passed to future
  • Added a backend parameter to control which kernel backend to launch
  • Split every different kernel launch into its own subwrapper (triton and arch-specific gluon kernels) to simplify adding new arch support in the future
  • Created a new get_unified_attention_config function for wrappers

Test Plan

pytest -v op_tests/triton_tests/attention/test_unified_attention.py

Test Result

Submission Checklist

@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
multigpu 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: 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 5088 --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.

@farlukas
farlukas force-pushed the farlukas/unified-attention-refactor branch from bc8c42b to 810f2cb Compare August 28, 2026 18:59
@farlukas
farlukas force-pushed the farlukas/unified-attention-refactor branch from a158214 to 665c87f Compare August 31, 2026 16:21
@farlukas
farlukas marked this pull request as ready for review September 1, 2026 16:15
@farlukas
farlukas requested a review from a team September 1, 2026 16:15
@cagrikymk
cagrikymk self-requested a review September 1, 2026 18:14
@zufayu
zufayu requested review from a team and azaidy September 2, 2026 01:22
@cagrikymk
cagrikymk merged commit 0da135e into main Sep 2, 2026
128 of 134 checks passed
@cagrikymk
cagrikymk deleted the farlukas/unified-attention-refactor branch September 2, 2026 02:03
@Boss2002n
Boss2002n requested a balanced review from Copilot September 2, 2026 03:00

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

Missing architecture configs and unsupported Triton MXFP4 routing introduce runtime failures and incorrect results.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Refactors unified attention into backend-specific launch wrappers backed by architecture-specific JSON tuning.

Changes:

  • Adds _UAParams and Triton/Gluon dispatch wrappers.
  • Moves launch heuristics into a shared config resolver and per-architecture JSON.
  • Extends tests and benchmarks with backend selection.
File summaries
File Description
aiter/ops/triton/attention/unified_attention.py Refactors dispatch and kernel launch wrappers.
aiter/ops/triton/utils/unified_attention_utils.py Adds config lookup and derived tuning logic.
aiter/ops/triton/configs/gfx950/triton/attention/unified_attention/DEFAULT.json Adds gfx950 Triton tuning.
aiter/ops/triton/configs/gfx942/triton/attention/unified_attention/DEFAULT.json Adds gfx942 Triton tuning.
aiter/ops/triton/configs/gfx1250/triton/attention/unified_attention/DEFAULT.json Adds gfx1250 Triton tuning.
aiter/ops/triton/configs/gfx1250/gluon/attention/unified_attention/DEFAULT.json Adds gfx1250 Gluon tuning.
aiter/ops/triton/configs/gfx1201/triton/attention/unified_attention/DEFAULT.json Adds gfx1201 Triton tuning.
aiter/ops/triton/configs/gfx1200/triton/attention/unified_attention/DEFAULT.json Adds gfx1200 Triton tuning.
aiter/ops/triton/configs/gfx1151/triton/attention/unified_attention/DEFAULT.json Adds gfx1151 Triton tuning.
aiter/ops/triton/configs/gfx1100/triton/attention/unified_attention/DEFAULT.json Adds gfx1100 Triton tuning.
op_tests/triton_tests/attention/test_unified_attention.py Adds backend-parameterized coverage.
op_tests/op_benchmarks/triton/bench_unified_attention.py Adds benchmark backend selection.
Review details
  • Files reviewed: 12/12 changed files
  • Comments generated: 5
  • Review effort level: Balanced

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +167 to +170
if backend == "gluon":
assert (
_is_gluon_available()
), f"Gluon backend requires one of {_GLUON_SUPPORTED_ARCHS}, got '{get_arch()}'"
Comment on lines +212 to +216
cfg_dir = resolve_config_dir("attention", _CONFIG_NAME, backend=backend, arch=arch)
config = load_config_json(f"{cfg_dir}/DEFAULT.json", required=False)
if config is None:
raise AssertionError(
f"Required config file doesn't exist: {cfg_dir}/DEFAULT.json"
Comment on lines +339 to +343
use_gluon_3d = is_3d_gluon_available(params, backend)
if use_gluon_3d:
if DEVICE_ARCH == "gfx1250":
_unified_attention_3d_gfx1250(
params,
Comment on lines +263 to +267
def get_unified_attention_config(
op: str,
params,
backend: str = "triton",
arch: str | None = None,
help="Sliding window size (default: disabled)",
)
parser.add_argument(
"-backend",
mustafayildirim added a commit to mustafayildirim/aiter that referenced this pull request Sep 8, 2026
The upstream refactor (ROCm#5088) replaced select_2d_config with per-arch
JSON config tables, but the D-axis GEQ entries (D_GEQ_512, D_GEQ_256)
shadow the Q_GEQ_256 entry (BLOCK_M=128) for models with head_size
>= 256 — so large prefills still run at BLOCK_M=16 (e.g. Gemma-4,
head_dim 256/512).

Add head_size-aware composite keys so large prefill gets BLOCK_M=128
while keeping the head-size-specific num_warps/num_stages/TILE_SIZE
from ROCm#4044:

  D_GEQ_512.Q_GEQ_256: BLOCK_M=128, warps=4, stages=2, TILE=16
  D_GEQ_256.Q_GEQ_256: BLOCK_M=128, warps=2, stages=2, TILE=32

The launch wrapper already raises BLOCK_M to next_pow2(nqpkv) after
the lookup, so these entries are safe for any GQA ratio (Copilot's
note on the previous Python-based fix is moot in table form).

Measured on gfx942 (MI325X) with Gemma-4-31B FP8-block, 32k in / 1k
out: 5.9% e2e latency improvement (17.13s -> 16.12s warm avg), 7.8%
mean ITL improvement (16.8ms -> 15.5ms/tok). Related: ROCm#4044 (the
original Python-tier fix this replaces), ROCm#5027 (fused QK-norm RoPE
with head_dim 512 + weightless V-norm, complementary Gemma-4 path).

Signed-off-by: Mustafa Yildirim <[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.

4 participants