aboutsummaryrefslogtreecommitdiffstats
path: root/modules/devices.py
blob: 30d30b99c228315eaac9c777015c8e2b91ad3e2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import torch

# has_mps is only available in nightly pytorch (for now), `getattr` for compatibility
has_mps = getattr(torch, 'has_mps', False)

cpu = torch.device("cpu")


def get_optimal_device():
    if torch.cuda.is_available():
        return torch.device("cuda")

    if has_mps:
        return torch.device("mps")

    return cpu