{"slug": "understanding-attention-algorithms-and-their-backends-for-image-and-video", "title": "Understanding Attention Algorithms and Their Backends for Image and Video Generation", "summary": "AMD's ROCm blog explains that choosing the right attention algorithm in ComfyUI can significantly impact performance, memory usage, and stability on AMD GPUs, with PyTorch SDPA recommended as the safest default due to AOTriton integration and Flash Attention (CK Tile) typically delivering the highest throughput in benchmarks. The blog warns that xformers can silently override other choices and that split/quad attention trades performance for memory safety.", "body_md": "# Understanding Attention Algorithms and Their Backends for Image and Video Generation[#](#understanding-attention-algorithms-and-their-backends-for-image-and-video-generation)\n\nComfyUI has become a widely adopted tool for running modern generative AI workloads, from text-to-image and video generation to more advanced pipelines like WAN2.2. Its node-based workflow makes it accessible without requiring deep coding knowledge, but under the hood it still relies heavily on one of the most important building blocks in modern AI models: **attention**.\n\nFor users running on AMD GPUs with ROCm™, choosing the right attention implementation can have a **significant impact on performance, memory usage, and stability**. However, this choice is far from straightforward. ComfyUI exposes multiple attention flags, each mapping to different algorithms and backend implementations (AOTriton, CK Tile, rocBLAS/hipBLASLt, Triton), often with non-obvious priority rules and interactions.\n\nThe challenge is not just what attention algorithm to use, but understanding:\n\nhow ComfyUI selects attention under the hood\n\nhow that maps to ROCm backends\n\nand what actually performs optimally in practice\n\nThis blog breaks down these layers and offers a practical guide to help you make informed decisions when running ComfyUI for image and video generation on Linux-based systems with AMD RDNA™ architecture GPUs.\n\nFor background and setup across AMD platforms, refer to the earlier ROCm blogs [Running ComfyUI on AMD Instinct GPU](https://rocm.blogs.amd.com/software-tools-optimization/comfyui-on-amd/README.html), [Getting Started with ComfyUI on AMD Radeon™ RX 9000 Series GPUs](https://rocm.blogs.amd.com/artificial-intelligence/comfyui-radeon-9000/README.html), and [Running ComfyUI in Windows with ROCm on WSL](https://rocm.blogs.amd.com/software-tools-optimization/rocm-on-wsl/README.html).\n\n## Quick recommendations[#](#quick-recommendations)\n\nIf you were to take one thing from this blog, let it be the following section which summarizes **practical recommendations** based on common usage scenarios:\n\n|\n|\n|\n|---|---|---|\n|\n|\nSafe, well-integrated, automatically selects optimized AOTriton backend. |\n|\n|\nIn our benchmarks, typically delivered the highest throughput on the tested configurations. |\n|\nKeep disabled or explicitly override. |\nxformers has higher priority and may silently override other choices. |\n|\n|\nReduces memory footprint by avoiding full attention computation. |\n|\nPyTorch math (implicit fallback) |\nMost stable but slowest path. |\n|\n|\nFlags that explicitly disable xformers. For example, xformers will override the |\n\nQuick recommendations **takeaways**\n\n**PyTorch SDPA** is the safest default on AMD due to AOTriton integration.**Flash Attention (CK Tile)** typically gives optimal raw performance.**xformers can silently override your choice**, so be explicit when needed.** Split/quad attention trades performance for memory safety.**\n\nThese choices can significantly impact generation throughput, memory usage, and overall stability. In some cases, selecting the right attention backend can significantly impact performance on AMD GPUs.\n\n*Note:* PyTorch SDPA (CK) and the modified PyTorch/AOTriton builds used in this blog are experimental and not officially supported on RDNA at the time of writing.\n\n## Attention Selection Overview[#](#attention-selection-overview)\n\nAt a high level, selecting an attention implementation in ComfyUI is not determined solely by the CLI flag. The final implementation depends on ComfyUI priority rules, installed packages, AMD/ROCm availability checks, and backend dispatch.\n\n|\n|\n|\n|\n|\n|\n|---|---|---|---|---|---|\nSage Attention |\n|\nNo |\nTriton |\nExperimental / research |\nRequires sageattention package. Not officially supported on AMD. On gfx12xx, additional patching may be required due to Triton compilation issues. In the measured workloads, Sage Attention was generally slower than PyTorch SDPA on Navi31 and Strix-Halo, and had stability issues on Navi48. |\nxformers |\nAuto-detected if installed |\nNo |\nCK Tile |\nImplicit path |\nHigh-priority path. If installed, xformers may be selected automatically and can silently override other choices. It should be handled carefully because it was observed to be unstable in some tested scenarios. |\nFlash Attention |\n|\nNo |\nCK Tile by default; Aiter/Triton optional with |\nMaximum throughput |\nRequires DAO-AILab/flash-attention package. In the benchmarks, CK-backed Flash Attention delivered the highest throughput in most cases. Make sure xformers is disabled or bypassed when you want this path to be selected. |\nPyTorch SDPA |\n|\nYes |\nAOTriton by default; CK experimentally possible with |\nStable default |\nSafest and most integrated option on AMD. In ComfyUI, |\nSplit Attention |\n|\nYes |\nPure PyTorch implementation; batched matrix operations dispatch through rocBLAS/hipBLASLt |\nMemory-constrained workloads |\nComputes attention in slices to reduce memory pressure. This trades performance for memory safety and also suppresses AMD auto-detection of PyTorch/AOTriton attention. |\nSub-quadratic Attention |\n|\nYes |\nPure PyTorch implementation; batched matrix operations dispatch through rocBLAS/hipBLASLt |\nFallback / extreme memory constraints |\nLowest-priority path. Useful when other optimized attention implementations are unavailable or unsuitable, but generally not the performance-oriented choice. |\n\n## Choosing the Right Attention[#](#choosing-the-right-attention)\n\nBefore diving into individual flags, the image below highlights how ComfyUI resolves attention internally:\n\n**Attention flag** selects a high-level algorithm (e.g. PyTorch SDPA, Flash Attention).The algorithm maps to a\n\n**backend implementation**(AOTriton, CK Tile, Triton, rocBLAS/hipBLASLt).The backend determines\n\n**performance characteristics** such as throughput and memory usage.\n\nUnderstanding this mapping is important because the CLI flag ultimately determines which attention algorithm and which ROCm backend is used, directly impacting performance.\n\nComfyUI provides multiple attention flags:\n\n`--use-split-cross-attention`\n\n`--use-quad-cross-attention`\n\n`--use-pytorch-cross-attention`\n\n`--use-sage-attention`\n\n(sageattention package must be installed)`--use-flash-attention`\n\n(flash-attention package must be installed)`--disable-xformers`\n\nThese options are **mutually exclusive**, and their behavior depends on installed libraries and internal priority rules. For example, `--use-sage-attention`\n\nrequires sageattention package to be installed, while `--use-flash-attention`\n\nneeds corresponding DAO-AILab/flash-attention. Also, Linux supports all of the listed backends, while some of them might have limited support on Windows.\n\nThese flags are passed as CLI arguments when launching ComfyUI:\n\npython ComfyUI/main.py `--use-\\*-attention`\n\nApart from that, there are settings for controlling attention precision and up casting. These won’t be covered in this blog:\n\n`--force-upcast-attention`\n\n`--dont-upcast-attention`\n\n### Attention priority[#](#attention-priority)\n\nComfyUI chooses the global attention implementation based on the priority order in [ComfyUI/comfy/ldm/modules/attention.py at master · Comfy-Org/ComfyUI](https://github.com/Comfy-Org/ComfyUI/blob/master/comfy/ldm/modules/attention.py#L776-L796):\n\n|\n|\n|\n|---|---|---|\n1 |\nSage attention |\nsageattention installed + |\n2 |\nxformers |\nROCm xformers installed (auto, no flag needed) |\n3 |\nFlash attention |\nDAO-AILab/flash-attention installed + |\n4 |\nPyTorch SDPA |\n|\n5 |\nSplit attention |\n|\n6 |\nSub-quadratic attention |\nDefault |\n\n**VAE Decoder Attention**[#](#vae-decoder-attention)\n\nThe VAE decoder follows a separate attention selection path: [ComfyUI/comfy/ldm/modules/diffusionmodules/model.py at master · Comfy-Org/ComfyUI](https://github.com/Comfy-Org/ComfyUI/blob/master/comfy/ldm/modules/diffusionmodules/model.py#L329). On AMD GPUs, PyTorch SDPA is intentionally disabled for VAE due to stability issues at high resolutions. As a result, VAE attention typically falls back to xformers (if available) or split attention.\n\n|\n|\n|\n|---|---|---|\n1 |\nxformers |\nROCm xformers installed and if not disabled via |\n2 |\nPyTorch SDPA |\n|\n3 |\nSplit attention |\nFallback when PyTorch attention or xformers is disabled. Uses Batched matrix multiplication implementation (falls back to rocBLAS/hipBLASLt) |\n\n### ComfyUI AMD/ROCm specifics[#](#comfyui-amd-rocm-specifics)\n\nThe most important AMD/ROCm specifics are:\n\nComfyUI will automatically enable\n\n**PyTorch SDPA** attention with compatible PyTorch/ROCm versions:[ComfyUI/comfy/model_management.py at master · Comfy-Org/ComfyUI](https://github.com/Comfy-Org/ComfyUI/blob/master/comfy/model_management.py#L480).FP8 operations are enabled for newer AMD architectures:\n\n[ComfyUI/comfy/model_management.py at master · Comfy-Org/ComfyUI](https://github.com/Comfy-Org/ComfyUI/blob/master/comfy/model_management.py#L515)TORCH_ROCM_AOTRITON_ENABLE_EXPERIMENTAL=1 is\n\n**set** by default within ComfyUI:[ComfyUI/main.py at master · Comfy-Org/ComfyUI](https://github.com/Comfy-Org/ComfyUI/blob/master/main.py#L68), which enables experimental memory efficient attention (backed by AOTriton on AMD). In practice we need to pass –use-pytorch-cross-attention to get this behavior.and`--use-split-cross-attention`\n\nsuppress AMD auto-detection of PyTorch/AOTriton attention.`--use-quad-cross-attention`\n\nWithout xformers and without a supported architecture, the default path is sub-quadratic attention.\n\n### Attention backends overview[#](#attention-backends-overview)\n\nThe following table shows how different attention implementations map to backend implementations on AMD/ROCm:\n\n|\n|\n|---|---|\nSage attention |\nTriton |\nxformers |\nCK Tile |\nFlash attention |\nCK Tile - default |\n(Aiter) Triton - force with |\n|\nPyTorch SDPA |\nFlash attention (AOTriton, CK) (AOTriton by default, or CK if |\nMemory efficient attention (AOTriton, CK) (AOTriton by default, or CK if |\n|\nMath (C++) |\n|\nSplit Cross attention |\nPure PyTorch implementation (e.g. einsum - falls back to rocBLAS/hipBLASLt) |\nSub-quadratic attention |\nPure PyTorch implementation (e.g. batched matrix multiplication - falls back to rocBLAS/hipBLASLt) |\n\nPyTorch SDPA Flash attention and Memory efficient attention share the same backends for AMD/ROCm, essentially making them the same.\n\n## More on Attention[#](#more-on-attention)\n\nWith Attention priority and Attention backends we have covered all ComfyUI attention algorithms from a high-level perspective. Therefore, the following paragraphs deep dive into the attention algorithms behind different CLI flags by following the Attention priority discussed previously. Also, ComfyUI AMD/ROCm specifics will be covered.\n\n`--use-sage-attention`\n\n[#](#use-sage-attention)\n\n`--use-sage-attention`\n\n**Note:** sageattention works out-of-the-box for gfx1100 and gfx1151. For gfx12xx the patch needs to be applied as there are triton compilation errors. These are known bugs:\n\nThis PR solves the gfx12xx issue: [thu-ml/SageAttention#365](https://github.com/thu-ml/SageAttention/pull/365)\n\nSage attention is a quantization technique that boosts the transformer attention performance by using INT8 quantization and matrix smoothing.\n\nCurrently, sageattention is not an officially supported package from AMD, it is limited to CUDA stack and should be used for experimental purposes. There are community and partial AMD efforts to enable the Triton route through Sage attention.\n\nAs sage-attention is not available out-of-the-box, this package needs to be installed with the following command:\n\n```\npip install \"sageattention\\<2\"\n```\n\nPassing `low_precision_attention=False`\n\n, will bypass sage-attention and fallback to attention_pytorch and if sage-attention raises **any exception**, it logs an error and falls back to attention_pytorch.\n\n`--disable-xformers`\n\n[#](#disable-xformers)\n\n`--disable-xformers`\n\n**Note:** For mGPU T2V WAN2.2 workload, xformers produces Memory access faults on Navi48 VAE Decoder phase.\n\nIf xformers library is detected, it will be used automatically if not disabled by this flag. Therefore, no special activation flag is needed to use xformers as based on the priority chain, ComfyUI selects xformers second (after sage attention).\n\nUsing any of the following flags will bypass xformers:\n\n`--use-pytorch-cross-attention`\n\n`--use-sage-attention`\n\n(sageattention package must be installed)\n\nAttention_xformers calls memory-efficient attention and lets the xformers library determine which ROCm library or backend is used. ([ComfyUI/comfy/ldm/modules/attention.py at master · Comfy-Org/ComfyUI](https://github.com/Comfy-Org/ComfyUI/blob/master/comfy/ldm/modules/attention.py#L505)). Also, –use-pytorch-cross-attention explicitly sets XFORMERS_IS_AVAILABLE = False ([ComfyUI/comfy/model_management.py at master · Comfy-Org/ComfyUI](https://github.com/Comfy-Org/ComfyUI/blob/master/comfy/model_management.py#L458-L460)) and it is the flag that actively disables xformers.\n\nxformers is not available out-of-the-box. Therefore, to install it, follow the install from source instructions from the xformers repository: [ROCm/xformers: Hackable and optimized Transformers building blocks, supporting a composable construction](https://github.com/ROCm/xformers).\n\n`--use-flash-attention`\n\n[#](#use-flash-attention)\n\n`--use-flash-attention`\n\nThis flag will utilize Flash attention 2 algorithm described in the following paper: [FlashAttention-2: Faster Attention with Better Parllelism and Work Partitioning](https://tridao.me/publications/flash2/flash2.pdf). Usually, this implementation produces strong results on AMD GPUs.\n\nFor `--use-flash-attention`\n\n, DAO-AILab/flash-attention package needs to be installed and additionally for DAO-AILab (Aiter) Triton, Aiter needs to be installed: [ROCm/aiter: AI Tensor Engine for ROCm](https://github.com/ROCm/aiter) (Or follow the aiter checkout steps when building DAO-AILab/flash-attention):\n\n```\npython -m pip install --no-build-isolation git+https://github.com/ROCm/aiter.git\n```\n\nTo build DAO-AILab/flash-attention, follow the Readme.md from the official DAO-AILab/flash-attention repository: [Dao-AILab/flash-attention](https://github.com/Dao-AILab/flash-attention#amd-rocm-support).\n\nBuilding DAO-AILab/flash-attention **without** `FLASH_ATTENTION_TRITON_AMD_ENABLE`\n\nprovides the option to toggle between CK Tile and Triton FA with `FLASH_ATTENTION_TRITON_AMD_ENABLE=TRUE`\n\n.\n\nFor peak throughput, enable `FLASH_ATTENTION_TRITON_AMD_AUTOTUNE=\"TRUE\"`\n\nto search for optimal settings, which incurs a one-time warmup cost. Alternatively, if not autotuning, `FLASH_ATTENTION_FWD_TRITON_AMD_CONFIG_JSON`\n\nmay be used to set a single triton config overriding the hardcoded defaults for attn_fwd.\n\n`--use-pytorch-cross-attention`\n\n[#](#use-pytorch-cross-attention)\n\n`--use-pytorch-cross-attention`\n\nLets PyTorch internally choose one of the three available implementations:\n\nFlash Attention (AOTriton, CK)\n\nMemory efficient (AOTriton, CK)\n\nMath (C++ implementation)\n\nBoth Flash Attention and Memory Efficient Attention dispatch to the same ROCm kernel library, which is AOTriton by default or CK if `TORCH_ROCM_FA_PREFER_CK=1`\n\nor `torch.backends.cuda.preferred_rocm_fa_library(\"ck\")`\n\nis set. Math, or pure C++ implementation, is a PyTorch SDPA that does not use kernel fusion, tiling, or memory optimizations. Currently, **CK** PyTorch cross attention is **not supported for RDNA** architectures. Flash Attention is not to be confused with the DAO-AILab/flash-attention package. Even though they share a similar name, Flash Attention in this context refers to PyTorch SDPA Flash Attention 2 implementation.\n\nIn this analysis, we used an internal experimental build of PyTorch 2.10 with CK-enabled SDPA on Navi31, Navi48, and Strix-Halo. This configuration is not officially supported on RDNA architectures and is used here solely for experimental comparison.\n\nAlso, for this blog, we evaluated a newer Triton version within AOTriton (0.11.1b) and compared it against the official AOTriton configuration. Specifically, we used the Triton version from AOTriton 0.12 (ROCm/triton at aotriton/0.12), as our experiments showed that upgrading the Triton dependency can provide measurable performance benefits.\n\n`--use-split-cross-attention`\n\n[#](#use-split-cross-attention)\n\n`--use-split-cross-attention`\n\nThis is ComfyUI’s pure PyTorch attention implementation that helps avoid out‑of‑memory (OOM) errors by computing attention in slices rather than all at once: [ComfyUI/comfy/ldm/modules/attention.py at master · Comfy-Org/ComfyUI](https://github.com/Comfy-Org/ComfyUI/blob/master/comfy/ldm/modules/attention.py#L328). It is one of the last resorts in the priority chain and should be used when there is a need for reduced memory pressure. Split cross-attention is available out-of-the-box without the need to install any additional packages.\n\nOn AMD/ROCm, PyTorch dispatches the underlying batched matrix multiplications (e.g., einsum) down through its own ROCm backend to **rocBLAS/hipBLASLt**. Also, for AMD, passing this flag suppresses the auto-enabling of PyTorch attention (`ENABLE_PYTORCH_ATTENTION`\n\n) on supported arches: [ComfyUI/comfy/model_management.py at master · Comfy-Org/ComfyUI](https://github.com/Comfy-Org/ComfyUI/blob/master/comfy/model_management.py#L506).\n\n`--use-quad-cross-attention`\n\n[#](#use-quad-cross-attention)\n\n`--use-quad-cross-attention`\n\n`--use-quad-cross-attention`\n\nactivates sub-quadratic attention, which is an implementation of the algorithm from the paper [“Self-attention Does Not Need O(n²) Memory”](https://arxiv.org/abs/2112.05682v2). Sub-quadratic attention is the default fallback when none of sage/xformers/flash/pytorch/split attention are active or available and should be used when split cross-attention produces out-of-memory issues. Quad cross-attention is available out-of-the-box without need to install any additional packages.\n\nFor AMD, passing this flag suppresses the auto-enabling of PyTorch attention (`ENABLE_PYTORCH_ATTENTION`\n\n) on supported arches: [ComfyUI/comfy/model_management.py at master · Comfy-Org/ComfyUI](https://github.com/Comfy-Org/ComfyUI/blob/master/comfy/model_management.py#L506).\n\nAs with split-cross-attention, the quad-cross-attention will be dispatched to **rocBLAS/hipBLASLt** as it is using PyTorch batched matrix multiplication functions.\n\n## WAN2.2 14B T2V & I2V benchmark results[#](#wan2-2-14b-t2v-i2v-benchmark-results)\n\n**DISCLAIMER**: Performance results are based on AMD testing using the WAN2.2 workflows, hardware platforms, software versions, and configurations described in this article. Actual results will vary depending on model, workload, software stack, system configuration, backend selection, and optimization settings.\n\nKey findings from benchmarks:\n\nIn our measurements, Flash attention with CK delivered the highest throughput on the tested workloads.\n\nGains range from\n\n**~20% up to 40–50%** depending on workload and hardwarePyTorch SDPA (AOTriton) offers stable performance but lower peak throughput\n\nSage attention produces significantly worse results than PyTorch SDPA (AOTriton) on Navi31 and Strix-Halo, while it fails with Memory access faults on Navi48\n\nDifferences are more pronounced on larger models and unified-memory systems (e.g., Strix Halo)\n\nIn these tests, RDNA4 (Navi48) delivered roughly ~60% higher throughput than RDNA3 (Navi31) under the same workload and backend.\n\nThe experiments were run on two different workflows:\n\n[comfyui_txt2video_Wan2.2-Lightning-T2V-A14B-4steps-lora-HIGH-fp16](../../_downloads/56b58759780c70e1e6f3ae420cb7ae4a/comfyui_txt2video_Wan2.2-Lightning-T2V-A14B-4steps-lora-HIGH-fp16.json)[comfyui_image2video_wan2.2-i2v-scale-fp8-lightx-workflow](../../_downloads/558b4420c112f4a2816e050875ca8b86/comfyui_image2video_wan2.2-i2v-scale-fp8-lightx-workflow.json)This workflow needs to be modified for the ComfyUI to be able to change the FA algorithm. The default value is hardcoded to SDPA, change it to “comfy” to control the FA with\n\n`--use-flash-attention`\n\n, change it to “sageattn” to use it with`--use-sage-attention`\n\n.\n\n### comfyui_txt2video_Wan2.2-Lightning-T2V-A14B-4steps-lora-HIGH-fp16[#](#comfyui-txt2video-wan2-2-lightning-t2v-a14b-4steps-lora-high-fp16)\n\nThe figures below show the performance of different Flash Attention backends on Navi 31, Navi 48, and Strix Halo (128 GB), including throughput and percentage throughput differences relative to PyTorch AOTriton SDPA for the WAN 2.2 T2V workload:\n\nFor more detailed information, refer to the table below:\n\n|\n|\n|\n|\n|\n|\n|---|---|---|---|---|---|\n|\nPyTorch SDPA (AOTriton) |\n(1.75) 1.68 |\n(1.39) 1.38 |\n(0.72) 0.72 |\nN/A |\nPyTorch SDPA (bumped AOTriton) |\n(1.40) 1.29 |\n(1.07) 1.07 |\n(0.94) 0.94 |\n26.506 |\n|\nPyTorch SDPA (CK) |\n(1.36) 1.24 |\n(1.03) 1.01 |\n(0.97) 0.99 |\n31.5789 |\n|\nDAO-AILab (Aiter) Triton |\n(1.30) 1.27 |\n(1.04) 1.04 |\n(0.96) 0.96 |\n28.5714 |\n|\nDAO-AILab CK |\n(1.31) 1.20 |\n(0.97) 0.97 |\n(1.04) 1.04 |\n|\n|\nSage Attention (1.0.6) |\n(2.24) 2.15 |\n(1.97) 1.97 |\n(0.51) 0.51 |\n-34.1463 |\n|\n|\nPyTorch SDPA (AOTriton) |\n(4.23) 1.38 |\n(0.77) 0.74 |\n(1.31) 1.35 |\nN/A |\nPyTorch SDPA (bumped AOTriton) |\n(2.27) 0.97 |\n(0.67) 0.67 |\n(1.49) 1.49 |\n9.85915 |\n|\nPyTorch SDPA (CK) |\n(2.61) 1.20 |\n(0.61) 0.60 |\n(1.64) 1.65 |\n|\n|\nDAO-AILab (Aiter) Triton |\n(2.45) 0.98 |\n(0.70) 0.67 |\n(1.43) 1.48 |\n9.18728 |\n|\nDAO-AILab CK |\n(5.63) 1.32 |\n(0.60) 0.62 |\n(1.68) 1.61 |\n17.5676 |\n|\nSage Attention (1.0.6) |\n(5.37) 0.91 |\n(0.65) 0.65 |\n(1.55) 1.54 |\n3.30033 |\n|\n|\nPyTorch SDPA (AOTriton) |\n(4.98) 3.32 |\n(2.83) 2.8 |\n(0.35) 0.36 |\nN/A |\nPyTorch SDPA (bumped AOTriton) |\n(6.70) 4.80 |\n(3.08) 2.98 |\n(0.33) 0.34 |\n-5.71429 |\n|\nPyTorch SDPA (CK) |\n(6.07) 3.28 |\n(2.19) 2.18 |\n(0.46) 0.46 |\n30.0000 |\n|\nDAO-AILab (Aiter) Triton |\n(4.33) 3.76 |\n(1.99) 1.94 |\n(0.50) 0.52 |\n36.3636 |\n|\nDAO-AILab CK |\n(5.25) 3.00 |\n(1.8) 1.79 |\n(0.56) 0.56 |\n|\n|\nSage Attention (1.0.6) |\n(7.74) 5.15 |\n(3.82) 4.02 |\n(0.26) 0.25 |\n-36.0656 |\n\n### comfyui_image2video_wan2.2-i2v-scale-fp8-lightx-workflow[#](#comfyui-image2video-wan2-2-i2v-scale-fp8-lightx-workflow)\n\nThe figures below show the performance of different Flash Attention backends on Navi 31, Navi 48, and Strix Halo (128 GB), including throughput and percentage throughput differences relative to PyTorch AOTriton SDPA for the WAN 2.2 I2V workload:\n\nFor more detailed information, refer to the table below:\n\n|\n|\n|\n|\n|\n|\n|---|---|---|---|---|---|\n|\nPyTorch SDPA (AOTriton) |\n(2.14) 1.80 |\n(1.31) 1.31 |\n(0.76) 0.76 |\nN/A |\nPyTorch SDPA (bumped AOTriton) |\n(1.91) 1.57 |\n(1.10) 1.09 |\n(0.91) 0.91 |\n17.9641 |\n|\nPyTorch SDPA (CK) |\n(1.77) 1.44 |\n(0.96) 0.94 |\n(1.04) 1.07 |\n33.8798 |\n|\nDAO-AILab (Aiter) Triton |\n(1.80) 1.66 |\n(0.98) 0.97 |\n(1.02) 1.03 |\n30.1676 |\n|\nDAO-AILab CK |\n(1.56) 1.60 |\n(0.91) 0.92 |\n(1.10) 1.09 |\n|\n|\nSage Attention (1.0.6) |\n(2.63) 2.27 |\n(1.97) 1.97 |\n(0.55) 0.56 |\n-30.3030 |\n|\n|\nPyTorch SDPA (AOTriton) |\n(10.63) 1.95 |\n(1.28) 0.71 |\n(0.78) 1.41 |\nN/A |\nPyTorch SDPA (bumped AOTriton) |\n(3.81) 1.03 |\n(0.61) 0.60 |\n(1.65) 1.66 |\n16.2866 |\n|\nPyTorch SDPA (CK) |\n(3.44) 1.00 |\n(0.59) 0.59 |\n(1.69) 1.70 |\n18.6495 |\n|\nDAO-AILab (Aiter) Triton |\n(3.23) 1.32 |\n(0.66) 0.65 |\n(1.53) 1.55 |\n9.45946 |\n|\nDAO-AILab CK |\n(3.29) 1.22 |\n(0.58) 0.58 |\n(1.72) 1.73 |\n|\n|\nSage Attention (1.0.6) |\n(3.23) 1.04 |\n(0.61) 0.60 |\n(1.65) 1.66 |\n6.85358 |\n|\n|\nPyTorch SDPA (AOTriton) |\n(6.0) 3.49 |\n(3.16) 3.00 |\n(0.32) 0.33 |\nN/A |\nPyTorch SDPA (bumped AOTriton) |\n(5.71) 3.20 |\n(2.93) 2.88 |\n(0.34) 0.35 |\n5.88235 |\n|\nPyTorch SDPA (CK) |\n(5.11) 2.23 |\n(1.83) 1.83 |\n(0.55) 0.55 |\n|\n|\nDAO-AILab (Aiter) Triton |\n(5.09) 2.46 |\n(1.89) 1.89 |\n(0.53) 0.53 |\n46.5116 |\n|\nDAO-AILab CK |\n(4.85) 2.32 |\n(2.28) 1.81 |\n(0.44) 0.55 |\n|\n|\nSage Attention (1.0.6) |\n(6.62) 4.11 |\n(3.43) 3.61 |\n(0.29) 0.28 |\n-16.3934 |\n\n*Note:* Entries in the tables in parentheses “(XY)” are the numbers from cold start runs, while the numbers without parentheses “XY” are the numbers from the second run with the warm cache.\n\n*Note:* Because MIOpen does not ship a kernel database for RDNA, cold runs were run with the following environment variables:\n\n```\nexport COMFYUI_ENABLE_MIOPEN=1\nexport MIOPEN_FIND_MODE=1\nexport MIOPEN_FIND_ENFORCE=4\nexport MIOPEN_SEARCH_CUTOFF=ON\nexport TORCH_BLAS_PREFER_HIPBLASLT=1\n```\n\nwhile for the second run, some of the environment variables were unset to let MIOpen use the database entries:\n\n```\nunset MIOPEN_FIND_MODE\nunset MIOPEN_FIND_ENFORCE\nunset MIOPEN_SEARCH_CUTOFF\n```\n\n### Result interpretation[#](#result-interpretation)\n\nAt a high level, performance is driven by three factors: hardware generation, backend selection, and workload constraints. Therefore, these results provide a useful snapshot of how both **hardware evolution** and **software maturity** impact attention-heavy diffusion workloads on AMD platforms.\n\n**Hardware scaling (from RDNA3 to RDNA4).**\n\nKeeping the workload and backend constant, RDNA4 (Navi48) delivers roughly **+60% higher throughput** compared to RDNA3 (Navi31). This is the clearest signal in the data: newer GPU architectures translate directly into meaningful gains for attention-dominated workloads, independent of software improvements.\n\n**Software stack maturity.**\n\nEven on specific hardware, moving across different attention backends and software versions results in significant performance differences. Depending on the configuration, throughput improves by:\n\nup to\n\n**+20% on Navi48** up to\n\n**+36% on Navi31** up to\n\n**+50% on Strix Halo**\n\nThis highlights that the ROCm attention stack is still evolving rapidly, with backend selection playing a major role in overall performance.\n\n**Composable Kernels (CK) as the winner.**\n\nAcross nearly all tested configurations, **CK-backed implementations** (either via PyTorch SDPA-CK or DAO-AILab Flash Attention with CK) were typically the fastest in our measurements. This consistency confirms that hand-tuned kernel implementations remain the dominant factor for peak performance.\n\n**Strix Halo: trading throughput for capacity.**\n\nWhile Strix Halo shows approximately **3× lower raw throughput** compared to Navi48, which is expected due to its APU design, it enables workloads that would otherwise not fit on discrete GPUs, thanks to its **128GB unified memory**.\n\nIn this context, the key metric shifts from how fast it runs to whether it runs at all. Importantly, software improvements still scale well here, with up to **+50% gains** when comparing AOTriton with CK, indicating that the same optimization trends apply even in memory-bound scenarios.\n\n**Current performance insights and optimization opportunities.**\n\nThe results highlight several opportunities for continued optimization and refinement:\n\n**Cold-start latency**(3–11 minutes on Navi48), primarily driven by MIOpen kernel database tuning rather than steady-state execution performance. Thankfully, warm database runs eliminate most of this overhead, indicating strong runtime efficiency once the system is initialized.**Sage Attention** shows room for further tuning in this context, suggesting opportunities to improve its performance for these workloads or explore alternative optimizations.The observed performance of the\n\n**bumped AOTriton on Strix-Halo** highlights an interesting area for deeper analysis, which may unlock additional performance gains with further investigation.\n\n## Summary[#](#summary)\n\nIn this blog, you learned how ComfyUI attention algorithms map to ROCm backends and how those backend choices influence performance, memory usage, and stability on AMD GPUs. You also learned how to select optimal attention configuration for your workload using practical recommendations, implementation comparisons, and benchmark-driven performance analysis. Across all measured configurations, the dominant driver of throughput is the choice of backend (CK > AOTriton-bumped > AOTriton); silicon generation (RDNA4 over RDNA3) compounds those gains.\n\nWhile multiple attention paths are available, their behavior is shaped by a combination of ComfyUI priority rules, installed libraries, and the underlying ROCm backend. In practice, this means that seemingly small configuration choices, such as leaving xformers enabled, can significantly affect which attention implementation is actually used.\n\nFrom both analysis and benchmarking, a few clear patterns emerge:\n\n**PyTorch SDPA (AOTriton)** provides the most reliable and easiest-to-use default, with good performance.**PyTorch SDPA (CK)** provides mixed results. In the case of I2V workload the results are similar or even the same as DAO-AILab/flash-attention (CK backend), while in the case of T2V it even performs slightly better than DAO-AILab/flash-attention (CK backend) on Navi48. Nevertheless, it is not yet officially supported.**DAO-AILab/flash-attention (CK backend)** delivers the highest throughput, with improvements ranging from**~20% up to 40–50%** depending on the model and hardware.**xformers must be handled carefully**, as it is not stable and can silently override other attention choices.** Split and sub-quadratic attention**remain important fallbacks for memory-constrained scenarios, trading performance for stability.** Sage attention**produces significantly worse results than PyTorch SDPA (AOTriton) for Navi31 and Strix-Halo and therefore is not recommended. Additionally, on gfx12xx there are known issues with the sageattention package and[thu-ml/SageAttention#365](https://github.com/thu-ml/SageAttention/pull/365)needs to be included. Nevertheless, Sage attention, in certain cases, outperforms only PyTorch SDPA (AOTriton).\n\nThese findings highlight an important takeaway: **the CLI flag alone does not determine performance - the full stack, from flag to backend, must be considered**.\n\nFor most users, the following guidelines are a good starting point:\n\nUse\n\n`--use-pytorch-cross-attention`\n\nfor a stable, well-integrated default.Use\n\n`--use-flash-attention`\n\n(with xformers disabled) when maximizing throughput.Use split or sub-quadratic attention when memory pressure becomes a limiting factor.\n\nUltimately, optimal configuration still depends on the specific workload, model size, and GPU architecture. For optimal results, benchmarking on your target setup remains essential.\n\n*Note:* CK-based PyTorch SDPA and modified AOTriton configurations used here are experimental and not officially supported on RDNA architectures at the time of writing.\n\n## Disclaimers[#](#disclaimers)\n\nPerformance results are based on AMD testing using the WAN2.2 workflows, hardware platforms, software versions, and configurations described in this article. Actual results will vary depending on model, workload, software stack, system configuration, backend selection, and optimization settings. The information presented in this document is for informational purposes only and may contain technical inaccuracies, omissions, and typographical errors. The information contained herein is subject to change and may be rendered inaccurate for many reasons, including but not limited to product and roadmap changes, component and motherboard version changes, new model and/or product releases, product differences between differing manufacturers, software changes, BIOS flashes, firmware upgrades, or the like. Any computer system has risks of security vulnerabilities that cannot be completely prevented or mitigated. AMD assumes no obligation to update or otherwise correct or revise this information. However, AMD reserves the right to revise this information and to make changes from time to time to the content hereof without obligation of AMD to notify any person of such revisions or changes. THIS INFORMATION IS PROVIDED ‘AS IS.” AMD MAKES NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE CONTENTS HEREOF AND ASSUMES NO RESPONSIBILITY FOR ANY INACCURACIES, ERRORS, OR OMISSIONS THAT MAY APPEAR IN THIS INFORMATION. AMD SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT WILL AMD BE LIABLE TO ANY PERSON FOR ANY RELIANCE, DIRECT, INDIRECT, SPECIAL, OR OTHER CONSEQUENTIAL DAMAGES ARISING FROM THE USE OF ANY INFORMATION CONTAINED HEREIN, EVEN IF AMD IS EXPRESSLY ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. AMD, the AMD Arrow logo, AMD Radeon™, Radeon™, RDNA™, AMD Instinct™, Radeon Instinct™, CDNA, ROCm™ and combinations thereof are trademarks of Advanced Micro Devices, Inc. Other product names used in this publication are for identification purposes only and may be trademarks of their respective companies. Linux® is the registered trademark of Linus Torvalds in the U.S. and other countries. Python is a trademark of the Python Software Foundation. PyTorch, the PyTorch logo and any related marks are trademarks of The Linux Foundation. © 2026 Advanced Micro Devices, Inc. All rights reserved\n\nThird-party content is licensed to you directly by the third party that owns the content and is not licensed to you by AMD. ALL LINKED THIRD-PARTY CONTENT IS PROVIDED “AS IS” WITHOUT A WARRANTY OF ANY KIND. USE OF SUCH THIRD-PARTY CONTENT IS DONE AT YOUR SOLE DISCRETION AND UNDER NO CIRCUMSTANCES WILL AMD BE LIABLE TO YOU FOR ANY THIRD-PARTY CONTENT. YOU ASSUME ALL RISK AND ARE SOLELY RESPONSIBLE FOR ANY DAMAGES THAT MAY ARISE FROM YOUR USE OF THIRD-PARTY CONTENT.", "url": "https://wpnews.pro/news/understanding-attention-algorithms-and-their-backends-for-image-and-video", "canonical_source": "https://rocm.blogs.amd.com/software-tools-optimization/comfyui-fa-backends/README.html", "published_at": "2026-07-20 00:00:00+00:00", "updated_at": "2026-07-20 15:47:52.003141+00:00", "lang": "en", "topics": ["artificial-intelligence", "generative-ai", "ai-infrastructure", "ai-tools", "developer-tools"], "entities": ["AMD", "ComfyUI", "ROCm", "PyTorch", "AOTriton", "CK Tile", "xformers", "RDNA"], "alternates": {"html": "https://wpnews.pro/news/understanding-attention-algorithms-and-their-backends-for-image-and-video", "markdown": "https://wpnews.pro/news/understanding-attention-algorithms-and-their-backends-for-image-and-video.md", "text": "https://wpnews.pro/news/understanding-attention-algorithms-and-their-backends-for-image-and-video.txt", "jsonld": "https://wpnews.pro/news/understanding-attention-algorithms-and-their-backends-for-image-and-video.jsonld"}}