Skip to content

Commit d8e6078

Browse files
committed
add note and fix docstring
1 parent e088694 commit d8e6078

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

docs/source-pytorch/common/checkpointing_intermediate.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ For fine-grained control over checkpointing behavior, use the :class:`~lightning
2121
checkpoint_callback = ModelCheckpoint(dirpath="my/path/", save_top_k=2, monitor="val_loss")
2222
trainer = Trainer(callbacks=[checkpoint_callback])
2323
trainer.fit(model)
24-
checkpoint_callback.best_model_path
24+
25+
.. note::
26+
You can access the paths of saved checkpoints via the ``checkpoint_callback.best_model_path`` and
27+
``checkpoint_callback.last_model_path`` properties or alternatively ``trainer.checkpoint_callback.best_model_path``
28+
and ``trainer.checkpoint_callback.last_model_path``. These provide the file paths to the best checkpoint
29+
(based on the monitored metric) and the most recently saved checkpoint, respectively.
2530

2631
Any value that has been logged via *self.log* in the LightningModule can be monitored.
2732

src/lightning/pytorch/callbacks/model_checkpoint.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ class ModelCheckpoint(Checkpoint):
204204
... )
205205
206206
# retrieve the best checkpoint after training
207-
checkpoint_callback = ModelCheckpoint(dirpath='my/path/')
208-
trainer = Trainer(callbacks=[checkpoint_callback])
209-
model = ...
210-
trainer.fit(model)
211-
checkpoint_callback.best_model_path
207+
>>> checkpoint_callback = ModelCheckpoint(dirpath='my/path/')
208+
>>> trainer = Trainer(callbacks=[checkpoint_callback])
209+
>>> model = ... # doctest: +SKIP
210+
>>> trainer.fit(model) # doctest: +SKIP
211+
>>> print(checkpoint_callback.best_model_path) # doctest: +SKIP
212212
213213
.. tip:: Saving and restoring multiple checkpoint callbacks at the same time is supported under variation in the
214214
following arguments:

0 commit comments

Comments
 (0)