Skip to content

Commit c30ba1b

Browse files
kazhangtchatonSkafteNicki
authored andcommitted
Replace a MisconfigurationException with warning in ModelCheckpoint callback (#4560)
* replace MisconfigurationException with warning * update test * check raising UserWarning Co-authored-by: chaton <[email protected]> Co-authored-by: Nicki Skafte <[email protected]> (cherry picked from commit 30ad3e2)
1 parent d67ade1 commit c30ba1b

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

pytorch_lightning/callbacks/model_checkpoint.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ def __validate_init_configuration(self):
247247
' configuration. No quantity for top_k to track.'
248248
)
249249
if self.save_last:
250-
raise MisconfigurationException(
251-
'ModelCheckpoint(save_last=True, monitor=None) is not a valid configuration.'
252-
' You can save the last checkpoint with ModelCheckpoint(save_top_k=None, monitor=None)'
250+
rank_zero_warn(
251+
'ModelCheckpoint(save_last=True, monitor=None) is a redundant configuration.'
252+
' You can save the last checkpoint with ModelCheckpoint(save_top_k=None, monitor=None).'
253253
)
254254

255255
def __init_ckpt_dir(self, filepath, dirpath, filename, save_top_k):

tests/checkpointing/test_model_checkpoint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ def test_none_monitor_top_k(tmpdir):
284284

285285
def test_none_monitor_save_last(tmpdir):
286286
""" Test that a warning appears for save_last=True with monitor=None. """
287-
with pytest.raises(
288-
MisconfigurationException, match=r'ModelCheckpoint\(save_last=True, monitor=None\) is not a valid.*'
287+
with pytest.warns(
288+
UserWarning, match=r'ModelCheckpoint\(save_last=True, monitor=None\) is a redundant.*'
289289
):
290290
ModelCheckpoint(dirpath=tmpdir, save_last=True)
291291
# These should not fail

0 commit comments

Comments
 (0)