Spaces:
Sleeping
Sleeping
Download utils.py from gaurannggg7/Signlink: direct link, hf CLI and curl.
- Browser
- Download file 630 Bytes
-
https://huggingface.co/spaces/gaurannggg7/Signlink/resolve/main/utils.py
- Command line
-
hf download hf://spaces/gaurannggg7/Signlink/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/gaurannggg7/Signlink/resolve/main/utils.py
630 Bytes
| import os | |
| import torch | |
| def get_best_device() -> torch.device: | |
| """ | |
| Return the fastest available device in this order: | |
| 1) TPU (if on Colab with TPU runtime) | |
| 2) CUDA GPU | |
| 3) Apple MPS | |
| 4) CPU | |
| """ | |
| if 'COLAB_TPU_ADDR' in os.environ: | |
| try: | |
| import torch_xla.core.xla_model as xm | |
| return xm.xla_device() | |
| except ImportError: | |
| pass | |
| if torch.cuda.is_available(): | |
| return torch.device('cuda') | |
| if getattr(torch.backends, 'mps', None) and torch.backends.mps.is_available(): | |
| return torch.device('mps') | |
| return torch.device('cpu') | |