def restore(self, target,
                mode,
                reload_metadata=True,
                check_ckpt_exists=False,
                restore_folder=None):
        """
        Args:
            target: can be one of the following semantics
              - int: 0 for the last (or best), 1 for the second last (or best), etc.
              - global steps of the ckpt file, the suffix string right before ".ckpt"
            mode: "best" or "history", which group to restore
            reload_metadata: overwrite self.metadata with the metadata.yml file content
            check_ckpt_exists: raise FileNotFoundError if the checkpoint target doesn't exist
            restore_folder: if None, use self.folder, else specify a folder to restore from
                if not None, reload_metadata will be forced to True

        Returns:
            - full ckpt file path if successfully restored
            - None otherwise

        Warnings:
            to restore attrs that point to pytorch Module, you must initialize
            the Module class first, because the checkpoint only saves the
            state_dict, not how to construct your Module
        """
        assert mode in ['best', 'history']
        with self._change_folder(restore_folder):
            if reload_metadata or restore_folder:
                self._load_metadata()
            self._check_version()
            meta = self.metadata
            if isinstance(target, int):
                assert target >= 0, \
                    'target int should start from 0 for the last or best'
                try:
                    if mode == 'best':
                        ckpt_file = meta.best_ckpt_files[target]
                    else:
                        ckpt_file = meta.history_ckpt_files[target]
                except IndexError:
                    if check_ckpt_exists:
                        raise FileNotFoundError(
                            '{} [{}] ckpt file missing'
                            .format(mode.capitalize(), target))
                    else:
                        ckpt_file = '__DOES_NOT_EXIST__'
            else:
                assert '.ckpt' not in target, 'use restore_full_path() instead'
                if mode == 'best':
                    ckpt_file = self.ckpt_name('best-{}'.format(target))
                else:
                    ckpt_file = self.ckpt_name(target)
            return self._restore(ckpt_file, check_ckpt_exists)

        Args:
            target: can be one of the following semantics
              - int: 0 for the last (or best), 1 for the second last (or best), etc.
              - global steps of the ckpt file, the suffix string right before ".ckpt"
            mode: "best" or "history", which group to restore
            reload_metadata: overwrite self.metadata with the metadata.yml file content
            check_ckpt_exists: raise FileNotFoundError if the checkpoint target doesn't exist
            restore_folder: if None, use self.folder, else specify a folder to restore from
                if not None, reload_metadata will be forced to True

        Returns:
            - full ckpt file path if successfully restored
            - None otherwise

        Warnings:
            to restore attrs that point to pytorch Module, you must initialize
            the Module class first, because the checkpoint only saves the
            state_dict, not how to construct your Module
        
surreal/utils/checkpoint.py