StabilityMatrix icon indicating copy to clipboard operation
StabilityMatrix copied to clipboard

Triton 3 wheels published for Windows

Open liujvnes opened this issue 1 year ago • 11 comments

Proposal

As seen here https://www.reddit.com/r/StableDiffusion/comments/1g45n6n/triton_3_wheels_published_for_windows_and_working/

Comfy could get a 24% speed benefit, should we try the pull or not? Thank you.

liujvnes avatar Oct 15 '24 19:10 liujvnes

It seems the Python installed by StabilityMatrix is an incomplete installation, and it lacks distutils. Please ask the authors of StabilityMatrix to fix that.

btw why stablitymatrix replace venv created with python 3.11. i want to use existing venv when using with stablity matrix.

shivshankar11 avatar Oct 15 '24 20:10 shivshankar11

This issue is stale because it has been open 30 days with no activity. Remove the stale label or comment, else this will be closed in 5 days.

github-actions[bot] avatar Nov 15 '24 02:11 github-actions[bot]

This is becoming a problem with many of the new video generaiton models requiring triton and sage. It would be great to be able to leverage the comfyUI in stable diffusion.

pupphelper avatar Dec 12 '24 03:12 pupphelper

I think those issues are related: #954 and #801 I use StabilityMatrix for 2 years and don't want to drop 🥹 Also found this issue from Reddit thread (see below): https://www.reddit.com/r/StableDiffusion/comments/1iz8npm/comment/mf1uran/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button

Q: Is there any roadmap on updated/compatible Python version?

Image

DmytroSokhach avatar Feb 27 '25 18:02 DmytroSokhach

There's nothing stopping you from installing pre-built wheels from the link above. Download the Python 3.10 version, open the Python Packages dialog, click the + button, and enter the path to the file you downloaded:

Image

Congrats, Triton is now installed in whichever webUI you chose.

Q: Is there any roadmap on updated/compatible Python version?

We are working on it. It's not as easy as it seems.

mohnjiles avatar Feb 27 '25 18:02 mohnjiles

There's nothing stopping you from installing pre-built wheels from the link above. Download the Python 3.10 version, open the Python Packages dialog, click the + button, and enter the path to the file you downloaded:

Image

Congrats, Triton is now installed in whichever webUI you chose.

Q: Is there any roadmap on updated/compatible Python version?

We are working on it. It's not as easy as it seems.

ITS INSTALL BUT NOT WORK, NOT A ISSUE WITH NORMAL VENV

