Sign In

Step-by-Step Guide Series: ComfyUI - Installing SageAttention 2

101
Step-by-Step Guide Series: ComfyUI - Installing SageAttention 2

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: For comfyUI portable, 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.x, 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 :

Automatic instalation:

Open PowerShell as administrator and run the following command:

winget install --id Microsoft.VisualStudio.2022.BuildTools -e --source winget --override "--quiet --wait --norestart --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows10SDK.20348"

Manual instalation:

Launch the install, 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 :

Only for ComfyUI portable version :

The portable version of python doesn't have all the necessary libraries, so you'll have to add them manually.

Go to your python folder and copy "include" and "libs" folder :

Paste it into “ComfyUI_windows_portable\python_embeded” :

For all version :

Now download triton and put it in a folder :

Open a terminal in this folder and run :

For ComfyUI Portable version (change the path to the one where you extracted ComfyUI portable) :

C:\AI\ComfyUI_windows_portable\python_embeded\python.exe -s -m pip install .\triton-3.2.0-cp312-cp312-win_amd64.whl

For ComfyUI installer version (change the path to the one where you instaled ComfyUI) :

C:\AI\ComfyUI\.venv\Scripts\activate.ps1 
python -s -m pip install .\triton-3.2.0-cp312-cp312-win_amd64.whl 

For ComfyUI git cloned version :

python -s -m pip install .\triton-3.2.0-cp312-cp312-win_amd64.whl

If you use a venv for your comfy activate it as for the installed version.

Sageattention2 :

Finally, we move on to the installation of sageattention.

Open a terminal in the folder of your choice and clone sageattention repo :

git clone https://github.com/thu-ml/SageAttention.git

Move to the downloaded folder and launch the installation:

cd .\SageAttention\  

For ComfyUI Portable version (change the path to the one where you extracted ComfyUI portable) :

C:\AI\ComfyUI_windows_portable\python_embeded\python.exe  -s -m pip install .

For ComfyUI installer version (change the path to the one where you instaled ComfyUI) :

C:\AI\ComfyUI\.venv\Scripts\activate.ps1 
python.exe  -s -m pip install . --no-build-isolation

For ComfyUI git cloned version :

python.exe  -s -m pip install . --no-build-isolation

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.

This guide is now complete. If you have any questions or suggestions, don't hesitate to post a comment.

If you have any problems, please be as specific as possible so that I can help you.

101

Comments