Skip to content

[Triton/Gluon] fav3_sage: RDNA3 (gfx1100) support: FP16 V and a tuned gfx1100 table - #6770

Merged
brunomazzottiamd merged 3 commits into
ROCm:mainfrom
TwelveNights:triton-fav3-sage-rdna3
Nov 4, 2026
Merged

brunomazzottiamd merged 3 commits into
ROCm:mainfrom
TwelveNights:triton-fav3-sage-rdna3

Conversation

@TwelveNights

@TwelveNights TwelveNights commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

fav3_sage (SageAttention v1: INT8 QK, FP8 PV) has tuned tables only for gfx942 and gfx950. Other archs use the gfx942 table. On gfx1100 (Radeon PRO W7900) the results are correct, but the op is not usable:

  • It runs at 5-6 TFLOP/s. This is 4x slower than torch SDPA and 10x slower than aiter's own bf16 Triton MHA on the same GPU.
  • The first call compiles for 9 minutes at 4608 tokens and for approximately 40 minutes at 32760 tokens. MAX_SEQLENS_* are constexpr, so each new sequence length compiles again. The unit tests did 17 cases in 27 minutes.

There are two causes:

  1. FP8 V. RDNA3 has no FP8 WMMA. Triton converts the FP8 V tile and the FP8 P tile to FP16 in software in the inner loop. With FP8 V, the kernel stays at approximately 8 TFLOP/s for each tile size that we tried.
  2. The gfx942 tile. BLOCK_M=256, BLOCK_N=128, num_warps=8 is too large for wave32 with 256 VGPRs per lane. At head dim 128 it spills more than 1000 VGPRs (183 at head dim 64).

Technical details

Three commits, 5 files, +161 / -27:

 .../_triton_kernels/quant/sage_attention_quant.py  |  8 +-
 aiter/ops/triton/attention/fav3_sage.py            | 33 +++++++--
 .../triton/attention/fav3_sage/DEFAULT.json        | 14 ++++
 .../triton/quant/sage_attention_quant_wrappers.py  | 47 ++++++++----
 op_tests/triton_tests/attention/test_fav3_sage.py  | 86 +++++++++++++++++++++-
  1. fav3_sage.py: when arch_info.is_fp8_avail() is False, the wrapper asks sage_quant for an FP16 V instead of an FP8 V. The kernel takes the P*V type from V (p.to(v.type.element_ty)), so it uses FP16 WMMA. There is no attention kernel change. gfx942, gfx950, gfx1200, gfx1201 and gfx1250 have FP8, so they keep the FP8 path. fav3_sage_wrapper_func has a v_dtype argument (default: FP8 if the arch has FP8, else FP16), so the FP16/BF16 V path can be tested on every arch.
  2. configs/gfx1100/triton/attention/fav3_sage/DEFAULT.json: BLOCK_M=64, BLOCK_N=64, num_warps=4, num_stages=1, waves_per_eu=1, PRE_LOAD_V=false. This tile does not spill (250 VGPRs at head dim 128, 239 at head dim 64; 16 KB LDS). fwd_a3_tuned has the same values, so a3_tuned=True does not change the launch on gfx1100.
  3. sage_quant (review follow-up): V is quantized only when v_dtype is FP8. A 16-bit V is passed through (cast to v_dtype if needed) with a v_scale of ones, and no V programs are launched; sage_quant_kernel guards the V branch with a QUANTIZE_V constexpr (replacing the unused FP8_MAX). FP8_TYPE / FP8_MAX / v_fp8 are renamed v_dtype / v_dtype_max / v_out. New tests: test_sage_quant_16bit_v_passthrough, test_sage_v_dtype (FP16, BF16, FP8 V), and test_sage_non_dense_inputs with an FP16 V. On gfx942 a 16-bit V needs BLOCK_N=64 (the FP8-sized table needs 80 KB LDS), so the tests pass get_sage_fwd_configs(block_n=64) for 16-bit V.

