def load_checkpoint_to_cpu(path, arg_overrides=None):
    """Loads a checkpoint to CPU (with upgrading for backward compatibility)."""
    try:
        from fairseq.fb_pathmgr import fb_pathmgr

        with fb_pathmgr.open(path, "rb") as f:
            state = torch.load(
                f, map_location=lambda s, l: default_restore_location(s, "cpu")
            )
    except (ModuleNotFoundError, ImportError):
        # if path manager not found, continue with local file.
        state = torch.load(
            path, map_location=lambda s, l: default_restore_location(s, "cpu")
        )
    args = state["args"]
    if arg_overrides is not None:
        for arg_name, arg_val in arg_overrides.items():
            setattr(args, arg_name, arg_val)
    state = _upgrade_state_dict(state)
    return state
Loads a checkpoint to CPU (with upgrading for backward compatibility).
infoxlm/fairseq/fairseq/checkpoint_utils.py