Announcement: The development has moved to https://github.com/triton-lang/triton-windows . Users are not affected by this change, and you can continue to install triton-windows using pip. Currently the maintainers of the new repo are @woct0rdho and @jammm.
Based on andreigh, wkpark, mantaionut, eaplatanios, anmyachev, and more development in the community. Thank you all!
triton.jit and torch.compile just workTriton accelerates your AI model by compiling things on your computer. You need to install it in the correct environment.
Check your GPU model. Technically they're categorized by 'compute capability' (also known as 'CUDA architecture', 'streaming multiprocessor version', or 'sm'). For example:
This is officially supported by Triton. It only works with Triton >= 3.3, PyTorch >= 2.7, and CUDA >= 12.8 .
This is officially supported by Triton.
This is officially supported by Triton. Although fp8 (also known as float8) on Ampere is not supported by the official Triton, it's supported since triton-windows 3.5.0.post21.
This is officially supported by Triton <= 3.2 . Support for Turing has been dropped since Triton 3.3, see https://github.com/triton-lang/triton/pull/5066
Although fp8 (also known as float8) and bf16 (also known as bfloat16) on Turing are not supported by the official Triton, fp8 is supported since triton-windows 3.2.0.post21.
This is not supported. See https://github.com/woct0rdho/triton-windows/issues/133 if you want to help.
Also, make sure you have the latest GPU driver.
Check how your Python is installed. Either of the following environments is supported:
python_embeded in the ComfyUI installation folder
system\python in the FramePack installation folderpython, but use the full path C:\path\to\python_embeded\python.exepip, but instead run C:\path\to\python_embeded\python.exe -m pippip.exe in the folder python_embeded. If you directly run pip, you're actually running a pip.exe installed somewhere else on your computercd to python_embeded, then run .\python.exe, but remember to add .\ to run an executable in the current folder. In PowerShell, without .\, you're still running a python.exe installed somewhere else on your computerC:\Python312\ or C:\Program Files\Python312\ and directly use itC:\Users\<your username>\AppData\Local\Programs\Python\Python312\ and directly use itcondavenv or virtualenvI don't recommend installing Python from Windows Store, because it's complicated to interact with a 'packaged' Windows app.
For other environment managers like poetry or uv, if you find problems, please open an issue.
Make sure what environment you're using. You can run Get-Command -All python in PowerShell (or where python in cmd) to see the installation path of Python, and python --version to see its version. If you see multiple Python installations, make sure that you install and run everything from the first one.
cp311 in its name, then it means you're not using the Python environment you thinkDon't mix two environments, unless you know them very well.
Although technically Triton can be used alone, in the following let's assume you use it with PyTorch. Each PyTorch minor version is only guaranteed to work with a specific Triton minor version:
| PyTorch | Triton |
|---|---|
| 2.4 | 3.1 |
| 2.5 | 3.1 |
| 2.6 | 3.2 |
| 2.7 | 3.3 |
| 2.8 | 3.4 |
| 2.9 | 3.5 |
| 2.10 | 3.6 |
PyTorch 2.3 and older are not supported in this repo.
If you have to use Triton 3.2 because you're using an old GPU, then you can try to use Triton 3.2 with PyTorch >= 2.7, but it's not guaranteed to always work.
You can skip this.
Since triton-windows 3.2.0.post11, a minimal CUDA toolchain is bundled in the Triton wheels, so you don't need to manually install it.
CUDA toolchain minor version bundled in each Triton minor version:
| Triton | CUDA |
|---|---|
| 3.1 .. 3.2 | 12.4 |
| 3.3 .. 3.6 | 12.8 |
See nvidia-toolchain-version.json for the detailed versions.
If you need to override the CUDA toolchain, you can set the environment variable CUDA_PATH.
CUDA 12 is required. CUDA 11 and older are not supported. Choose either of the following ways to install CUDA:
a) System-wide: Recommended for most people
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.8\include
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.8\lib\x64
PATH:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.8\binptxas --version, and it shows your CUDA version like Cuda compilation tools, release 12.8, V12.8.61, then you're doing rightb) conda: Do this only if you're already using conda
conda install -c conda-forge cuda-nvcc pytorch-gpu
pytorch channel, and it should be installed in conda-forge channelc) pip: Do this if you don't want to install too much boilerplate, and you want to contain everything in a venv, with minimal impact to the system
pip install nvidia-cuda-nvcc-cu12 nvidia-cuda-runtime-cu12
Lib\site-packages\nvidia\cuda_runtime\ in your Python installation path (or venv), and you need to add a library in it
lib into cuda_runtimeFor details about version compatibility of various pip packages and CUDA, see https://github.com/woct0rdho/triton-windows/issues/43
You can skip this.
Since triton-windows 3.2.0.post13, TinyCC is bundled in the Triton wheels, so you don't need to manually install a C compiler to use Triton. Packages that directly call triton.jit, such as SageAttention, will just work.
You still need to install a C++ compiler if you use torch.compile targeting CPU. This may happen when you use nodes like 'CompileModel' in ComfyUI. Triton does not affect how PyTorch configures the C++ compiler in this case.
If you need to override the C compiler, you can set the environment variable CC. MSVC, GCC, and Clang are supported for the JIT compilation in Triton.
If you set CC in the 'Environment Variables' window, then it should be a string, not a list. A list will implicitly add a semicolon ; at its end and cause problems.
If you don't have a C compiler, I recommend to install MSVC and Windows SDK.
Then you need to add the path containing cl.exe to the Windows PATH:
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.43.34808\bin\Hostx64\x64cl, and it shows Microsoft (R) C/C++ Optimizing Compiler ..., then you're doing rightDo this if you don't want to permanently modify the Windows PATH.
Before running Python, if you use PowerShell, run the following: (Find the ps1 file according to your installation)
&"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Launch-VsDevShell.ps1" -Arch amd64
Or if you use cmd, run the following: (This is equivalent to 'x64 Native Tools Command Prompt' from the Start menu)
"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\VsDevCmd.bat" -arch=amd64
It automatically adds the paths containing cl.exe and other relevant VS components, see https://github.com/woct0rdho/triton-windows/issues/79 . Although it does not set the environment variable CC, it sets VCINSTALLDIR, VCToolsVersion, WindowsSdkDir, WindowsSDKVersion, and Triton will recognize them.
vcredist is required (also known as 'Visual C++ Redistributable for Visual Studio 2015-2022', msvcp140.dll, vcruntime140.dll), because libtriton.pyd is compiled by MSVC. Install it from https://aka.ms/vs/17/release/vc_redist.x64.exe
Since triton-windows 3.2.0.post11, the wheels are published to https://pypi.org/project/triton-windows/ , so you don't need to manually download a wheel from GitHub releases, and pip will automatically find it.
If you've installed an old version of triton, first uninstall it:
pip uninstall triton
Now you can install triton-windows 3.6, or upgrade the already installed version. To prevent breaking with your installed PyTorch when a new version of Triton is released in future, you can limit the version to be < 3.7:
pip install -U "triton-windows<3.7"
Note again that if you're using the embeded Python, then instead of directly run pip, you need:
C:\path\to\python_embeded\python.exe -m pip install -U "triton-windows<3.7"
Or if you want triton-windows 3.2, then run:
pip install -U "triton-windows<3.3"
python_embeded in the ComfyUI installation foldersystem\python in the FramePack installation foldervenv\Scripts folderos.path.dirname(sysconfig.get_paths()["include"]) to find the Python folder, see py_include_dirinclude and libs into the Python folder to make Triton work
Lib in the Python folder, containing things like site-packages or __future__.py. You should not modify the Lib folderpython-dev on Linux, and you can obtain the two folders from nuget when bundling Python in your app, see https://github.com/comfyanonymous/ComfyUI/pull/7200 )Before using Triton in larger projects like ComfyUI, please run the following script to test if Triton itself works.
test_triton.py, then run python test_triton.pyimport torch
import triton
import triton.language as tl
@triton.jit
def add_kernel(x_ptr, y_ptr, output_ptr, n_elements, BLOCK_SIZE: tl.constexpr):
pid = tl.program_id(axis=0)
block_start = pid * BLOCK_SIZE
offsets = block_start + tl.arange(0, BLOCK_SIZE)
mask = offsets < n_elements
x = tl.load(x_ptr + offsets, mask=mask)
y = tl.load(y_ptr + offsets, mask=mask)
output = x + y
tl.store(output_ptr + offsets, output, mask=mask)
def add(x: torch.Tensor, y: torch.Tensor):
output = torch.empty_like(x)
n_elements = output.numel()
grid = lambda meta: (triton.cdiv(n_elements, meta["BLOCK_SIZE"]),)
add_kernel[grid](x, y, output, n_elements, BLOCK_SIZE=1024)
return output
a = torch.rand(3, device="cuda")
b = a + a
b_compiled = add(a, a)
print(b_compiled - b)
print("If you see tensor([0., 0., 0.], device='cuda:0'), then it works")
ModuleNotFoundError: No module named 'triton.language'; 'triton' is not a packageDon't name the test script triton.py. Also, check if there is a folder named triton in your current directory. If so, Python will think it's the 'triton' package and fail to import.
AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'This is because your setuptools is outdated. Run the following and try again:
python -m ensurepip -U
python -m pip install -U pip
python -m pip install -U setuptools
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\<your username>\\.triton'This is because of the permission settings of your user folder, see https://github.com/lllyasviel/FramePack/issues/221
ImportError: DLL load failed while importing libtritonThis is usually because your vcredist DLLs are too old.
If you're using conda, then you may try:
conda install -c conda-forge vc14_runtime
If you're not using conda, then you need to find the vcredist DLLs (vcruntime140.dll, vcruntime140_1.dll) in your Python installation folder:
python_embeded.system\python in the FramePack installation folderIf you're not sure, you can run the following in the same Python environment:
import sysconfig
print(sysconfig.get_paths())
For example, it may show {'stdlib': 'C:\\Python312\\Lib', 'platstdlib': 'C:\\tmp\\.venv\\Lib', ...}, where stdlib shows that the 'base' Python installation folder (not the venv folder) is C:\Python312\ (without the last Lib). The DLLs should be in this folder.
After finding the DLLs in the Python installation folder, you can install the latest vcredist, then copy the DLLs msvcp140.dll, vcruntime140.dll, vcruntime140_1.dll from C:\Windows\System32\ to the Python installation folder, and replace the existing ones.
You can right-click the DLL -> Properties -> Details to see its version. A new enough version, such as 14.42, is required by my Triton wheels.
ImportError: DLL load failed while importing cuda_utilsC:\Users\<your username>\.triton\cache\
C:\Users\<your username>\AppData\Local\Temp\torchinductor_<your username>\
triton.jit (which is used by packages like SageAttention), and the second folder exists only if you have used torch.compileGet-Command -All python in PowerShell (or where python in cmd) to see the installation path of Python, and python --version to see its version. If you see multiple Python installations, make sure that you install and run everything from the first oneinclude and libs from the correct version of PythonSystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formatsYou also need to delete the cache folders above.
This should not happen if you upgrade to Python 3.13, see https://github.com/python/cpython/issues/104922 . If the error still exists, you may try to debug following https://github.com/woct0rdho/triton-windows/issues/163
If the above still doesn't work, you may try:
import sys
import dlltracer
print("import torch")
with dlltracer.Trace(out=sys.stdout):
import torch
print("import triton")
with dlltracer.Trace(out=sys.stdout):
import triton
print("begin definition")
with dlltracer.Trace(out=sys.stdout):
import triton.language as tl
@triton.jit
def add_kernel(x_ptr, y_ptr, output_ptr, n_elements, BLOCK_SIZE: tl.constexpr):
pid = tl.program_id(axis=0)
block_start = pid * BLOCK_SIZE
offsets = block_start + tl.arange(0, BLOCK_SIZE)
mask = offsets < n_elements
x = tl.load(x_ptr + offsets, mask=mask)
y = tl.load(y_ptr + offsets, mask=mask)
output = x + y
tl.store(output_ptr + offsets, output, mask=mask)
def add(x: torch.Tensor, y: torch.Tensor):
output = torch.empty_like(x)
n_elements = output.numel()
grid = lambda meta: (triton.cdiv(n_elements, meta["BLOCK_SIZE"]),)
add_kernel[grid](x, y, output, n_elements, BLOCK_SIZE=1024)
return output
print("begin torch add")
with dlltracer.Trace(out=sys.stdout):
a = torch.rand(3, device="cuda")
b = a + a
print("begin jit add")
with dlltracer.Trace(out=sys.stdout):
b_compiled = add(a, a)
print(b_compiled - b)
print("If you see tensor([0., 0., 0.], device='cuda:0'), then it works")
If it shows PermissionError: [WinError 5] failed to start trace (0x00000005), then you need to make sure to run it as administrator.
(Security reminder: You don't need the administrator privilege to run Triton and other usual Python code. It's only dlltracer that needs it.)
If it shows Failed \Device\...\cuda_utils.pyd, please also:
cuda_utils.pyd at this locationcuda_utils.pyd depends on, and send a screenshot (or other related information) in the issuetorch.compile may create temp files with very long filenames, causing errors like:
File "C:\...\Lib\site-packages\torch\_inductor\runtime\triton_heuristics.py", line 537, in _precompile_config
binary = triton.compile(*compile_args, **compile_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\...\Lib\site-packages\triton\compiler\compiler.py", line 288, in compile
metadata_group[ir_filename] = fn_cache_manager.put(next_module, ir_filename)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\...\Lib\site-packages\triton\runtime\cache.py", line 122, in put
with open(temp_path, mode) as f:
^^^^^^^^^^^^^^^^^^^^^
torch._inductor.exc.InductorError: FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\<your username>\\AppData\\Local\\Temp\\torchinductor_<your username>\\triton\\0\\...LONG...FILE...NAME...'
Or errors like:
[WinError 206] The filename or extension is too long
The solution is to enable Windows' long path support. A reboot is required after the modification.
If you see errors like
torch._dynamo.exc.BackendCompilerFailed: backend='inductor' raised:
CompilationError: at 8:11:
def triton_(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
xnumel = 196608
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = tl.full([XBLOCK], True, tl.int1)
x0 = xindex
tmp0 = tl.load(in_ptr0 + (x0), None)
tmp1 = tmp0.to(tl.float32)
^
and in the full error log you find
AssertionError: fp8e4nv data type is not supported on CUDA arch < 89
then it's because in the official Triton, fp8 only works on Nvidia GPUs with sm >= 89, such as RTX 40xx and newer.
Since triton-windows 3.5.0.post21, fp8 on RTX 30xx is supported.
os.renameIf you see errors like
FileExistsError: [WinError 183] Cannot create a file when that file already exists: ...
then you need: https://github.com/pytorch/pytorch/issues/138211
This has been fixed since PyTorch 2.6 .
If you're using ComfyUI, the model is compiled, and you see error messages like
ValueError: Pointer argument (at 0) cannot be accessed from Triton (cpu tensor?)
then you may use --gpu-only when launching ComfyUI to disable model offloading, see https://github.com/woct0rdho/triton-windows/issues/61
triton.ops was removed in Triton 3.1, and this is because some of your Python package is outdated (most likely bitsandbytes), see https://github.com/woct0rdho/triton-windows/issues/65
Exception Code: 0x80000003If you see Exception Code: 0x80000003 in libtriton.pyd in a function like registerImplicitTypeID, that may not actually be an issue in Triton, but a CUDA error happened earlier, see https://github.com/thu-ml/SageAttention/issues/270 . If you want to help debug, you may set the environment variable CUDA_LAUNCH_BLOCKING=1 and run again.
See BUILD.md. This is for developers.
(top 30 of 394)
MLIR
39.9%
Python
30.8%
C++
28.8%
Announcement: The development has moved to https://github.com/triton-lang/triton-windows . Users are not affected by this change, and you can continue to install triton-windows using pip. Currently the maintainers of the new repo are @woct0rdho and @jammm.
Based on andreigh, wkpark, mantaionut, eaplatanios, anmyachev, and more development in the community. Thank you all!
triton.jit and torch.compile just workTriton accelerates your AI model by compiling things on your computer. You need to install it in the correct environment.
Check your GPU model. Technically they're categorized by 'compute capability' (also known as 'CUDA architecture', 'streaming multiprocessor version', or 'sm'). For example:
This is officially supported by Triton. It only works with Triton >= 3.3, PyTorch >= 2.7, and CUDA >= 12.8 .
This is officially supported by Triton.
This is officially supported by Triton. Although fp8 (also known as float8) on Ampere is not supported by the official Triton, it's supported since triton-windows 3.5.0.post21.
This is officially supported by Triton <= 3.2 . Support for Turing has been dropped since Triton 3.3, see https://github.com/triton-lang/triton/pull/5066
Although fp8 (also known as float8) and bf16 (also known as bfloat16) on Turing are not supported by the official Triton, fp8 is supported since triton-windows 3.2.0.post21.
This is not supported. See https://github.com/woct0rdho/triton-windows/issues/133 if you want to help.
Also, make sure you have the latest GPU driver.
Check how your Python is installed. Either of the following environments is supported:
python_embeded in the ComfyUI installation folder
system\python in the FramePack installation folderpython, but use the full path C:\path\to\python_embeded\python.exepip, but instead run C:\path\to\python_embeded\python.exe -m pippip.exe in the folder python_embeded. If you directly run pip, you're actually running a pip.exe installed somewhere else on your computercd to python_embeded, then run .\python.exe, but remember to add .\ to run an executable in the current folder. In PowerShell, without .\, you're still running a python.exe installed somewhere else on your computerC:\Python312\ or C:\Program Files\Python312\ and directly use itC:\Users\<your username>\AppData\Local\Programs\Python\Python312\ and directly use itcondavenv or virtualenvI don't recommend installing Python from Windows Store, because it's complicated to interact with a 'packaged' Windows app.
For other environment managers like poetry or uv, if you find problems, please open an issue.
Make sure what environment you're using. You can run Get-Command -All python in PowerShell (or where python in cmd) to see the installation path of Python, and python --version to see its version. If you see multiple Python installations, make sure that you install and run everything from the first one.
cp311 in its name, then it means you're not using the Python environment you thinkDon't mix two environments, unless you know them very well.
Although technically Triton can be used alone, in the following let's assume you use it with PyTorch. Each PyTorch minor version is only guaranteed to work with a specific Triton minor version:
| PyTorch | Triton |
|---|---|
| 2.4 | 3.1 |
| 2.5 | 3.1 |
| 2.6 | 3.2 |
| 2.7 | 3.3 |
| 2.8 | 3.4 |
| 2.9 | 3.5 |
| 2.10 | 3.6 |
PyTorch 2.3 and older are not supported in this repo.
If you have to use Triton 3.2 because you're using an old GPU, then you can try to use Triton 3.2 with PyTorch >= 2.7, but it's not guaranteed to always work.
You can skip this.
Since triton-windows 3.2.0.post11, a minimal CUDA toolchain is bundled in the Triton wheels, so you don't need to manually install it.
CUDA toolchain minor version bundled in each Triton minor version:
| Triton | CUDA |
|---|---|
| 3.1 .. 3.2 | 12.4 |
| 3.3 .. 3.6 | 12.8 |
See nvidia-toolchain-version.json for the detailed versions.
If you need to override the CUDA toolchain, you can set the environment variable CUDA_PATH.
CUDA 12 is required. CUDA 11 and older are not supported. Choose either of the following ways to install CUDA:
a) System-wide: Recommended for most people
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.8\include
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.8\lib\x64
PATH:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.8\binptxas --version, and it shows your CUDA version like Cuda compilation tools, release 12.8, V12.8.61, then you're doing rightb) conda: Do this only if you're already using conda
conda install -c conda-forge cuda-nvcc pytorch-gpu
pytorch channel, and it should be installed in conda-forge channelc) pip: Do this if you don't want to install too much boilerplate, and you want to contain everything in a venv, with minimal impact to the system
pip install nvidia-cuda-nvcc-cu12 nvidia-cuda-runtime-cu12
Lib\site-packages\nvidia\cuda_runtime\ in your Python installation path (or venv), and you need to add a library in it
lib into cuda_runtimeFor details about version compatibility of various pip packages and CUDA, see https://github.com/woct0rdho/triton-windows/issues/43
You can skip this.
Since triton-windows 3.2.0.post13, TinyCC is bundled in the Triton wheels, so you don't need to manually install a C compiler to use Triton. Packages that directly call triton.jit, such as SageAttention, will just work.
You still need to install a C++ compiler if you use torch.compile targeting CPU. This may happen when you use nodes like 'CompileModel' in ComfyUI. Triton does not affect how PyTorch configures the C++ compiler in this case.
If you need to override the C compiler, you can set the environment variable CC. MSVC, GCC, and Clang are supported for the JIT compilation in Triton.
If you set CC in the 'Environment Variables' window, then it should be a string, not a list. A list will implicitly add a semicolon ; at its end and cause problems.
If you don't have a C compiler, I recommend to install MSVC and Windows SDK.
Then you need to add the path containing cl.exe to the Windows PATH:
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.43.34808\bin\Hostx64\x64cl, and it shows Microsoft (R) C/C++ Optimizing Compiler ..., then you're doing rightDo this if you don't want to permanently modify the Windows PATH.
Before running Python, if you use PowerShell, run the following: (Find the ps1 file according to your installation)
&"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Launch-VsDevShell.ps1" -Arch amd64
Or if you use cmd, run the following: (This is equivalent to 'x64 Native Tools Command Prompt' from the Start menu)
"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\VsDevCmd.bat" -arch=amd64
It automatically adds the paths containing cl.exe and other relevant VS components, see https://github.com/woct0rdho/triton-windows/issues/79 . Although it does not set the environment variable CC, it sets VCINSTALLDIR, VCToolsVersion, WindowsSdkDir, WindowsSDKVersion, and Triton will recognize them.
vcredist is required (also known as 'Visual C++ Redistributable for Visual Studio 2015-2022', msvcp140.dll, vcruntime140.dll), because libtriton.pyd is compiled by MSVC. Install it from https://aka.ms/vs/17/release/vc_redist.x64.exe
Since triton-windows 3.2.0.post11, the wheels are published to https://pypi.org/project/triton-windows/ , so you don't need to manually download a wheel from GitHub releases, and pip will automatically find it.
If you've installed an old version of triton, first uninstall it:
pip uninstall triton
Now you can install triton-windows 3.6, or upgrade the already installed version. To prevent breaking with your installed PyTorch when a new version of Triton is released in future, you can limit the version to be < 3.7:
pip install -U "triton-windows<3.7"
Note again that if you're using the embeded Python, then instead of directly run pip, you need:
C:\path\to\python_embeded\python.exe -m pip install -U "triton-windows<3.7"
Or if you want triton-windows 3.2, then run:
pip install -U "triton-windows<3.3"
python_embeded in the ComfyUI installation foldersystem\python in the FramePack installation foldervenv\Scripts folderos.path.dirname(sysconfig.get_paths()["include"]) to find the Python folder, see py_include_dirinclude and libs into the Python folder to make Triton work
Lib in the Python folder, containing things like site-packages or __future__.py. You should not modify the Lib folderpython-dev on Linux, and you can obtain the two folders from nuget when bundling Python in your app, see https://github.com/comfyanonymous/ComfyUI/pull/7200 )Before using Triton in larger projects like ComfyUI, please run the following script to test if Triton itself works.
test_triton.py, then run python test_triton.pyimport torch
import triton
import triton.language as tl
@triton.jit
def add_kernel(x_ptr, y_ptr, output_ptr, n_elements, BLOCK_SIZE: tl.constexpr):
pid = tl.program_id(axis=0)
block_start = pid * BLOCK_SIZE
offsets = block_start + tl.arange(0, BLOCK_SIZE)
mask = offsets < n_elements
x = tl.load(x_ptr + offsets, mask=mask)
y = tl.load(y_ptr + offsets, mask=mask)
output = x + y
tl.store(output_ptr + offsets, output, mask=mask)
def add(x: torch.Tensor, y: torch.Tensor):
output = torch.empty_like(x)
n_elements = output.numel()
grid = lambda meta: (triton.cdiv(n_elements, meta["BLOCK_SIZE"]),)
add_kernel[grid](x, y, output, n_elements, BLOCK_SIZE=1024)
return output
a = torch.rand(3, device="cuda")
b = a + a
b_compiled = add(a, a)
print(b_compiled - b)
print("If you see tensor([0., 0., 0.], device='cuda:0'), then it works")
ModuleNotFoundError: No module named 'triton.language'; 'triton' is not a packageDon't name the test script triton.py. Also, check if there is a folder named triton in your current directory. If so, Python will think it's the 'triton' package and fail to import.
AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'This is because your setuptools is outdated. Run the following and try again:
python -m ensurepip -U
python -m pip install -U pip
python -m pip install -U setuptools
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\<your username>\\.triton'This is because of the permission settings of your user folder, see https://github.com/lllyasviel/FramePack/issues/221
ImportError: DLL load failed while importing libtritonThis is usually because your vcredist DLLs are too old.
If you're using conda, then you may try:
conda install -c conda-forge vc14_runtime
If you're not using conda, then you need to find the vcredist DLLs (vcruntime140.dll, vcruntime140_1.dll) in your Python installation folder:
python_embeded.system\python in the FramePack installation folderIf you're not sure, you can run the following in the same Python environment:
import sysconfig
print(sysconfig.get_paths())
For example, it may show {'stdlib': 'C:\\Python312\\Lib', 'platstdlib': 'C:\\tmp\\.venv\\Lib', ...}, where stdlib shows that the 'base' Python installation folder (not the venv folder) is C:\Python312\ (without the last Lib). The DLLs should be in this folder.
After finding the DLLs in the Python installation folder, you can install the latest vcredist, then copy the DLLs msvcp140.dll, vcruntime140.dll, vcruntime140_1.dll from C:\Windows\System32\ to the Python installation folder, and replace the existing ones.
You can right-click the DLL -> Properties -> Details to see its version. A new enough version, such as 14.42, is required by my Triton wheels.
ImportError: DLL load failed while importing cuda_utilsC:\Users\<your username>\.triton\cache\
C:\Users\<your username>\AppData\Local\Temp\torchinductor_<your username>\
triton.jit (which is used by packages like SageAttention), and the second folder exists only if you have used torch.compileGet-Command -All python in PowerShell (or where python in cmd) to see the installation path of Python, and python --version to see its version. If you see multiple Python installations, make sure that you install and run everything from the first oneinclude and libs from the correct version of PythonSystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formatsYou also need to delete the cache folders above.
This should not happen if you upgrade to Python 3.13, see https://github.com/python/cpython/issues/104922 . If the error still exists, you may try to debug following https://github.com/woct0rdho/triton-windows/issues/163
If the above still doesn't work, you may try:
import sys
import dlltracer
print("import torch")
with dlltracer.Trace(out=sys.stdout):
import torch
print("import triton")
with dlltracer.Trace(out=sys.stdout):
import triton
print("begin definition")
with dlltracer.Trace(out=sys.stdout):
import triton.language as tl
@triton.jit
def add_kernel(x_ptr, y_ptr, output_ptr, n_elements, BLOCK_SIZE: tl.constexpr):
pid = tl.program_id(axis=0)
block_start = pid * BLOCK_SIZE
offsets = block_start + tl.arange(0, BLOCK_SIZE)
mask = offsets < n_elements
x = tl.load(x_ptr + offsets, mask=mask)
y = tl.load(y_ptr + offsets, mask=mask)
output = x + y
tl.store(output_ptr + offsets, output, mask=mask)
def add(x: torch.Tensor, y: torch.Tensor):
output = torch.empty_like(x)
n_elements = output.numel()
grid = lambda meta: (triton.cdiv(n_elements, meta["BLOCK_SIZE"]),)
add_kernel[grid](x, y, output, n_elements, BLOCK_SIZE=1024)
return output
print("begin torch add")
with dlltracer.Trace(out=sys.stdout):
a = torch.rand(3, device="cuda")
b = a + a
print("begin jit add")
with dlltracer.Trace(out=sys.stdout):
b_compiled = add(a, a)
print(b_compiled - b)
print("If you see tensor([0., 0., 0.], device='cuda:0'), then it works")
If it shows PermissionError: [WinError 5] failed to start trace (0x00000005), then you need to make sure to run it as administrator.
(Security reminder: You don't need the administrator privilege to run Triton and other usual Python code. It's only dlltracer that needs it.)
If it shows Failed \Device\...\cuda_utils.pyd, please also:
cuda_utils.pyd at this locationcuda_utils.pyd depends on, and send a screenshot (or other related information) in the issuetorch.compile may create temp files with very long filenames, causing errors like:
File "C:\...\Lib\site-packages\torch\_inductor\runtime\triton_heuristics.py", line 537, in _precompile_config
binary = triton.compile(*compile_args, **compile_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\...\Lib\site-packages\triton\compiler\compiler.py", line 288, in compile
metadata_group[ir_filename] = fn_cache_manager.put(next_module, ir_filename)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\...\Lib\site-packages\triton\runtime\cache.py", line 122, in put
with open(temp_path, mode) as f:
^^^^^^^^^^^^^^^^^^^^^
torch._inductor.exc.InductorError: FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\<your username>\\AppData\\Local\\Temp\\torchinductor_<your username>\\triton\\0\\...LONG...FILE...NAME...'
Or errors like:
[WinError 206] The filename or extension is too long
The solution is to enable Windows' long path support. A reboot is required after the modification.
If you see errors like
torch._dynamo.exc.BackendCompilerFailed: backend='inductor' raised:
CompilationError: at 8:11:
def triton_(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
xnumel = 196608
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = tl.full([XBLOCK], True, tl.int1)
x0 = xindex
tmp0 = tl.load(in_ptr0 + (x0), None)
tmp1 = tmp0.to(tl.float32)
^
and in the full error log you find
AssertionError: fp8e4nv data type is not supported on CUDA arch < 89
then it's because in the official Triton, fp8 only works on Nvidia GPUs with sm >= 89, such as RTX 40xx and newer.
Since triton-windows 3.5.0.post21, fp8 on RTX 30xx is supported.
os.renameIf you see errors like
FileExistsError: [WinError 183] Cannot create a file when that file already exists: ...
then you need: https://github.com/pytorch/pytorch/issues/138211
This has been fixed since PyTorch 2.6 .
If you're using ComfyUI, the model is compiled, and you see error messages like
ValueError: Pointer argument (at 0) cannot be accessed from Triton (cpu tensor?)
then you may use --gpu-only when launching ComfyUI to disable model offloading, see https://github.com/woct0rdho/triton-windows/issues/61
triton.ops was removed in Triton 3.1, and this is because some of your Python package is outdated (most likely bitsandbytes), see https://github.com/woct0rdho/triton-windows/issues/65
Exception Code: 0x80000003If you see Exception Code: 0x80000003 in libtriton.pyd in a function like registerImplicitTypeID, that may not actually be an issue in Triton, but a CUDA error happened earlier, see https://github.com/thu-ml/SageAttention/issues/270 . If you want to help debug, you may set the environment variable CUDA_LAUNCH_BLOCKING=1 and run again.
See BUILD.md. This is for developers.
(top 30 of 394)
MLIR
39.9%
Python
30.8%
C++
28.8%