"""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()