import torch accelerator = torch.accelerator.current_accelerator(check_available=True) device = accelerator or torch.device("cpu")