Repository navigation
[Triton/Gluon] Refactor Unified Attention - #5088
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
PR title tags: |
bc8c42b to
810f2cb
Compare
a158214 to
665c87f
Compare
There was a problem hiding this comment.
🟡 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
_UAParamsand 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.
| if backend == "gluon": | ||
| assert ( | ||
| _is_gluon_available() | ||
| ), f"Gluon backend requires one of {_GLUON_SUPPORTED_ARCHS}, got '{get_arch()}'" |
| 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" |
| use_gluon_3d = is_3d_gluon_available(params, backend) | ||
| if use_gluon_3d: | ||
| if DEVICE_ARCH == "gfx1250": | ||
| _unified_attention_3d_gfx1250( | ||
| params, |
| 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", |
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]>
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_attentionwrapper which will result in the function growing for every new arch support, making it harder to maintain and read.Technical Details
_UAParamsclass that can be passed to futurebackendparameter to control which kernel backend to launchget_unified_attention_configfunction for wrappersTest Plan
Test Result
Submission Checklist