mirror of
https://github.com/lllyasviel/stable-diffusion-webui-forge.git
synced 2026-06-04 21:05:48 +08:00
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:
parent
dfdcbab685
commit
c187160fd1
@ -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()
|
||||
|
||||
@ -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):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user