diff --git a/CHANGELOG.md b/CHANGELOG.md index 00bd7c84b0fb9..bf426c3fa0371 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -418,6 +418,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Removed `TrainerProperties` mixin and moved property definitions directly into `Trainer` ([#9495](https://github.com/PyTorchLightning/pytorch-lightning/pull/9495)) +- Removed a redundant warning with `ModelCheckpoint(monitor=None)` callback ([#9875](https://github.com/PyTorchLightning/pytorch-lightning/pull/9875)) + + ### Fixed diff --git a/pytorch_lightning/callbacks/model_checkpoint.py b/pytorch_lightning/callbacks/model_checkpoint.py index a56a4e7eeaad7..8d8dca9db5b24 100644 --- a/pytorch_lightning/callbacks/model_checkpoint.py +++ b/pytorch_lightning/callbacks/model_checkpoint.py @@ -147,7 +147,7 @@ class ModelCheckpoint(Callback): Raises: MisconfigurationException: - If ``save_top_k`` is neither ``None`` nor more than or equal to ``-1``, + If ``save_top_k`` is smaller than ``-1``, if ``monitor`` is ``None`` and ``save_top_k`` is none of ``None``, ``-1``, and ``0``, or if ``mode`` is none of ``"min"`` or ``"max"``. ValueError: @@ -427,11 +427,7 @@ def __validate_init_configuration(self) -> None: f"ModelCheckpoint(save_top_k={self.save_top_k}, monitor=None) is not a valid" " configuration. No quantity for top_k to track." ) - if self.save_last: - rank_zero_warn( - "ModelCheckpoint(save_last=True, save_top_k=None, monitor=None) is a redundant configuration." - " You can save the last checkpoint with ModelCheckpoint(save_top_k=None, monitor=None)." - ) + if self.save_top_k == -1 and self.save_last: rank_zero_info( "ModelCheckpoint(save_last=True, save_top_k=-1, monitor=None)" diff --git a/tests/checkpointing/test_model_checkpoint.py b/tests/checkpointing/test_model_checkpoint.py index ed2da81dbdeda..5664458564993 100644 --- a/tests/checkpointing/test_model_checkpoint.py +++ b/tests/checkpointing/test_model_checkpoint.py @@ -516,15 +516,6 @@ def test_none_monitor_top_k(tmpdir): ModelCheckpoint(dirpath=tmpdir, save_top_k=1) -def test_none_monitor_save_last(tmpdir): - """Test that a warning appears for save_last=True with monitor=None.""" - with pytest.warns(UserWarning, match=r"ModelCheckpoint.*is a redundant.*"): - ModelCheckpoint(dirpath=tmpdir, save_last=True) - # These should not fail - ModelCheckpoint(dirpath=tmpdir, save_last=None) - ModelCheckpoint(dirpath=tmpdir, save_last=False) - - def test_invalid_every_n_epochs(tmpdir): """Make sure that a MisconfigurationException is raised for a negative every_n_epochs argument.""" with pytest.raises(MisconfigurationException, match=r".*Must be >= 0"):