aboutsummaryrefslogtreecommitdiffstats
path: root/modules/devices.py
diff options
context:
space:
mode:
authorNuullll <vfirst218@gmail.com>2023-11-10 03:06:26 +0000
committerNuullll <vfirst218@gmail.com>2023-11-30 12:22:46 +0000
commit8b40f475a31109cc6ecbdc0d14a0cee9e0303291 (patch)
tree31932dc6e586bbddfb57477468f6586438f83312 /modules/devices.py
parentf0f100e67b78f686dc73cf3c8cad422e45cc9b8a (diff)
downloadstable-diffusion-webui-gfx803-8b40f475a31109cc6ecbdc0d14a0cee9e0303291.tar.gz
stable-diffusion-webui-gfx803-8b40f475a31109cc6ecbdc0d14a0cee9e0303291.tar.bz2
stable-diffusion-webui-gfx803-8b40f475a31109cc6ecbdc0d14a0cee9e0303291.zip
Initial IPEX support
Diffstat (limited to 'modules/devices.py')
-rw-r--r--modules/devices.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/modules/devices.py b/modules/devices.py
index 1d4eb563..be599736 100644
--- a/modules/devices.py
+++ b/modules/devices.py
@@ -3,7 +3,7 @@ import contextlib
from functools import lru_cache
import torch
-from modules import errors, shared
+from modules import errors, shared, xpu_specific
if sys.platform == "darwin":
from modules import mac_specific
@@ -30,6 +30,9 @@ def get_optimal_device_name():
if has_mps():
return "mps"
+ if xpu_specific.has_ipex:
+ return xpu_specific.get_xpu_device_string()
+
return "cpu"
@@ -100,11 +103,15 @@ def autocast(disable=False):
if dtype == torch.float32 or shared.cmd_opts.precision == "full":
return contextlib.nullcontext()
+ if xpu_specific.has_xpu:
+ return torch.autocast("xpu")
+
return torch.autocast("cuda")
def without_autocast(disable=False):
- return torch.autocast("cuda", enabled=False) if torch.is_autocast_enabled() and not disable else contextlib.nullcontext()
+ device_type = "xpu" if xpu_specific.has_xpu else "cuda"
+ return torch.autocast(device_type, enabled=False) if torch.is_autocast_enabled() and not disable else contextlib.nullcontext()
class NansException(Exception):