import torch
from pathlib import Path
from typing import Dict
from typing import Any


def load_checkpoint(path_to_checkpoint: Path, use_gpu: bool = True) -> Dict[str, Any]:
    """
    Loads a Torch checkpoint from the given file. If use_gpu==False, map all parameters to the GPU, otherwise
    left the device of all parameters unchanged.
    """
    map_location = None if use_gpu else 'cpu'
    checkpoint = torch.load(str(path_to_checkpoint), map_location=map_location)
    return checkpoint