diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2024-01-31 19:39:29 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-31 19:39:29 +0000 |
commit | 96b550430a986fa49670249aabdd42cd182fb6c8 (patch) | |
tree | 44cbaa680fd3afeea5799fa75af4d52872f646ba /modules/devices.py | |
parent | ce168ab5dbc8b54b7245f352a2eaa55a37019b91 (diff) | |
parent | cc3f604310458eed7d26456c1b3934d582283ffe (diff) | |
download | stable-diffusion-webui-gfx803-96b550430a986fa49670249aabdd42cd182fb6c8.tar.gz stable-diffusion-webui-gfx803-96b550430a986fa49670249aabdd42cd182fb6c8.tar.bz2 stable-diffusion-webui-gfx803-96b550430a986fa49670249aabdd42cd182fb6c8.zip |
Merge pull request #14801 from wangshuai09/npu_support
Add NPU Support
Diffstat (limited to 'modules/devices.py')
-rw-r--r-- | modules/devices.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/modules/devices.py b/modules/devices.py index 8f49f7a4..28c0c54d 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, npu_specific if sys.platform == "darwin": from modules import mac_specific @@ -57,6 +57,9 @@ def get_optimal_device_name(): if has_xpu(): return xpu_specific.get_xpu_device_string() + if npu_specific.has_npu: + return npu_specific.get_npu_device_string() + return "cpu" @@ -84,6 +87,16 @@ def torch_gc(): if has_xpu(): xpu_specific.torch_xpu_gc() + if npu_specific.has_npu: + torch_npu_set_device() + npu_specific.torch_npu_gc() + + +def torch_npu_set_device(): + # Work around due to bug in torch_npu, revert me after fixed, @see https://gitee.com/ascend/pytorch/issues/I8KECW?from=project-issue + if npu_specific.has_npu: + torch.npu.set_device(0) + def enable_tf32(): if torch.cuda.is_available(): @@ -256,4 +269,3 @@ def first_time_calculation(): x = torch.zeros((1, 1, 3, 3)).to(device, dtype) conv2d = torch.nn.Conv2d(1, 1, (3, 3)).to(device, dtype) conv2d(x) - |