How the table was tuned: the scripts in utils/_triton/tuning/ support only GEMM families. So we used a sweep script that calls the public wrappers (sage_quant, then fav3_sage_func(config=...)) and times them with triton.testing.do_bench. Steps:

  • Compile-only pass for gfx1100 (VGPR, spill and LDS counts) over BLOCK_M {32, 64, 128, 256} x BLOCK_N {16, 32, 64, 128} x num_warps {2, 4, 8} x num_stages {1, 2} x waves_per_eu {1, 2} x PRE_LOAD_V.
  • Timed sweep on the W7900: 144 configs at (1, 24, 4608, D) for D = 64 and 128.
  • Refinement of the best 13 configs at 4608 and 32760 tokens, D = 64 and 128. We selected the config with the best worst-case ratio to the best config for each shape (98.7%).

The table has one fwd entry for all head dims, the same as the gfx942 and gfx950 tables.

Test plan

  • Unit tests on gfx1100 and gfx942, before and after:
    pytest op_tests/triton_tests/attention/test_fav3_sage.py op_tests/triton_tests/attention/test_fav3_sage_compile.py
  • Accuracy against an fp32 SDPA reference at image and video DiT shapes: FLUX 1024² (1, 24, 4608, D) and Wan 2.1 1.3B 480p 81 frames (1, 12, 32760, D), D = 64 and 128, bf16 inputs, bshd.
  • Performance with the aiter benchmark:
    python op_tests/op_benchmarks/triton/bench_fav3_sage.py -b 1 -hq 24 -sq 4608 -d 128 -metric throughput (and the other three shapes).
    Baselines on gfx1100: aiter Triton MHA flash_attn_func (bf16) and torch.nn.functional.scaled_dot_product_attention (bf16).
  • gfx942: before/after A/B of the benchmark, three alternating runs.
  • black 26.3.0 and ruff 0.15.7 on the changed Python file.

Software: torch 2.10.0+rocm7.0, Triton 3.6.0 for the first two commits; Triton 3.8.0 (the wheel aiter CI uses) for the sage_quant follow-up and the updated unit-test counts. GPUs: Radeon PRO W7900 (gfx1100), MI300X (gfx942).

Test results

Update: 16-bit V passed through (commit 3, Triton 3.8.0)

sage_quant and full fav3_sage call on the W7900, bf16 bshd inputs, ms (range of 3-4 alternating runs; "before" = commits 1-2):

shape (B, H, N, D) sage_quant before sage_quant after fav3_sage before fav3_sage after
(1, 24, 4608, 128) 1.04-1.06 0.74-0.79 4.37-4.57 4.12-4.28
(1, 24, 4608, 64) 0.59-0.62 0.49-0.50 2.39-2.61 2.34-2.47
(1, 12, 32760, 128) 4.20-4.22 3.02-3.09 96.9-101.9 95.4-102.2
(1, 12, 32760, 64) 1.51-1.55 1.21-1.26 51.2-53.9 51.7-53.3

Accuracy against fp32 SDPA is unchanged (same cosine, rel. L2 and max abs). A BF16 V passed through without the FP16 cast made sage_quant about 0.15 ms faster but the P*V kernel 1-8% slower and slightly less accurate, so the default is FP16. gfx942 FP8 path, before/after commit 3: 343-344, 210, 496-498 and 314-318 TFLOP/s on the four shapes, no change.

Unit tests with all three commits on Triton 3.8.0: gfx1100 529 passed, 596 skipped; gfx942 554 passed, 571 skipped.

Unit tests (commits 1-2, Triton 3.6.0)

GPU before after
gfx1100 (W7900) 17 passed, 0 failed in 27 min, then stopped by the time limit (each new shape compiles for minutes) 459 passed, 571 skipped in 94 s
gfx942 (MI300X) 459 passed, 571 skipped 459 passed, 571 skipped

The skipped tests are the MXFP4 tests (is_fp4_avail() is False on these archs).

Performance on gfx1100 (W7900), commits 1-2, Triton 3.6.0

TFLOP/s = 4·B·H·N²·D / time, the bench_fav3_sage.py formula. fav3_sage includes the Q/K/V quantization.

