{"id":24721,"library":"torch-directml","title":"PyTorch DirectML","description":"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.","status":"active","version":"0.2.5.dev240914","language":"python","source_language":"en","source_url":"https://github.com/microsoft/DirectML","tags":["pytorch","directml","gpu-acceleration","windows","machine-learning"],"install":[{"cmd":"pip install torch-directml","lang":"bash","label":"Install latest preview"}],"dependencies":[{"reason":"Required; torch-directml is a backend plugin for PyTorch.","package":"torch","optional":false}],"imports":[{"note":"The correct import is torch_directml, not directml.","wrong":"import directml","symbol":"torch_directml","correct":"import torch_directml"}],"quickstart":{"code":"import torch\nimport torch_directml\ndevice = torch_directml.device()\ntensor = torch.tensor([1.0, 2.0, 3.0]).to(device)\nprint(tensor.device)","lang":"python","description":"Basic setup: import torch_directml, get the default DirectML device, move a tensor to it."},"warnings":[{"fix":"Use `torch_directml.device()` or `torch_directml.device(torch_directml.device_count() - 1)` for specific devices.","message":"torch-directml does not support CUDA APIs; use torch_directml.device() instead of torch.device('cuda').","severity":"gotcha","affected_versions":"all"},{"fix":"Use `import torch_directml` instead of `import dml`.","message":"The `dml` module alias is deprecated; always import `torch_directml`.","severity":"deprecated","affected_versions":"<=0.2.4"},{"fix":"Run on Windows 10/11 with DirectX 12 capable GPU.","message":"Only Windows is supported; Linux/WSL is not supported for torch-directml (separate package tensorflow-directml may work for TF).","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run `pip install torch-directml` and ensure you are using the correct Python environment.","cause":"torch-directml is not installed or installed in wrong environment.","error":"ModuleNotFoundError: No module named 'torch_directml'"},{"fix":"Ensure Windows 10/11, DirectX 12 feature level 12_0, and latest GPU drivers are installed.","cause":"No compatible DirectX 12 GPU is available or drivers are outdated.","error":"RuntimeError: DirectML device not found"},{"fix":"Upgrade to torch-directml >=0.2.4: `pip install --upgrade torch-directml`.","cause":"Using an older version of torch-directml that does not have device_count.","error":"AttributeError: module 'torch_directml' has no attribute 'device_count'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}