How to install SageAttention2 on a Windows system with ComfyUI?
As I explained in this recent tutorial on how I optimized a ComfyUI workflow for Wan 2.2, SageAttention is a tool/component that allows you to generate videos faster.
To make the things easier, I'll consider that SINCE YOU HAVE COMFYUI, you already have a python virtual environment (venv) with everything installed and so on, because this will make the things much shorter to explain.
If you come here, I suppose that you are already aware of this kind of command:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
(don't use this one here)
or
pip install --force-reinstall torch torchvision --extra-index-url https://download.pytorch.org/whl/cu128
(this one is better for the present tutorial)
On a system that already has its CUDA toolkit:
(End of the warning)
So, first make sure to activate your "venv" environment: venv\Scripts\activate.bat
From there you can run the script: python combisage.py (save target as)
Run it with python to test if you have all the requirements (09.09:2025) to install SageAttention 2:
As given here:
https://github.com/thu-ml/SageAttention
You need this base environment:
python>=3.9 , torch>=2.3.0 , triton>=3.0.0
CUDA:
>=12.8 for Blackwell or SageAttention2++
>=12.4 for fp8 support on Ada
>=12.3 for fp8 support on Hopper
>=12.0 for Ampere
If you don't have the "MSVC C++ Compiler" and you want to install SageAttention2 from a WHL file, you probably don't need it. It is required if you want to install this software from its source on github on a windows system.
Once sageattention2 is installed, it gives this entry in your "pip list":
sageattention 2.2.0+cu128torch2.7.1.post2
So it is associated with a CUDA version and a Torch version.
If you have a version of CUDA that is lower than 12.8, it could be wise to uninstall it from the program files and install a more recent one:
https://developer.nvidia.com/cuda-12-8-0-download-archive (You may have to find a URL that is suitable for you)
The 12.8 was convenient for me.
Likewise, since I am going to explain that you should use a WHL file, because it is more convenient to install SageAttention2, make sure that the WHL file for sageattention that you can find is compatible with your version of Pytorch (torch).
Have a look here: https://github.com/woct0rdho/SageAttention/releases
sageattention-2.2.0+cu128torch2.8.0.post2-cp39-abi3-win_amd64.whl, means it will install "sage attention 2-2" it has been built for Torch 2.8.0. It is for python 3.9 (i used this packet despite having a python 3.10). It is for Windows on an amd64 system.
If not specify the version of Pytorch that you can find and install it with CUDA:
Exemple:
pip install --force-reinstall torch==2.8.0+cu128 torchvision --extra-index-url https://download.pytorch.org/whl/cu128
(yeah, that's an example, just an example)
See the WHL files for SageAttention that you can find and install a compatible environment for it.
***
If you need to install triton: pip install "triton>3"
***
The latest trick part is how to install the MSVC C++ Compiler:
Do you need the MSVC C++ Compiler ? Again, if you use a wheel file (.whl), likely no...
But you may want to install SageAttention from its source on a windows system.
You need then to go there:
https://visualstudio.microsoft.com/fr/downloads/
Download and run the setup tool VisualStudioSetup.exe
Install "Build Tools for Visual Studio" / "Desktop development with C++."
At the end, after the installation, you should have cl.exe available as command in your CMD shell or your power shell.
If you don't have it, you need to add its directory to your PATH.
It should be located in a place like that:
C:\Program Files\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.39.33523\bin\Hostx64\x64
(I don't know where it is on your system, but it should be a similar path).
Then, in the Windows search bar, type "environment variables" and open the matching option.
In the top section ("User variables for..."), select the Path variable and click "Edit...".
Click "New" and paste the full directory path you found.
****
When you think that you have installed everything correctly, run the script "combisage.py" again to check if everything is fine.
Then, download the best matching WHL file (see here or may be elsewhere) and install it like that in the environment where it should be installed:
pip install sageattention-2.2.0+cu128torch2.8.0.post2-cp39-abi3-win_amd64.whl
Or whatever is your wheel file is named...
Note that i used for myself a WHL file for python 3.9 despite having python 3.10, but my version of CUDA and Pytorch match.
Then you can try this in your console:
python -c "import sageattention"
(shouldn't return any error and nothing else)
pip show sageattention
(should show the details of the package).