We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7ba3923 commit 76ab31eCopy full SHA for 76ab31e
modules/devices.py
@@ -3,8 +3,15 @@
3
import torch
4
from modules import errors
5
6
-# has_mps is only available in nightly pytorch (for now), `getattr` for compatibility
7
-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
8
+def has_mps() -> bool:
9
+ if getattr(torch, 'has_mps', False): return False
10
+ try:
11
+ torch.zeros(1).to(torch.device("mps"))
12
+ return True
13
+ except Exception:
14
+ return False
15
16
cpu = torch.device("cpu")
17
@@ -25,7 +32,7 @@ def get_optimal_device():
25
32
else:
26
33
return torch.device("cuda")
27
34
28
- if has_mps:
35
+ if has_mps():
29
36
return torch.device("mps")
30
37
31
38
return cpu
0 commit comments