Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docs/source-pytorch/common/checkpointing_intermediate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ For fine-grained control over checkpointing behavior, use the :class:`~lightning
checkpoint_callback = ModelCheckpoint(dirpath="my/path/", save_top_k=2, monitor="val_loss")
trainer = Trainer(callbacks=[checkpoint_callback])
trainer.fit(model)
checkpoint_callback.best_model_path
# Access best and last model checkpoint directly from the callback
print(checkpoint_callback.best_model_path)
print(checkpoint_callback.last_model_path)
# Or via the trainer
print(trainer.checkpoint_callback.best_model_path)
print(trainer.checkpoint_callback.last_model_path)
Any value that has been logged via *self.log* in the LightningModule can be monitored.

Expand Down
10 changes: 5 additions & 5 deletions src/lightning/pytorch/callbacks/model_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ class ModelCheckpoint(Checkpoint):
... )
# retrieve the best checkpoint after training
checkpoint_callback = ModelCheckpoint(dirpath='my/path/')
trainer = Trainer(callbacks=[checkpoint_callback])
model = ...
trainer.fit(model)
checkpoint_callback.best_model_path
>>> checkpoint_callback = ModelCheckpoint(dirpath='my/path/')
>>> trainer = Trainer(callbacks=[checkpoint_callback])
>>> model = ... # doctest: +SKIP
>>> trainer.fit(model) # doctest: +SKIP
>>> print(checkpoint_callback.best_model_path) # doctest: +SKIP
.. tip:: Saving and restoring multiple checkpoint callbacks at the same time is supported under variation in the
following arguments:
Expand Down
Loading