shape (B, H, N, D) fav3_sage before fav3_sage after aiter Triton MHA bf16 (*) torch SDPA bf16
FLUX (1, 24, 4608, 128) 5.3 54.3 56.0 23.9
(1, 24, 4608, 64) 5.2 48.5 59.2 22.9
Wan (1, 12, 32760, 128) 6.1 63.6 52.8 23.6
(1, 12, 32760, 64) 5.9 58.8 56.6 21.9

(*) aiter's Triton MHA has no gfx1100 table either (it fails with "Required config file doesn't exist"). We ran it with its gfx1101 table, passed through config=.

The kernel alone (without quantization) runs at 58-66 TFLOP/s. At 4608 tokens the quantization takes approximately 1.06 ms of the call (approximately 20%), so fav3_sage is at or below the bf16 MHA there. At 32760 tokens the quantization cost is small, and fav3_sage is 4-20% faster than the bf16 MHA.

Contribution of each change (4608 tokens, TFLOP/s with quantization):

D=128 D=64
before (FP8 V, gfx942 table) 5.3 5.2
FP8 V, tuned tile only 8.4 7.5
FP16 V, gfx942 table only 16.6 25.3
FP16 V + tuned tile (this PR) 54.3 48.5

First-call compile time at (1, 24, 4608, 128): before 518 s, after approximately 1 s.

Accuracy (against fp32 SDPA)

GPU shapes cosine rel. L2 max abs
gfx1100 before (FP8 V) FLUX D128 0.99921 - 0.0094
gfx1100 after (FP16 V) all 4 shapes 0.99991-0.99992 0.0126-0.0132 0.0011-0.0037
gfx942 (FP8 V, no change) all 4 shapes 0.99920-0.99925 0.0386-0.0400 0.0026-0.0107

FP16 V also makes the result on gfx1100 more accurate.

gfx942 (MI300X): no change

bench_fav3_sage.py, TFLOP/s, three alternating runs each:

shape before after
(1, 24, 4608, 128) 396.5-398.6 396.2-397.0
(1, 24, 4608, 64) 256.3-256.4 255.6-256.7
(1, 12, 32760, 128) 566.0-568.9 567.0-568.9
(1, 12, 32760, 64) 371.3-372.2 371.4-373.1

Lint

black --check and ruff check pass.

Notes and limits

  • Only gfx1100 was measured. The table loader uses the exact arch name, so gfx1101, gfx1102, gfx1150 and gfx1151 still use the gfx942 table. They get the FP16 V path (no FP8 there either), but they were not measured. The config rules do not allow a gfx1100 → gfx1101 seed, so this PR does not add one.
  • Follow-up: on gfx1100 the quantization (sage_quant) is the next bottleneck at short sequences. At (1, 24, 4608, 128) it took 1.06 ms before commit 3 (K smoothing 0.19 ms, V amax 0.25 ms, quant kernel 0.62 ms) and 0.74-0.79 ms after it. Its launch parameters (num_warps=8, num_stages=3) are fixed in Python. Tuning them per arch needs a config table, so it is not in this PR.
  • Follow-up: aiter's Triton MHA (attention/mha.py) has no gfx1100 table.

