Download pixelart/device.py from azygod/pixelart-50m: direct link, hf CLI and curl.
- Browser
- Download file 521 Bytes
-
https://huggingface.co/azygod/pixelart-50m/resolve/main/pixelart/device.py
- Command line
-
hf download hf://azygod/pixelart-50m/pixelart/device.py
-
curl -L -o device.py https://huggingface.co/azygod/pixelart-50m/resolve/main/pixelart/device.py
521 Bytes
| """Pick the fastest available torch device: NVIDIA (cuda) > Apple Silicon (mps) > cpu.""" | |
| from __future__ import annotations | |
| import torch | |
| def pick_device() -> torch.device: | |
| if torch.cuda.is_available(): | |
| return torch.device("cuda") | |
| if torch.backends.mps.is_available(): | |
| return torch.device("mps") | |
| return torch.device("cpu") | |
| def synchronize(dev: torch.device) -> None: | |
| if dev.type == "cuda": | |
| torch.cuda.synchronize() | |
| elif dev.type == "mps": | |
| torch.mps.synchronize() | |