def get_map_location(target_device, fallback_device='cpu'):
    """Determine the location to map loaded data (e.g., weights)
    for a given target device (e.g. 'cuda').
    """
    map_location = torch.device(target_device)

    # The user wants to use CUDA but there is no CUDA device
    # available, thus fall back to CPU.
    if map_location.type == 'cuda' and not torch.cuda.is_available():
        warnings.warn(
            'Requested to load data to CUDA but no CUDA devices '
            'are available. Loading on device "{}" instead.'.format(
                fallback_device,
            ), DeviceWarning)
        map_location = torch.device(fallback_device)
    return map_location
def get_map_location ( target_device , fallback_device = 'cpu' ) : map_location = torch . device ( target_device ) if map_location . type == 'cuda' and not torch . cuda . is_available ( ) : warnings . warn ( 'Requested to load data to CUDA but no CUDA devices ' 'are available. Loading on device "{}" instead.' . format ( fallback_device , ) , DeviceWarning ) map_location = torch . device ( fallback_device ) return map_location
Determine the location to map loaded data (e.g., weights)
    for a given target device (e.g. 'cuda').