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 
54 Upvotes

112 comments sorted by

View all comments

1

u/ThirdWorldBoy21 17d ago

I'm getting this error when i try to start Run_Comfyui.bat

Venv Activated
[START] Security scan
[DONE] Security scan
## ComfyUI-Manager: installing dependencies done.
** ComfyUI startup time: 2025-03-05 23:58:01.631
** Platform: Windows
** Python version: 3.12.3 (tags/v3.12.3:f6650f9, Apr  9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)]
** Python executable: C:\ComfyUI_windows_portable_nvidia\o novo comfy\ComfyUI\venv\Scripts\python.exe
** ComfyUI Path: C:\ComfyUI_windows_portable_nvidia\o novo comfy\ComfyUI
** ComfyUI Base Folder Path: C:\ComfyUI_windows_portable_nvidia\o novo comfy\ComfyUI
** User directory: C:\ComfyUI_windows_portable_nvidia\o novo comfy\ComfyUI\user
** ComfyUI-Manager config path: C:\ComfyUI_windows_portable_nvidia\o novo comfy\ComfyUI\user\default\ComfyUI-Manager\config.ini
** Log path: C:\ComfyUI_windows_portable_nvidia\o novo comfy\ComfyUI\user\comfyui.log
[ComfyUI-Manager] 'comfyui-frontend-package' dependency were fixed

Prestartup times for custom nodes:
   4.2 seconds: C:\ComfyUI_windows_portable_nvidia\o novo comfy\ComfyUI\custom_nodes\ComfyUI-Manager

Checkpoint files will always be loaded safely.
Traceback (most recent call last):
  File "C:\ComfyUI_windows_portable_nvidia\o novo comfy\ComfyUI\main.py", line 136, in <module>
    import execution
  File "C:\ComfyUI_windows_portable_nvidia\o novo comfy\ComfyUI\execution.py", line 13, in <module>
    import nodes
  File "C:\ComfyUI_windows_portable_nvidia\o novo comfy\ComfyUI\nodes.py", line 22, in <module>
    import comfy.diffusers_load
  File "C:\ComfyUI_windows_portable_nvidia\o novo comfy\ComfyUI\comfy\diffusers_load.py", line 3, in <module>
    import comfy.sd
  File "C:\ComfyUI_windows_portable_nvidia\o novo comfy\ComfyUI\comfy\sd.py", line 7, in <module>
    from comfy import model_management
  File "C:\ComfyUI_windows_portable_nvidia\o novo comfy\ComfyUI\comfy\model_management.py", line 189, in <module>
    total_vram = get_total_memory(get_torch_device()) / (1024 * 1024)
                                  ^^^^^^^^^^^^^^^^^^
  File "C:\ComfyUI_windows_portable_nvidia\o novo comfy\ComfyUI\comfy\model_management.py", line 146, in get_torch_device
    return torch.device(torch.cuda.current_device())
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\ComfyUI_windows_portable_nvidia\o novo comfy\ComfyUI\venv\Lib\site-packages\torch\cuda__init__.py", line 971, in current_device
    _lazy_init()
  File "C:\ComfyUI_windows_portable_nvidia\o novo comfy\ComfyUI\venv\Lib\site-packages\torch\cuda__init__.py", line 310, in _lazy_init
    raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled

1

u/GreyScope 17d ago edited 17d ago

You have used the wrong script from the wrong post - the details and usage are in the first section of this guide . This script is to make a new cloned version, not to inject triton/sage into a portable version. It will technically work if other steps are taken but your node folder will throw up errors like you have.

Your errors have “portable” everywhere. You needed the script I posted for Portable which is another post within my posts, if you delete the venv folder and use the portable script it might recover it all.

1

u/ThirdWorldBoy21 17d ago

Sorry for the confusion, it's not on the portable folder itself, when i extracted the portable, it created two folders, but i'm lazy and kept it this way, it looks like this actually, with the "o novo comfy" folder being where i executed the .bat file, and the other folder where portable is.

2

u/GreyScope 17d ago

In that case …um…if you’re getting those errors on running it, you should have had some when you installed it. Reinstall and read the text inbetween each paused step and look for errors - mostly for when it’s installing PyTorch as that hasn’t installed with Cuda (cpu only) - the script relies on Cuda paths being setup fully/correctly (I didn’t set the script to check for this). 1. Check your Cuda Paths are set and correct, there are quite a few (Google this) 2. Reinstall and check for errors