This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def torch_device(priority=['xla', 'cuda', 'mps', 'xpu', 'cpu']): | |
import torch | |
t = torch.Tensor([0]) | |
for device in map(torch.device, priority): | |
try: | |
t.to(device) | |
return device | |
except (RuntimeError, AssertionError): | |
pass |