aboutsummaryrefslogtreecommitdiff
path: root/modules/devices.py
diff options
context:
space:
mode:
Diffstat (limited to 'modules/devices.py')
-rw-r--r--modules/devices.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/modules/devices.py b/modules/devices.py
new file mode 100644
index 00000000..25008a04
--- /dev/null
+++ b/modules/devices.py
@@ -0,0 +1,12 @@
+import torch
+
+
+# has_mps is only available in nightly pytorch (for now), `getattr` for compatibility
+has_mps = getattr(torch, 'has_mps', False)
+
+def get_optimal_device():
+ if torch.cuda.is_available():
+ return torch.device("cuda")
+ if has_mps:
+ return torch.device("mps")
+ return torch.device("cpu")