Add warning when not saving hparams

This commit is contained in:
NicEggert
2019-10-22 16:21:19 -05:00
parent b1f6c49bd3
commit 9529aa6cc8
+7 -1
View File
@@ -175,7 +175,13 @@ class TrainerIOMixin(object):
# add the hparams and state_dict from the model
model = self.get_model()
checkpoint['state_dict'] = model.state_dict()
checkpoint['hparams'] = vars(model.hparams)
if hasattr(model, "hparams"):
checkpoint['hparams'] = vars(model.hparams)
else:
warnings.warn(
"Did not find hyperparameters at model.hparams. Saving checkpoint without"
" hyperparameters"
)
# give the model a chance to add a few things
model.on_save_checkpoint(checkpoint)