PS S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI> venv\Scripts\activate (venv) PS S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI> pip install triton-3.2.0-cp310-cp310-win_amd64.whl Processing s:\ai\visual\stabilitymatrix\data\packages\comfyui webui\triton-3.2.0-cp310-cp310-win_amd64.whl Installing collected packages: triton Attempting uninstall: triton Found existing installation: triton 3.1.0 Uninstalling triton-3.1.0: Successfully uninstalled triton-3.1.0 Successfully installed triton-3.2.0 (venv) PS S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI> ./test.py (venv) PS S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI> python test.py Traceback (most recent call last): File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\test.py", line 2, in import triton File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages\triton_init_.py", line 20, in from .runtime import ( File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages\triton\runtime_init_.py", line 1, in from .autotuner import (Autotuner, Config, Heuristics, autotune, heuristics) File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages\triton\runtime\autotuner.py", line 9, in from .jit import KernelInterface File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages\triton\runtime\jit.py", line 12, in from ..runtime.driver import driver File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages\triton\runtime\driver.py", line 1, in from ..backends import backends File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages\triton\backends_init_.py", line 50, in backends = discover_backends() File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages\triton\backends_init.py", line 44, in _discover_backends driver = load_module(name, os.path.join(root, name, 'driver.py')) File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages\triton\backends_init.py", line 12, in _load_module spec.loader.exec_module(module) File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages\triton\backends\amd\driver.py", line 7, in from triton.runtime.build import build File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages\triton\runtime\build.py", line 8, in import setuptools File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages\setuptools_init.py", line 22, in import distutils_hack.override # noqa: F401 File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages_distutils_hack\override.py", line 1, in import('distutils_hack').do_override() File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages_distutils_hack_init.py", line 89, in do_override ensure_local_distutils() File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages_distutils_hack_init.py", line 76, in ensure_local_distutils assert '_distutils' in core.file, core.file AssertionError: S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\Scripts\python310.zip\distutils\core.pyc

shivshankar11 avatar Feb 27 '25 19:02 shivshankar11

There's nothing stopping you from installing pre-built wheels from the link above. Download the Python 3.10 version, open the Python Packages dialog, click the + button, and enter the path to the file you downloaded: Image Congrats, Triton is now installed in whichever webUI you chose.

Q: Is there any roadmap on updated/compatible Python version?

We are working on it. It's not as easy as it seems.

ITS INSTALL BUT NOT WORK, NOT A ISSUE WITH NORMAL VENV

PS S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI> venv\Scripts\activate (venv) PS S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI> pip install triton-3.2.0-cp310-cp310-win_amd64.whl Processing s:\ai\visual\stabilitymatrix\data\packages\comfyui webui\triton-3.2.0-cp310-cp310-win_amd64.whl Installing collected packages: triton Attempting uninstall: triton Found existing installation: triton 3.1.0 Uninstalling triton-3.1.0: Successfully uninstalled triton-3.1.0 Successfully installed triton-3.2.0 (venv) PS S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI> ./test.py (venv) PS S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI> python test.py Traceback (most recent call last): File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\test.py", line 2, in import triton File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages\triton__init__.py", line 20, in from .runtime import ( File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages\triton\runtime__init__.py", line 1, in from .autotuner import (Autotuner, Config, Heuristics, autotune, heuristics) File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages\triton\runtime\autotuner.py", line 9, in from .jit import KernelInterface File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages\triton\runtime\jit.py", line 12, in from ..runtime.driver import driver File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages\triton\runtime\driver.py", line 1, in from ..backends import backends File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages\triton\backends__init__.py", line 50, in backends = discover_backends() File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages\triton\backends__init_.py", line 44, in discover_backends driver = load_module(name, os.path.join(root, name, 'driver.py')) File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages\triton\backends__init.py", line 12, in load_module spec.loader.exec_module(module) File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages\triton\backends\amd\driver.py", line 7, in from triton.runtime.build import build File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages\triton\runtime\build.py", line 8, in import setuptools File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages\setuptools__init.py", line 22, in import distutils_hack.override # noqa: F401 File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages_distutils_hack\override.py", line 1, in import('distutils_hack').do_override() File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages_distutils_hack__init.py", line 89, in do_override ensure_local_distutils() File "S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\lib\site-packages_distutils_hack__init__.py", line 76, in ensure_local_distutils assert '_distutils' in core.file, core.file AssertionError: S:\Ai\Visual\StabilityMatrix\Data\Packages\ComfyUI WebUI\venv\Scripts\python310.zip\distutils\core.pyc

There's no need to yell. If you want it done, the code is open source, feel free to submit a PR.

mohnjiles avatar Feb 27 '25 19:02 mohnjiles

I've been using StabilityMatrix for a long time, but I guess the only way to have Triton actually working is to drop it and switch to ComfyUI portable, then ?

Talae06 avatar Mar 11 '25 12:03 Talae06

I've been using StabilityMatrix for a long time, but I guess the only way to have Triton actually working is to drop it and switch to ComfyUI portable, then ?

the only way, i think.

lilngu avatar Mar 19 '25 01:03 lilngu

A member of our Discord has written a guide to get it working in SM's Comfy, I'll paste it here. Many thanks to Xaragan on our Discord!

Installing SageAttention on StabilityMatrix (Windows)

This guide provides a step-by-step process to install SageAttention 2.1.1 for ComfyUI in StabilityMatrix on Windows 11.


1. Prerequisites: Ensure Required Dependencies Are Installed

Before proceeding, make sure the following are installed and properly configured:

Python 3.10 (required by StabilityMatrix)

  • Stability Matrix only supports Python 3.10 as of February 28, 2025.

Visual Studio 2022 Build Tools

  • Required for compiling components

CUDA 12.8 (Global Installation)

  • NOT within ComfyUI but as a system-wide installation
  • Install from: https://developer.nvidia.com/cuda-downloads
  • Verify CUDA 12.8 is set as default:
    nvcc --version
    
  • If an older CUDA version is shown, update your environment variables:
    set PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.8\bin;%PATH%
    set CUDA_HOME=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.8
    

2. Set Up the Environment

  1. Open Command Prompt (cmd.exe) as Administrator

  2. Navigate to your StabilityMatrix ComfyUI installation folder:

    cd /d [YOUR_STABILITY_MATRIX_PATH]\Data\Packages\ComfyUI
    

    Replace [YOUR_STABILITY_MATRIX_PATH] with your actual installation path (e.g., D:\Stability_Matrix)

  3. Activate the virtual environment:

    call venv\Scripts\activate.bat
    

3. Fix Distutils and Setuptools Issues

StabilityMatrix's embedded Python lacks some standard components that need to be fixed:

  1. Set the required environment variable:

    set SETUPTOOLS_USE_DISTUTILS=stdlib
    
  2. Upgrade setuptools:

    pip install --upgrade setuptools
    

4. Install Triton Manually

SageAttention requires Triton, which isn't properly included in StabilityMatrix:

  1. Download the Triton wheel from:
    https://github.com/woct0rdho/triton-windows/releases

  2. Install the latest Triton package:

    pip install [DOWNLOAD_PATH]\triton-3.2.0-cp310-cp310-win_amd64.whl
    

    Replace [DOWNLOAD_PATH] with the folder where you downloaded the wheel file

    Note: The latest version as of this guide is triton-3.2.0. Ensure you install the version compatible with Python 3.10: triton-3.2.0-cp310-cp310-win_amd64.whl


5. Install SageAttention (Requires Manual Compilation)

🚨 Important: pip install sageattention does not work for versions > 2, so manual building is required.

📌 Step 1: Set Environment Variables

set SETUPTOOLS_USE_DISTUTILS=setuptools

📌 Step 2: Copy Missing Development Files

StabilityMatrix's Python installation lacks development headers that need to be copied from your system Python.

A. Copy Python Header Files (Python.h)

  1. Source: Navigate to your system Python include directory:

    [SYSTEM_PYTHON_PATH]\include
    

    Replace [SYSTEM_PYTHON_PATH] with your Python 3.10 installation path (typically C:\Users\[USERNAME]\AppData\Local\Programs\Python\Python310 or C:\Python310)

  2. Copy all files from this folder

  3. Paste them into BOTH destination folders:

    [YOUR_STABILITY_MATRIX_PATH]\Data\Packages\ComfyUI\venv\Scripts\Include
    [YOUR_STABILITY_MATRIX_PATH]\Data\Packages\ComfyUI\venv\include
    

B. Copy the Python Library (python310.lib)

  1. Source: Navigate to:

    [SYSTEM_PYTHON_PATH]\libs
    

    Replace [SYSTEM_PYTHON_PATH] with your Python 3.10 installation path (typically C:\Users\[USERNAME]\AppData\Local\Programs\Python\Python310 or C:\Python310)

  2. Copy python310.lib from this folder

  3. Paste it into:

    [YOUR_STABILITY_MATRIX_PATH]\Data\Packages\ComfyUI\venv\libs
    

📌 Step 3: Install SageAttention

  1. Clone the SageAttention repository:

    git clone https://github.com/thu-ml/SageAttention.git [TARGET_FOLDER]\SageAttention
    

    Replace [TARGET_FOLDER] with your desired download location

  2. Install SageAttention in your ComfyUI virtual environment:

    pip install [TARGET_FOLDER]\SageAttention
    

6. Activate Sage Attention in ComfyUI

Add --use-sage-attention as a start argument for ComfyUI in StabilityMatrix.

A note of my own: you can use pip install triton-windows now instead of the prebuilt wheel if you prefer.

We're also making solid progress getting a newer, more compatible Python version that won't need so many hacky workarounds, and since it seems to be getting more popular now, look out for an "install sage attention" button in the app in the future that will automate all this.

mohnjiles avatar Mar 19 '25 02:03 mohnjiles

I also found these pre-made SageAttention wheels which might help:

https://github.com/woct0rdho/SageAttention/releases

But I'd also love to see PY 3.12...

Getting SageAttention working was definitely not straight forward. I was already using a Triton wheel, but getting errors. I followed the instructions above and installed triton-windows. That installed 3.3.0, I got different errors. But 3.2.0 was available, and now I finally got SageAttention working as well as TorchCompiling my models with the KJ nodes.

phazei avatar Apr 25 '25 20:04 phazei