diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2023-07-08 11:19:34 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-08 11:19:34 +0000 |
commit | fc049a2fd3fe4a7d5859ae004d81f30e59f42d06 (patch) | |
tree | 15af914a7967a317abd7d9e0975dc4b2c17376cd /modules/mac_specific.py | |
parent | 522a8b9f629940a205812b5b023f25c051f3c8d8 (diff) | |
parent | ae74b44c69a40c3b2f2a91f5ee4160e6d8bbd31e (diff) | |
download | stable-diffusion-webui-gfx803-fc049a2fd3fe4a7d5859ae004d81f30e59f42d06.tar.gz stable-diffusion-webui-gfx803-fc049a2fd3fe4a7d5859ae004d81f30e59f42d06.tar.bz2 stable-diffusion-webui-gfx803-fc049a2fd3fe4a7d5859ae004d81f30e59f42d06.zip |
Merge branch 'dev' into better-status-reporting-1
Diffstat (limited to 'modules/mac_specific.py')
-rw-r--r-- | modules/mac_specific.py | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/modules/mac_specific.py b/modules/mac_specific.py index d74c6b95..735847f5 100644 --- a/modules/mac_specific.py +++ b/modules/mac_specific.py @@ -4,16 +4,21 @@ from modules.sd_hijack_utils import CondFunc from packaging import version -# has_mps is only available in nightly pytorch (for now) and macOS 12.3+. -# check `getattr` and try it for compatibility +# before torch version 1.13, has_mps is only available in nightly pytorch and macOS 12.3+, +# use check `getattr` and try it for compatibility. +# in torch version 1.13, backends.mps.is_available() and backends.mps.is_built() are introduced in to check mps availabilty, +# since torch 2.0.1+ nightly build, getattr(torch, 'has_mps', False) was deprecated, see https://github.com/pytorch/pytorch/pull/103279 def check_for_mps() -> bool: - if not getattr(torch, 'has_mps', False): - return False - try: - torch.zeros(1).to(torch.device("mps")) - return True - except Exception: - return False + if version.parse(torch.__version__) <= version.parse("2.0.1"): + if not getattr(torch, 'has_mps', False): + return False + try: + torch.zeros(1).to(torch.device("mps")) + return True + except Exception: + return False + else: + return torch.backends.mps.is_available() and torch.backends.mps.is_built() has_mps = check_for_mps() |