from typing import Tuple
import torch


def set_device(use_gpu: bool) -> Tuple[torch.device, bool]:
    """Sets device and pin_memory parameters.

    Args:
        use_gpu (bool)

    Returns:
        device (torch.device): cpu or cuda
        pin_memory (bool): whether using pin_memory.
                           True if the model is trained on GPU.
    """
    if use_gpu and torch.cuda.is_available():
        device = torch.device("cuda")
        pin_memory = True
    else:
        device = torch.device("cpu")
        pin_memory = False
    return device, pin_memory