Device Utilities
Device resolution utilities for PyTorch training and inference.
Provides a single entry point for resolving user-requested device strings
(auto, cpu, cuda, mps) into concrete PyTorch device identifiers,
with availability checks for CUDA and Apple Metal Performance Shaders (MPS).
- src.utils.device.is_mps_available() bool[source]
Check whether Apple Metal Performance Shaders (MPS) backend is available.
- Returns:
Trueiftorch.backends.mpsis available and built,Falseotherwise.
- src.utils.device.resolve_torch_device(requested: str = 'auto') str[source]
Resolve a user-requested device string to a concrete PyTorch device.
- Parameters:
requested – One of
"auto","cpu","cuda", or"mps"."auto"selects CUDA if available, then MPS, falling back to CPU.- Returns:
The resolved device string (
"cuda","mps", or"cpu").- Raises:
ValueError – If
requestedis not a supported choice, or if the requested device is not available on the current machine.