dl-from-scratch / utils /device.py
yusiwen's picture
refactor: extract device detection to utils/device.py (CUDA→MPS→CPU)
e9956a9 unverified
Raw
History Blame Contribute Delete
294 Bytes
import torch
def get_device():
"""Auto-detect best available device: CUDA → MPS → CPU."""
if torch.cuda.is_available():
return torch.device("cuda")
elif torch.backends.mps.is_available():
return torch.device("mps")
else:
return torch.device("cpu")