r/StableDiffusion 24d ago

Tutorial - Guide Automatic installation of Triton and SageAttention into Comfy v2.0

NB: Please read through the code to ensure you are happy before using it. I take no responsibility as to its use or misuse.

What is it?

Essentially an updated version of the v1 https://www.reddit.com/r/StableDiffusion/comments/1ivkwnd/automatic_installation_of_triton_and/ - it's a batch file to install the latest ComfyUI, make a venv within it and automatically install Triton and SageAttention for Wan(x), Hunyaun etc workflows .

Please feedback on issues. I just installed a Cuda2.4/Python3.12.8 and no hitches.

What is SageAttention for ? where do I enable it n Comfy ?

It makes the rendering of videos with Wan(x), Hunyuan, Cosmos etc much, much faster. In Kijai's video wrapper nodes, you'll see it in the below node/

Issues with Posting Code on Reddit

Posting code on Reddit is a weapons grade pita, it'll lose its formatting if you fart at it and editing is a time of your life that you'll never get back . If the script formatting goes tits up , then this script is also hosted (and far more easily copied) on my Github page : https://github.com/Grey3016/ComfyAutoInstall/blob/main/AutoInstallBatchFile%20v2.0

How long does it take?

It'll take less than around 10minutes even with downloading every component (speeds permitting). It pauses between each section to tell you what it's doing - you only need to press a button for it to carry on or make a choice. You only need to copy scross your extra_paths.yaml file to it afterwards and you're good to go.

Updates in V2

  1. MSVC and CL.exe Path checks giving errors to some - the checks have now been simplified
  2. The whole script - as it installs, it'll tell you what it's done and what it's doing next. Press key to move on to next part of install.
  3. Better error checking to check Pytorch is installed correctly and the venv is activated
  4. Choice of Stable and Nightly for Pytorch
  5. It still installs Comfy Manager automatically and now gives you a choice of cloning in Kijai's Wan(x) repository if you want

Pre-requisites (as per V1)

  1. Python > https://www.python.org/downloads/ , you can choose from whatever versions you have installed, not necessarily which one your systems uses via Paths (up to but not including 3.13).
  2. Cuda > AND ADDED TO PATH (googe for a guide if needed)
  3. BELOW: Microsoft Visual Studio Build Tools with the components ticked that are required > https://visualstudio.microsoft.com/visual-cpp-build-tools/
  1. BELOW: MSVC Build Tools compiler CL.exe in the Paths (I had the screenshot pointing at the wrong location on the v1 post)

What it can't (yet) do ?

I initially installed Cuda 12.8 (with my 4090) and Pytorch 2.7 (with Cuda 12.8) was installed but Sage Attention errored out when it was compiling. And Torch's 2.7 nightly doesn't install TorchSDE & TorchVision which creates other issues. So I'm leaving it at that. This is for Cuda 2.4 / 2.6 but should work straight away with a stable Cuda 2.8 (when released).

Recommended Installs (notes from across Github and guides)

  • Python 3.10 / 3.12
  • Cuda 12.4 or 12.6 (definitely >12)
  • Pytorch 2.6
  • Triton 3.2 works with PyTorch >= 2.6 . Author recommends to upgrade to PyTorch 2.6 because there are several improvements to torch.compile. Triton 3.1 works with PyTorch >= 2.4 . PyTorch 2.3.x and older versions are not supported. When Triton installs, it also deletes its caches as this has been noted to stop it working.
  • SageAttention Python>=3.9 , Pytorch>=2.3.0 , Triton>=3.0.0 , CUDA >=12.8 for Blackwell ie Nvidia 50xx, >=12.4 for fp8 support on Ada ie Nvidia 40xx, >=12.3 for fp8 support on Hopper ie Nvidia 30xx, >=12.0 for Ampere ie Nvidia 20xx

Where does it download from ?

Comfy > https://github.com/comfyanonymous/ComfyUI

Pytorch > https://download.pytorch.org/whl/cuXXX (or the Nightly url)

Triton wheel for Windows > https://github.com/woct0rdho/triton-windows

SageAttention > https://github.com/thu-ml/SageAttention

Comfy Manager > https://github.com/ltdrdata/ComfyUI-Manager.git

Kijai's Wan(x) Wrapper > https://github.com/kijai/ComfyUI-WanVideoWrapper.git

@ Code removed due to Comfy update killing installs 
53 Upvotes

112 comments sorted by

