ComfyUI --directml: No module named 'torch_directml' (fix)

ModuleNotFoundError: No module named 'torch_directml' appears when ComfyUI is started with --directml and the torch-directml package is missing. We reproduced it on ComfyUI v0.37.0 and checked what installing the package would do first.

1. The error

ComfyUI v0.37.0 started with the DirectML flag in a venv without the torch-directml package:

python main.py --directml
[INFO] Checkpoint files will always be loaded safely.
[WARNING] WARNING: torch-directml barely works, is very slow, has not been updated in over 1 year and might be removed soon, please don't use it, there are better options.
Traceback (most recent call last):
  File "/path/to/ComfyUI/main.py", line 251, in <module>
    import execution
  File "/path/to/ComfyUI/execution.py", line 17, in <module>
    import comfy.model_management
  File "/path/to/ComfyUI/comfy/model_management.py", line 114, in <module>
    import torch_directml
ModuleNotFoundError: No module named 'torch_directml'

ComfyUI exited with code 1. --directml makes comfy/model_management.py run import torch_directml (line 114) at startup, and that package is not in ComfyUI's requirements.txt, so a normal install never has it. Note the warning ComfyUI itself prints just before the traceback: it says torch-directml barely works, is very slow and might be removed.

2. Before you pip install it: it downgrades torch

The newest torch-directml on PyPI is 0.2.5.dev240914 (uploaded 2024-09-15). It pins torch==2.4.1 and torchvision==0.19.1. A dry run in our venv with torch 2.9.0:

pip install --dry-run torch-directml
Using Python 3.11.17 environment at: /path/to/venv
Resolved 26 packages in 211ms
Would download 6 packages
Would uninstall 3 packages
Would install 16 packages
 + nvidia-cublas-cu12==12.1.3.1
 + nvidia-cuda-cupti-cu12==12.1.105
 + nvidia-cuda-nvrtc-cu12==12.1.105
 + nvidia-cuda-runtime-cu12==12.1.105
 + nvidia-cudnn-cu12==9.1.0.70
 + nvidia-cufft-cu12==11.0.2.54
 + nvidia-curand-cu12==10.3.2.106
 + nvidia-cusolver-cu12==11.4.5.107
 + nvidia-cusparse-cu12==12.1.0.106
 + nvidia-nccl-cu12==2.20.5
 + nvidia-nvjitlink-cu12==12.9.86
 + nvidia-nvtx-cu12==12.1.105
 - torch==2.9.0+cpu
 + torch==2.4.1
 + torch-directml==0.2.5.dev240914
 - torchvision==0.24.0+cpu
 + torchvision==0.19.1
 - triton==3.8.0
 + triton==3.0.0

(Output from uv pip install --dry-run.) Installing it would replace your torch with 2.4.1, which can break custom nodes that need a newer torch. It also only has wheels for CPython 3.8 to 3.12 (Windows and manylinux x86_64). On Python 3.13, as used by recent portable builds:

Using Python 3.11.17 environment at: /path/to/venv
error: No solution found when resolving dependencies
  cause: Because all versions of torch-directml have no wheels with a matching Python ABI tag (e.g., `cp313`) and you require torch-directml, we can conclude that your requirements are unsatisfiable.

hint: You require CPython 3.13 (`cp313`), but we only found wheels for `torch-directml` (v0.2.5.dev240914) with the following Python ABI tags: `cp38`, `cp39`, `cp310`, `cp311`, `cp312`

3. Fix

Related: ComfyUI: No module named 'torchsde' · ComfyUI: No module named 'yaml' · ComfyUI: sageattention No module named 'triton'

Frequently asked questions

Does torch-directml work with Python 3.13?

No. Its latest release (0.2.5.dev240914) only has wheels for CPython 3.8 to 3.12, so pip finds no matching distribution on 3.13.

Will installing torch-directml change my torch version?

Yes. It pins torch==2.4.1 and torchvision==0.19.1; our dry run would have replaced torch 2.9.0.

Written with AI assistance. Measured on 2026-10-24 on Linux, CPython 3.11.17: ComfyUI v0.37.0 with torch 2.9.0+cpu, main.py --directml without torch-directml, dry-run installs of torch-directml 0.2.5.dev240914 (Python 3.11, and 3.13 for Windows). DirectML itself not tested. Output pasted unedited except shortened paths. PlainTables is our extension; ComfyUI and torch-directml are free.