import torch


def int_to_device(device: int) -> torch.device:
    """
    Return torch.device based on device index.
    If -1 or less return torch.cpu else torch.cuda.
    """
    if isinstance(device, torch.device):
        return device
    if device < 0:
        return torch.device("cpu")
    return torch.device(device)