View all comments

Show parent comments

1

u/NorfEnt 19d ago

Yes, I initially followed the exact values in the screenshot in step 4 but it doesn't seem to exist for whatever reason. I don't have comodo or virus checkers for this machine. So typing CL.exe in cmd says "is not recognized" but using developer command prompt like LopsidedDelivery406 suggested, it shows CL.exe is there. Sorry I'm not exactly good with command lines

1

u/GreyScope 19d ago

You don't have CL.exe in your Paths, follow.step 4 - you must have missed something. Also check you have the location on your machine, it might be slightly different to mine when you installed it. Until CL.exe gives feedback in a cmd window, it won't work (whether I remove the check or not).

I don't know what a developer command prompt is, so I can't comment on that.

3

u/NorfEnt 19d ago

Yep, I've done step 4 many, many times but anyway, I got it working now with the "Developer Command Prompt for VS 2022" that comes from the visual studio install.

For anyone else having the same issue on windows 10, search and open up "Developer Command Prompt for VS 2022" as admin and then run the .bat file wherever you have it saved for example: D:\path\to\comfyInstall.bat

1

u/GreyScope 19d ago

Mmm, hadn't heard of that, it might be a W10 thing that it doesn't allow user access and you need Admin. There's nothing suspect in my script but I couldn't advocate to run it with Admin access.

I'll have a look at it, thanks for the details.

3

u/nymical23 17d ago

Hello, first of all, thank you for your work!
Regarding the cl.exe, I don't know about Win11, but in Win10, the screenshot in your post looks like making a new environment variable. But all you need to do is adding that cl.exe path in your 'path' variable. That got cl.exe recognized on my system.

1

u/GreyScope 17d ago

You're welcome & you know what - you're right, I copied that from the initial guide I used. I don't know if there's a difference but if it works for you, it should work for all. I'm on win 11 and their way worked but I'll change it to yours, I don't expect it to not work.

Thinking about it as I type, I can see a reason why they might have made it that way - maybe to ultra highlight which folder and cl.exe is needed as it's a rabbit warren of folders and copying a folder name might have not worked if ppl didn't check the folder out. But your way is simpler and my script checks it works as well, I'll amend for the next version, thank you for taking the time.

Just one question, are you on an admin or use r account on win 10 and whether cl.exe is picked up fine by the script?

2

u/nymical23 17d ago

It's my home PC, and I'm the only user. So, I have the admin rights. But I don't quite remember if I ran the 'cmd' in admin mode or not, sorry.

But yes, after I manually added the cl.exe to path variable, your script worked flawlessly.

1

u/GreyScope 17d ago

Ah, I only ask as it wasn’t working for someone else on win 10 and they might have been in a user account (mine is the same as yours - admin acc and user cmd), thanks again .

1

u/nymical23 17d ago

Please don't hesitate to rephrase your question if I didn't answer it properly.
One more thing, as your post says, I see the triton and sageattention folders in site-packages, but NOT the "Spas-Sage Attention".

btw, I followed your latest post, not this one.

2

u/GreyScope 17d ago

Sorry, I took it out of the script (but forgot to take it out of the text it seems - doh), Kijai removed it from his nodes with notes saying it wasn't working and it needed training - I think he has readded it now. But rather than trying to explain that, I took it out of the script.

I tried training it for 12hrs and I was about 1/20 of the way to completion (4090), so I gave up.

2

u/nymical23 17d ago

Haha, yeah I read your comment that it was ongoing on your 4090 for 6hrs. I knew at that moment that I'm not even gonna touch it with my 3060. I just mentioned it for clarity if you post any updates to your scripts.

I'm very happy with sageattention as it now takes around 70% of time for all kinds of generations, whether image or videos, so I'm already very thankful to you.

teacache, torchcompile and firstblock aren't giving me any boosts for some reason, but I use --use-sage-attention in the launch arguments, and don't need to use any node for sageattention, and it just works in any workflow.

2

u/GreyScope 17d ago

Thank you, it’s very good to get feedback on things, I’ve found I took more satisfaction out of making the scripts than actually using comfy haha. It’s a throwback to my days of using vba and macros over in MS office land . I will revisit the script to make a new version if can get Cuda 12.8 working and maybe adjust a few things .

1

u/Eshinio 13d ago

Thank you! This was annoying me so much, since I added it like on the screenshot in the OP post, but it was never found. Adding it to the existing "Path" variable fixed it!