Step-by-Step Guide Series:
Windows ComfyUI - Installing SageAttention 2
Foreword :
English is not my mother tongue, so I apologize for any errors. Do not hesitate to send me messages if you find any.
This guide is intended to be as simple as possible, and certain terms will be simplified.
Purpose of this guide :
The aim of this guide is to describe step by step how to install SageAttention2 on the portable version of ComfyUI.
Why do you want to do this? :
Simply put, Sageattention will enable you to greatly reduce the time needed to generate video with WAN2.1, for example.
You can find out more about how it works on the dedicated Github page: https://github.com/thu-ml/SageAttention
Overview of performance gains on a 4090.
Prerequisites :
Warning: Updating ComfyUI is not enough! The embedded python version must be 3.12, which is never updated via ComfyUI manager, for example.
To check your Python version, open a terminal in the “ComfyUI_windows_portable\python_embeded” folder and type “.\python.exe --version”.
If you don't see 3.12.9, you need to re-download ComfyUI portable.
If you've been using my automated intalation script version 1.2 or higher, then you've already got the right version.
CUDA :
For cuda, just run the installer and leave the default options.
Once installation is complete, check that two new entries have been added to your environment variables:
Python :
Launch the installer, check both boxes and click "Install Now":
Click on "Disable path length limit" :
Click on "Close" :
Microsoft Visual Studio Build Tools :
Launch the installe, check boxes like this and click on "install while downloading" :
Once finished, reopen the environment variables and add a new system entry:
Variable name : cl.exe
Variable value : C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.43.34808\bin\Hostx86\x64\
Triton :
The portable version of python doesn't have all the necessary libraries, so you'll have to add them manually.
Download this : link
Unzip it :
Warning: depending on your windows security settings, the zip may be locked. You need to right-click on the zip, then select “property”, and check whether an “unlock” box is present in the bottom right-hand corner. If so, check it and apply before unzipping.
Copy both folders into “ComfyUI_windows_portable\python_embeded” :
Now download triton and put it in the folder :
Open a terminal in this folder and run :
.\python.exe -s -m pip install .\triton-3.2.0-cp312-cp312-win_amd64.whl
Sageattention2 :
Finally, we move on to the installation of sageattention.
Open a terminal in “ComfyUI_windows_portable\python_embeded” and clone sageattention repo :
git clone https://github.com/thu-ml/SageAttention.git
Move to the downloaded folder and launch the installation:
cd .\SageAttention\
..\python.exe -s -m pip install -e .
Wait until you get your hand back :
If all went well, you've finally made it!
How to use it :
After all that, perhaps you'd like to know how to activate this in ComfyUI?
You have two choices:
Use it only on certain workflows,
Run comfy directly with sageattention.
To activate it from a workflow:
In all my WAN2.1 workflows you will find the “Sage Attention” node:
You can now set it to sageattn triton :
To enable it when starting ComfyUI:
Edit the file "run_nvidia_gpu" :
Add "--use-sage-attention" at the end of the first line and save :
Start ComfyUI with this modified script.
If the modification worked well, you will be able to observe this line appear when starting ComfyUI.