Repository navigation
Conversation
SageAttention (INT8 QK^T, FP8 PV) for gfx1201 through the kernels-community/aiter-sage-attention Hub kernel. Calls the kernel cannot take (head dim other than 128, non-bf16, masks, causal, unequal Q/K/V shapes) fall back to native SDPA, since components such as the VAE follow the active backend. Supports Ulysses context parallelism. Signed-off-by: Sylvan Liu <Sylvan.Liu@amd.com>
| constraints=[_check_device_cuda, _check_shape], | ||
| supports_context_parallel=True, | ||
| ) | ||
| def _aiter_sage_attention_hub( |
There was a problem hiding this comment.
Yes. With Ulysses degree 2 on two gfx1201 GPUs, the output of dispatch_attention_fn is bit-identical to the single-GPU run, both for self-attention (kernel) and for cross-attention with shorter K/V (fallback). Ring attention raises NotImplementedError. TestContextParallelAttentionBackward checks gradients, so it doesn't apply to this inference-only backend.
|
|
||
|
|
||
| @is_attention | ||
| class TestAiterSageHubFallback: |
There was a problem hiding this comment.
Looks good but it needs to be decorated with something like is_aiter_sage_hub_supported?
There was a problem hiding this comment.
These tests replace the Hub kernel with a stub, so they run on CPU without a gfx1201 GPU or kernels, and only check which calls go to the kernel and which fall back. Would you like a GPU test with the real kernel as well, skipped unless a gfx1201 GPU and kernels are available?
There was a problem hiding this comment.
I think that would be nice? We could add that to
WDYT?
There was a problem hiding this comment.
Done in a09f58b: aiter_sage_hub is now in _ALL_BACKEND_PARAMS, skipped unless a gfx1201 GPU and kernels are available. The Flux and QwenImage tiny models use head dims below 128, so they only exercise the native fallback. I also added TestAiterSageHubKernel, which runs the real kernel on head dim 128 and compares it against SDPA (cosine similarity 0.9993).
On a gfx1201 GPU (torch 2.13, kernels 0.16.1):
test_attention_dispatch.py -k AiterSage: 8 passed- Flux and QwenImage
-k aiter_sage_hub: 8 passed, includingtest_compile
sayakpaul
left a comment
There was a problem hiding this comment.
Great stuff! Can we see some visual examples as well?
Thanks! Here is MiniMax-H3 text-to-video+audio from the benchmark in the description (960x544, 124 frames, 9 steps, seed 42), native SDPA on the left and aiter_sage_hub on the right. The audio is from the aiter_sage_hub run. Both original videos, each with its own audio, are attached too. t213_native.mp4t213_aiter_sage_hub.mp4 |
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Add aiter_sage_hub to the attention backend tester parameters, skipped unless a gfx1201 GPU and `kernels` are available. The tiny test models use head dims below 128, so they only exercise the native fallback; TestAiterSageHubKernel checks the real kernel on head dim 128 against SDPA. Signed-off-by: Sylvan Liu <Sylvan.Liu@amd.com>
What does this PR do?
Adds an
aiter_sage_hubattention backend for AMD RDNA4 (gfx1201) GPUs, as discussed in #15014. It runs SageAttention (INT8 QK^T, FP8 PV) from thekernels-community/aiter-sage-attentionHub kernel (huggingface/kernels-community#1229), which vendors the gfx1201 kernels from ROCm/aiter#6390.Fixes #15014
NotImplementedError, since it needs the LSE and the kernel does not return it.Results
MiniMax-H3 text-to-video+audio on one Radeon AI PRO R9700: 960x544, 124 frames, 9 steps (8 transformer calls), seed 42, torch 2.13, Hub kernel
v1, transformer with block-level group offloading.nativeaiter_sage_hubVideo PSNR to native is 23.3 dB (18.9 to 25.9 dB per frame) and audio SNR is 8.5 dB. For scale, the native backend alone differs by 23.7 dB video PSNR and 12.9 dB audio SNR between torch 2.11 and torch 2.13.
With Ulysses degree 2 on two GPUs,
dispatch_attention_fngives bit-identical output to the single-GPU run, both for self-attention (kernel) and for cross-attention with shorter K/V (fallback).Benchmark setup
Transformer calls were timed with forward pre/post hooks and
torch.cuda.synchronize().Tests
The tests use a stub in place of the Hub kernel, since CI has no gfx1201. The results above ran on gfx1201 with the published kernel.
Self-review notes
Final round of the
self-reviewskill:testing.mddiscourages call-level test doubles, but CI has no gfx1201. The fallback tests compare against the real native backend._ALL_BACKEND_PARAMS, same asaiter_fa2_hub: CI has no gfx1201, and the test models don't use head dim 128, so only the fallback would run.Before submitting
self-reviewskill on the diff?documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@sayakpaul @Abdennacer-Badaoui