Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 6 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,12 @@ 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

.. note::
You can access the paths of saved checkpoints via the ``checkpoint_callback.best_model_path`` and
``checkpoint_callback.last_model_path`` properties or alternatively ``trainer.checkpoint_callback.best_model_path``
and ``trainer.checkpoint_callback.last_model_path``. These provide the file paths to the best checkpoint
(based on the monitored metric) and the most recently saved checkpoint, respectively.

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