<< Back to posts
Torch - Get device across CPU / GPU / MPS
To check if you can run on CUDA (Nvidia GPU), MPS (Mac), or CPU:
import torch
device: str = 'cuda' if torch.cuda.is_available() else ('mps' if torch.backends.mps.is_available() else 'cpu')