Download device.py from j-llm/jevlite: direct link, hf CLI and curl.
- Browser
- Download file 558 Bytes
-
https://huggingface.co/j-llm/jevlite/resolve/main/device.py
- Command line
-
hf download hf://j-llm/jevlite/device.py
-
curl -L -o device.py https://huggingface.co/j-llm/jevlite/resolve/main/device.py
558 Bytes
| """Shared device selection: cuda > mps > cpu. | |
| Keeping the priority order in one place means the Apple Silicon path never | |
| leaks platform-specific branches into the training and eval scripts - they all | |
| just ask for the best available device. AMP/GradScaler stay CUDA-only at the | |
| call sites that use them; MPS runs the same code in fp32. | |
| """ | |
| import torch | |
| def pick_device(prefer=None): | |
| if prefer: | |
| return prefer | |
| if torch.cuda.is_available(): | |
| return "cuda" | |
| if torch.backends.mps.is_available(): | |
| return "mps" | |
| return "cpu" | |