import torch


def move_to_device(data, device):
    """
    Recursively move a tensor or a collection of tensors to the specific
    device.

    Args:
        data (dict | list | :obj:`torch.Tensor`): The tensor or collection of
            tensors to move.
        device (:obj:`torch.device` | str): The destination device.

    Returns:
        dict | list | :obj:`torch.Tensor`: The moved tensor or collection of \
            tensors.
    """
    if isinstance(data, dict):
        return {k: move_to_device(v, device) for k, v in data.items()}
    elif isinstance(data, (list, tuple)):
        return type(data)([move_to_device(d, device) for d in data])
    elif torch.is_tensor(data):
        return data.to(device)
    else:
        return data