PyTorch DirectML
raw JSON → 0.2.5.dev240914 verified Fri May 01 auth: no python
Provides a DirectML backend for hardware acceleration in PyTorch, enabling GPU acceleration on Windows devices with DirectX 12 compatible GPUs (including AMD, Intel, and NVIDIA). Current version is 0.2.5.dev240914, with preview releases following a monthly cadence.
pip install torch-directml Common errors
error ModuleNotFoundError: No module named 'torch_directml' ↓
cause torch-directml is not installed or installed in wrong environment.
fix
Run
pip install torch-directml and ensure you are using the correct Python environment. error RuntimeError: DirectML device not found ↓
cause No compatible DirectX 12 GPU is available or drivers are outdated.
fix
Ensure Windows 10/11, DirectX 12 feature level 12_0, and latest GPU drivers are installed.
error AttributeError: module 'torch_directml' has no attribute 'device_count' ↓
cause Using an older version of torch-directml that does not have device_count.
fix
Upgrade to torch-directml >=0.2.4:
pip install --upgrade torch-directml. Warnings
gotcha torch-directml does not support CUDA APIs; use torch_directml.device() instead of torch.device('cuda'). ↓
fix Use `torch_directml.device()` or `torch_directml.device(torch_directml.device_count() - 1)` for specific devices.
deprecated The `dml` module alias is deprecated; always import `torch_directml`. ↓
fix Use `import torch_directml` instead of `import dml`.
gotcha Only Windows is supported; Linux/WSL is not supported for torch-directml (separate package tensorflow-directml may work for TF). ↓
fix Run on Windows 10/11 with DirectX 12 capable GPU.
Imports
- torch_directml wrong
import directmlcorrectimport torch_directml
Quickstart
import torch
import torch_directml
device = torch_directml.device()
tensor = torch.tensor([1.0, 2.0, 3.0]).to(device)
print(tensor.device)