`--directml` crashes with a native DLL error when torch-directml is missing or incompatible
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 75/100
Research direction
Start in comfy/model_management.py at the torch_directml import and device selection described in the issue. Check how the default CUDA/CPU device is chosen and how import failures are handled. Run ComfyUI with --directml both with torch-directml unavailable and with a compatible installation; done means an import failure warns and falls back, while a working DirectML installation still selects DirectML.
Written by the indexing model from the issue text.
Description
Problem
Launching ComfyUI with --directml when torch-directml is missing or incompatible crashes the whole process with a native DLL exception instead of a clear Python error.
With an incompatible build installed (e.g. torch-directml 0.2.3.dev240715 built for torch 2.3.1, on torch 2.9.1):
File "comfy\model_management.py", line 114, in <module>
import torch_directml
ImportError: DLL load failed while importing torch_directml_native: The specified procedure could not be found.
Windows fatal exception: code 0xc0000139
With the package removed entirely:
ModuleNotFoundError: No module named 'torch_directml'
In both cases there is no fallback, so the app exits with code 1.
Why this happens
Portable distributions commonly ship torch-directml pinned to an old torch version. When the user upgrades torch, a launcher may still pass --directml, and model_management.py imports the stale native module unconditionally.
Suggestion
Wrap the import in try/except ImportError and fall back to the default device (CUDA/CPU) with a warning, so the app stays launchable:
if args.directml is not None:
logging.warning("WARNING: torch-directml barely works, ...")
try:
import torch_directml
except ImportError:
logging.warning("torch_directml is not installed, ignoring --directml and falling back to the default device.")
else:
directml_enabled = True
device_index = args.directml
...
I verified this locally: with the fallback in place, main.py --directml prints the warning and starts normally on CUDA.
Environment
- ComfyUI 0.45.2
- Python 3.11.9, Windows 11
- torch 2.9.1+cu128
- torch-directml 0.2.3.dev240715 (built against torch 2.3.1)
- Dominant language
- Python
- Stars
- 146k
- Forks
- 17.4k
- Avg merge
- 19h 44m
- Merged PRs (30d)
- 178
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Comfy-Org/ComfyUI
-
ROCm gfx1100: contiguous-k/v SDPA workaround is gfx1151-only, MiniMax H3 sampling 2.2x slower on RX 7900 XTXPossibly taken @TwelveNights claimed this 3 days ago. OpenPotential Bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Sub-quadratic attention is ~10x slower on long sequences on RDNA2 (gfx1030) because the key passed to bmm is non-contiguousPossibly taken @KornienkoDev claimed this 3 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
MoGe-3 output is nondeterministic on CUDA: sparse_pool3d_mean sums with float index_add_ (atomics)Possibly taken @potoior claimed this 9 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Comfy-Org/ComfyUI#17498 · 1 comment ·
Maintainers usually reply within 1 day
-
TRELLIS.2 texture bake fails under --bf16-vae: BakeTextureFromVoxel 'Got unsupported ScalarType BFloat16'Possibly taken @Shubham-Padkonde claimed this 10 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
Fix: Windows access violation during startup when loading comfy_api_nodes (pydantic-core GC issue)Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
All issues in Comfy-Org/ComfyUI
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
OCA/account-invoicing#2529 ·
Maintainers usually reply within 1 day
-
area/ci
Difficulty 1/5 Under an hour Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
ImageGen generate-batch aborts valid JSONL jobs containing a Unicode line separator in poster textOpenbug imagen skills
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Email validation accepts a trailing newlinePossibly taken @marcello-pichini claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day