diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2022-11-12 06:51:33 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-12 06:51:33 +0000 |
commit | 526f0aa5569241aabf276a83af1a7216e825c6cc (patch) | |
tree | 44f72af489dd12770d0e1672fc532e1bbd040c96 /modules/devices.py | |
parent | 7ba3923d5b494b7756d0b12f33acb3716d830b9a (diff) | |
parent | 1130d5df669911a5c67696be90bccca3ecf5f487 (diff) | |
download | stable-diffusion-webui-gfx803-526f0aa5569241aabf276a83af1a7216e825c6cc.tar.gz stable-diffusion-webui-gfx803-526f0aa5569241aabf276a83af1a7216e825c6cc.tar.bz2 stable-diffusion-webui-gfx803-526f0aa5569241aabf276a83af1a7216e825c6cc.zip |
Merge pull request #4623 from fumiama/mps
Fix wrong mps fallback
Diffstat (limited to 'modules/devices.py')
-rw-r--r-- | modules/devices.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/modules/devices.py b/modules/devices.py index 7511e1dc..bd3e4ffb 100644 --- a/modules/devices.py +++ b/modules/devices.py @@ -3,8 +3,15 @@ import contextlib import torch from modules import errors -# has_mps is only available in nightly pytorch (for now), `getattr` for compatibility -has_mps = getattr(torch, 'has_mps', False) +# has_mps is only available in nightly pytorch (for now) and MasOS 12.3+. +# check `getattr` and try it for compatibility +def has_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 cpu = torch.device("cpu") @@ -25,7 +32,7 @@ def get_optimal_device(): else: return torch.device("cuda") - if has_mps: + if has_mps(): return torch.device("mps") return cpu |