diff options
author | Abdullah Barhoum <ka70911@gmail.com> | 2022-09-11 05:11:27 +0000 |
---|---|---|
committer | AUTOMATIC1111 <16777216c@gmail.com> | 2022-09-11 06:49:43 +0000 |
commit | b5d1af11b7dc718d4d91d379c75e46f4bd2e2fe6 (patch) | |
tree | ac8bf9b5aebe5d95da9c91fe45b7cc19e5d845ea /modules/devices.py | |
parent | 065e310a3f4efdcdc206cfb70656108c70bc1c6d (diff) | |
download | stable-diffusion-webui-gfx803-b5d1af11b7dc718d4d91d379c75e46f4bd2e2fe6.tar.gz stable-diffusion-webui-gfx803-b5d1af11b7dc718d4d91d379c75e46f4bd2e2fe6.tar.bz2 stable-diffusion-webui-gfx803-b5d1af11b7dc718d4d91d379c75e46f4bd2e2fe6.zip |
Modular device management
Diffstat (limited to 'modules/devices.py')
-rw-r--r-- | modules/devices.py | 12 |
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") |