A guide to enabling advanced PyTorch extensions (FlashAttention, SageAttention, bitsandbytes) for AMD GPUs (RDNA 3/gfx1100+) on Windows using ROCm 7.
🚧 Status: Experimental | Requires manual compilation and specific versions.
- Triton Support:
triton-windows==3.6.0.post25with ROCm support. - Accelerated Attention:
flash-attention(Dao-AILab)sage-attention==1.0.6(patched for ROCm)
- 4-bit Quantization:
bitsandbytescompiled for ROCm 7 (NF4, QLoRA). - Tested Frameworks: Works with ComfyUI and standard PyTorch training scripts.
- GPU: AMD RDNA 3 Architecture (gfx1100+, e.g., RX 7900 XT/XTX).
- OS: Windows 10/11
- Python: 3.12 (recommended)
- ROCm: 7.12 nightly builds.
choco install visualstudio2022buildtools -y --params "--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.VC.CMake.Project --add Microsoft.VisualStudio.Component.VC.ATL"
choco install git.install -y --params "'/GitAndUnixToolsOnPath'"
choco install cmake --version=3.31.0 -y
choco install ninja -y
choco install python --version=3.12.0 -y-
Install PyTorch with ROCm 7:
pip install --index-url https://rocm.nightlies.amd.com/v2/gfx110X-all/ --pre torch torchaudio torchvision rocm[devel] --no-cache
-
Set up build environment: Save the following as
set_env.ps1and run it before any compilation.# set_env.ps1 $ROCM_ROOT = (rocm-sdk path --root).Trim() $env:PATH = "$ROCM_ROOT\lib\llvm\bin;$ROCM_ROOT\bin;$env:PATH" $env:CC = "clang-cl" $env:CXX = "clang-cl" $env:TRITON_CACHE_AUTOTUNING=1 $env:TORCH_ROCM_AOTRITON_ENABLE_EXPERIMENTAL=1
-
Install Triton:
pip install triton-windows==3.6.0.post25
-
Install FlashAttention:
git clone https://github.com/Dao-AILab/flash-attention cd flash-attention .\..\set_env.ps1 # Source the env script python setup.py bdist_wheel pip install dist\flash_attn-*.whl
-
Install SageAttention (patched for ROCm):
pip install https://github.com/guinmoon/SageAttention-Rocm7/releases/download/v1.0.6_rocm7/sageattention-1.0.6-py3-none-any.whl
Form manual compilation:
git clone https://github.com/thu-ml/SageAttention -b sageattention-1 # Скачиваем необходимые патчи curl -o .\sageattention\attn_qk_int8_per_block.py https://raw.githubusercontent.com/patientx/ComfyUI-Zluda/refs/heads/master/comfy/customzluda/sa/attn_qk_int8_per_block.py curl -o .\sageattention\attn_qk_int8_per_block_causal.py https://raw.githubusercontent.com/patientx/ComfyUI-Zluda/refs/heads/master/comfy/customzluda/sa/attn_qk_int8_per_block_causal.py curl -o .\sageattention\quant_per_block.py https://raw.githubusercontent.com/patientx/ComfyUI-Zluda/refs/heads/master/comfy/customzluda/sa/quant_per_block.py # Сборка и установка python setup.py bdist_wheel pip install .\dist\sageattention-1.0.6-py3-none-any.whl -
Install bitsandbytes (Pre-built wheel):
pip install https://github.com/guinmoon/bitsandbytes_win_rocm/releases/download/v0.49.2_romc7.12/bitsandbytes-0.49.2.dev0-cp312-cp312-win_amd64.whl
For manual compilation:
cmake -G Ninja -DCOMPUTE_BACKEND=hip -S . -B bitsandbytes -DCMAKE_BUILD_TYPE="Release" -DBNB_ROCM_ARCH="gfx1100;gfx1102;gfx1103" -DHIP_PLATFORM="amd" -DCMAKE_CXX_COMPILER="$env:ROCM_PATH/lib/llvm/bin/clang++.exe" -DCMAKE_PREFIX_PATH="$env:ROCM_PATH" -DCMAKE_HIP_COMPILER="$env:ROCM_PATH/lib/llvm/bin/clang++.exe" -DCMAKE_SHARED_LINKER_FLAGS="-L$env:ROCM_PATH/lib -lamdhip64 -lrocblas" cmake --build bitsandbytes -j python setup.py bdist_wheel pip install .\dist\bitsandbytes-0.49.2.dev0-cp312-cp312-win_amd64.whl
-
Install ComfyUI:
git clone https://github.com/Comfy-Org/ComfyUI cd ComfyUI pip install -r requirements.txt
-
Run with different attention backends:
# Activate environment vars .\path\to\set_env.ps1 # Run ComfyUI python main.py --normalvram --use-sage-attention # or --use-flash-attention
Tested on an AMD RX 7900 XTX.
| Model / Task | SDPA (s) | FlashAttention (s) | SageAttention (s) |
|---|---|---|---|
| Flux1.Dev (1080p) | 88.3 | 101.2 | 74.4 |
| LTX-2 | 277.5 | 286.9 | 231.5 |
SageAttention provides a significant speedup in stable diffusion workflows.
Install extra dependencies:
pip install jq transformers==4.57.5 peft==0.18.1 accelerate safetensors sentencepiece huggingface-hub trl==0.26.2 einops tqdm==4.67.1 traitlets==5.14.3Use Qlora.py for training and inference_q.py for inference.
Create secret.py with hf_token = 'hf_**********'
- This is an unofficial, community-supported setup.
- The architecture (
gfx1100) must be specified correctly in build commands. - Performance can vary significantly between different models and tasks.
- Always source the
set_env.ps1script before compiling any component.
- Original Detailed Guide (Habr): Russian Article
- Patched bitsandbytes fork: guinmoon/bitsandbytes_win_rocm
- Triton Windows Wheels: Comfy-Org/wheels