Skip to content

Commit

Permalink
Replace a MisconfigurationException with warning in ModelCheckpoint c…
Browse files Browse the repository at this point in the history
…allback (#4560)

* replace MisconfigurationException with warning

* update test

* check raising UserWarning

Co-authored-by: chaton <thomas@grid.ai>
Co-authored-by: Nicki Skafte <skaftenicki@gmail.com>
(cherry picked from commit 30ad3e2)
  • Loading branch information
kazhang authored and SeanNaren committed Nov 11, 2020
1 parent d67ade1 commit c30ba1b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pytorch_lightning/callbacks/model_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ def __validate_init_configuration(self):
' configuration. No quantity for top_k to track.'
)
if self.save_last:
raise MisconfigurationException(
'ModelCheckpoint(save_last=True, monitor=None) is not a valid configuration.'
' You can save the last checkpoint with ModelCheckpoint(save_top_k=None, monitor=None)'
rank_zero_warn(
'ModelCheckpoint(save_last=True, monitor=None) is a redundant configuration.'
' You can save the last checkpoint with ModelCheckpoint(save_top_k=None, monitor=None).'
)

def __init_ckpt_dir(self, filepath, dirpath, filename, save_top_k):
Expand Down
4 changes: 2 additions & 2 deletions tests/checkpointing/test_model_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ def test_none_monitor_top_k(tmpdir):

def test_none_monitor_save_last(tmpdir):
""" Test that a warning appears for save_last=True with monitor=None. """
with pytest.raises(
MisconfigurationException, match=r'ModelCheckpoint\(save_last=True, monitor=None\) is not a valid.*'
with pytest.warns(
UserWarning, match=r'ModelCheckpoint\(save_last=True, monitor=None\) is a redundant.*'
):
ModelCheckpoint(dirpath=tmpdir, save_last=True)
# These should not fail
Expand Down

0 comments on commit c30ba1b

Please sign in to comment.