in mmf/utils/checkpoint.py [0:0]
def load_state_dict(self):
ckpt_config = self.config.checkpoint
suffix = "best.ckpt" if ckpt_config.resume_best else "current.ckpt"
reverse_suffix = "best.ckpt" if not ckpt_config.resume_best else "current.ckpt"
ckpt_filepath = os.path.join(self.ckpt_foldername, self.ckpt_prefix + suffix)
# In case of interrupts and resume, ckpt_config.resume_file would be there
# But, if the checkpoints are already created in the save dir
# and resume is true signifying the interrupt resume, we should skip
# loading the resume file.
if (
ckpt_config.resume_file is not None or ckpt_config.resume_zoo is not None
) and (not ckpt_config.resume or not PathManager.exists(ckpt_filepath)):
if ckpt_config.resume_file and PathManager.exists(ckpt_config.resume_file):
self._load(
ckpt_config.resume_file,
load_pretrained=ckpt_config.resume_pretrained,
)
return
# resume_file doesn't exist, try from zoo now
elif ckpt_config.resume_zoo is not None:
self._load(
ckpt_config.resume_zoo,
load_zoo=True,
load_pretrained=ckpt_config.resume_pretrained,
)
return
else:
raise RuntimeError(f"{ckpt_config.resume_file} doesn't exist")
if ckpt_config.resume:
if PathManager.exists(ckpt_filepath):
self._load(ckpt_filepath)
else:
warnings.warn(
"Tried to resume but checkpoint filepath {} "
"is not present. Trying {}, otherwise skipping.".format(
ckpt_filepath, reverse_suffix
)
)
ckpt_filepath = ckpt_filepath.replace(suffix, reverse_suffix)
if PathManager.exists(ckpt_filepath):
self._load(ckpt_filepath)