Add --use-directml flag and fix crash when no NVIDIA GPU is present

- Add `--use-directml` as an alias for `--directml` in backend/args.py.
  Previously the flag was silently ignored by parse_known_args(), leaving
  directml_enabled=False and causing the code to fall through to a CUDA
  call that crashed with "Found no NVIDIA driver on your system."
- In memory_management.py, treat --use-directml the same as --directml
  (defaulting to device index -1).
- Add a torch.cuda.is_available() guard in get_torch_device() before
  calling torch.cuda.current_device(), falling back to CPU so the
  application does not crash on non-NVIDIA systems.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Peter Pfadenhauer 2026-02-21 21:16:10 +01:00
parent dfdcbab685
commit c187160fd1
2 changed files with 7 additions and 2 deletions

View File

@ -39,6 +39,7 @@ upcast.add_argument("--disable-attention-upcast", action="store_true")
parser.add_argument("--disable-xformers", action="store_true")
parser.add_argument("--directml", type=int, nargs="?", metavar="DIRECTML_DEVICE", const=-1)
parser.add_argument("--use-directml", action="store_true", dest="use_directml")
parser.add_argument("--disable-ipex-hijack", action="store_true")
vram_group = parser.add_mutually_exclusive_group()

View File

@ -44,7 +44,9 @@ if args.pytorch_deterministic:
torch.use_deterministic_algorithms(True, warn_only=True)
directml_enabled = False
if args.directml is not None:
if args.directml is not None or getattr(args, 'use_directml', False):
if args.directml is None:
args.directml = -1
import torch_directml
directml_enabled = True
@ -96,8 +98,10 @@ def get_torch_device():
else:
if is_intel_xpu():
return torch.device("xpu", torch.xpu.current_device())
else:
elif torch.cuda.is_available():
return torch.device(torch.cuda.current_device())
else:
return torch.device("cpu")
def get_total_memory(dev=None, torch_total_too=False):