@TwelveNights
TwelveNights requested a review from a team October 21, 2026 11:31
@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 (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu 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: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
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 6770 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

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.

🔵 Needs a closer look

The precision change and hardware-specific tuning need human review because the reported GPU accuracy and performance results were not independently verified.

No open issues 🎉

What changed in this PR

Improves fav3_sage support on gfx1100 without changing the attention kernel.

Changes:

  • Uses FP16 V on architectures without FP8 support.
  • Adds gfx1100 launch settings with 64×64 tiles and four warps.
File Description
aiter/​ops/​triton/​configs/​gfx1100/​triton/​attention/​fav3_sage/​DEFAULT.json Adds tuned gfx1100 launch settings.
aiter/​ops/​triton/​attention/​fav3_sage.py Selects FP16 V when FP8 is unavailable.

Review effort: Balanced

Comment thread aiter/ops/triton/attention/fav3_sage.py Resolved
…cores

fav3_sage quantizes V to FP8 for the P*V product. RDNA3 (gfx11) has no
FP8 WMMA, so Triton converts the FP8 V tile and the FP8 P tile to FP16 in
software in the inner loop. On gfx1100 this limits the kernel to about
8 TFLOP/s for every tile size.

When arch_info.is_fp8_avail() is False, sage_quant now writes V as FP16
with the same per-channel scale. The kernel takes its P*V type from V,
so it runs FP16 WMMA. The archs that have FP8 (gfx942, gfx950, gfx12,
gfx1250) keep the FP8 path.
gfx1100 has no fav3_sage table, so it used the gfx942 table:
BLOCK_M=256, BLOCK_N=128, num_warps=8. With wave32 and 256 VGPRs per
lane, this tile spills more than 1000 VGPRs at head dim 128 (183 at
head dim 64). With FP8 V it ran at 5-6 TFLOP/s, and the first call
compiled for 9 minutes (4608 tokens) to 40 minutes (32760 tokens).

The new table uses BLOCK_M=64, BLOCK_N=64, num_warps=4, num_stages=1,
waves_per_eu=1. This tile does not spill. It was the best single tile in
a sweep over BLOCK_M, BLOCK_N, num_warps, num_stages, waves_per_eu and
PRE_LOAD_V on a Radeon PRO W7900, for head dim 64 and 128 at 4608 and
32760 tokens. fwd_a3_tuned has the same values, so a3_tuned does not
change the launch on gfx1100.
With an FP16 V, sage_quant still computed the per-channel amax, divided
V by it in the quant kernel, and the attention epilogue multiplied the
scale back. For a 16-bit type this costs an amax, a full read/write pass
over V and an extra rounding, with no precision benefit.

sage_quant now quantizes V only when v_dtype is FP8. For FP16/BF16 it
returns V as is (cast to v_dtype if needed) with a v_scale of ones and
launches no V programs; sage_quant_kernel guards the V branch with a
QUANTIZE_V constexpr (it replaces the unused FP8_MAX). The FP8_TYPE /
FP8_MAX / v_fp8 names become v_dtype / v_dtype_max / v_out.

fav3_sage_wrapper_func takes a v_dtype argument (default: FP8 when the
arch has FP8, else FP16), so the 16-bit V path is tested on every arch.
New tests: sage_quant pass-through, accuracy for each V type, and
non-dense inputs with an FP16 V.

gfx1100 (W7900), Triton 3.8: sage_quant 1.04-1.06 -> 0.74-0.79 ms at
(1, 24, 4608, 128) and 4.2 -> 3.0-3.1 ms at (1, 12, 32760, 128); output
unchanged (same cosine, rel. L2 and max abs vs fp32 SDPA). gfx942: FP8
path unchanged.
@TwelveNights
TwelveNights force-pushed the triton-fav3-sage-rdna3 branch from f38dfb5 to b18334a Compare October 22, 2026 15:56

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

Hi @TwelveNights. The PR LGTM, so I'm approving it!

I'd like to have a thumbs up from @juuso-oskari (or someone else from his team) before merging, since they are the owners of Sage Attention.

@amd-xavierwang

amd-xavierwang commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Hi, this PR looks good! just wondering if you know any models/frameworks that would use this kernel on gfx1100. I am also interested in doing similar works, but do not know any popular models/concrete use cases.

@TwelveNights

Copy link
Copy Markdown
Contributor Author

Thanks. The main users are diffusion (DiT) models, where attention over long image/video token sequences dominates: video models like Wan 2.1 (32760 tokens at 480p, 81 frames) and image models like FLUX (4608 tokens at 1024²), which are the shapes in the tables above.

One concrete path: SGLang's diffusion runtime has an AITER_SAGE attention backend that calls fav3_sage_wrapper_func. On a W7900 with this PR, Wan 2.1 1.3B (832x480, 33 frames, 20 steps) took about 75 s end to end with that backend, against about 119 s with torch_sdpa. Without this PR the first call on gfx1100 spent over 40 minutes compiling.

@brunomazzottiamd

Copy link
Copy Markdown
Contributor

I'm merging this PR given the approval from @amd-xavierwang (he said "this PR looks good!" in #6770 (comment)). Thanks everyone!

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