Skip to content

Commit

Permalink
Improved checkpointing.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmcpantoja committed Dec 11, 2023
1 parent e8edb3b commit bac6b8d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/python/piper_train/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ def main():
Trainer.add_argparse_args(parser)
VitsModel.add_model_specific_args(parser)
parser.add_argument("--seed", type=int, default=1234)
parser.add_argument(
"--num_ckpt", default=1, help="# of ckpts saved."
)
parser.add_argument(
"--save_last", default=False, help="Always save the last checkpoint."
)
args = parser.parse_args()
_LOGGER.debug(args)

Expand All @@ -59,10 +65,18 @@ def main():

trainer = Trainer.from_argparse_args(args)
if args.checkpoint_epochs is not None:
trainer.callbacks = [ModelCheckpoint(every_n_epochs=args.checkpoint_epochs)]
trainer.callbacks = [ModelCheckpoint(
every_n_epochs=args.checkpoint_epochs,
filename="model",
save_top_k=args.num_ckpt,
save_last=args.save_last
)]
_LOGGER.debug(
"Checkpoints will be saved every %s epoch(s)", args.checkpoint_epochs
)
_LOGGER.debug(
"%s Checkpoints will be saved", args.num_ckpt
)

dict_args = vars(args)
if args.quality == "x-low":
Expand Down

3 comments on commit bac6b8d

@Sobsz
Copy link

@Sobsz Sobsz commented on bac6b8d Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to use num_ckpt causes the error TypeError: '<' not supported between instances of 'str' and 'int'. To fix it, add type parameters to the new arguments, like the one --seed has.

@rmcpantoja
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Sobsz,
Sorry for that. I'll try to solve it now. Thank you for your observation!

@rmcpantoja
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed :)

Please sign in to comment.