How can I save and restore the trained model when I call fit() at pytorch_lightning every time?
Hi, everyone!
I want to load model from checkpoint when start a training, and save it to disk when finished every epoch automatically,
Is there any nice way to do that correctly?
Shall we modify the Trianer code, or just use a special hook?
For loading the model, are you looking to load just the weights? If so, take a look at LightningModule.load_from_checkpoint: https://pytorch-lightning.readthedocs.io/en/latest/common/weights_loading.html#checkpoint-loading


Otherwise, if you want to load the whole training state (for example, including the optimizer states), take a look here: https://pytorch-lightning.readthedocs.io/en/latest/common/weights_loading.html#restoring-training-state


For saving, take a look at the ModelCheckpoint callback: https://pytorch-lightning.readthedocs.io/en/latest/common/weights_loading.html#automatic-saving