Skip to content

Commit f915a8a

Browse files
Programmer-RD-AIpre-commit-ci[bot]awaelchlirohitgr7
authored
Removed a redundant warning with ModelCheckpoint(monitor=None) callback (#9875)
* Update README.md * Update README.md * Create evaluation.py * Update README.md * Update evaluation.py * Create evaluation.py * Create evaluation.py * Update evaluation.py * Create nlp.py * Update evaluation.py * Create evaluation.py * Update nlp.py * Update nlp.py * Update evaluation.py * Create evaluation.py * Update nlp.py * Update nlp.py * Update requirements.txt * Update evaluation.py * Create data_loader.py * Update nlp.py * Update evaluation.py * Update data_loader.py * Update nlp.py * Update data_loader.py * Update requirements.txt * Update model_checkpoint.py * Delete evaluation.py * Delete data_loader.py * Delete nlp.py * Update requirements.txt * Update model_checkpoint.py * Update README.md * Update pytorch_lightning/callbacks/model_checkpoint.py * Update CHANGELOG.md * Update test_model_checkpoint.py * Update model_checkpoint.py * update * update * chlog update Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Adrian Wälchli <[email protected]> Co-authored-by: Rohit Gupta <[email protected]>
1 parent 54d4b4b commit f915a8a

File tree

3 files changed

+5
-15
lines changed

3 files changed

+5
-15
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
426426
- Removed `TrainerProperties` mixin and moved property definitions directly into `Trainer` ([#9495](https://github.com/PyTorchLightning/pytorch-lightning/pull/9495))
427427

428428

429+
- Removed a redundant warning with `ModelCheckpoint(monitor=None)` callback ([#9875](https://github.com/PyTorchLightning/pytorch-lightning/pull/9875))
430+
431+
429432
### Fixed
430433

431434

pytorch_lightning/callbacks/model_checkpoint.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class ModelCheckpoint(Callback):
147147
148148
Raises:
149149
MisconfigurationException:
150-
If ``save_top_k`` is neither ``None`` nor more than or equal to ``-1``,
150+
If ``save_top_k`` is smaller than ``-1``,
151151
if ``monitor`` is ``None`` and ``save_top_k`` is none of ``None``, ``-1``, and ``0``, or
152152
if ``mode`` is none of ``"min"`` or ``"max"``.
153153
ValueError:
@@ -427,11 +427,7 @@ def __validate_init_configuration(self) -> None:
427427
f"ModelCheckpoint(save_top_k={self.save_top_k}, monitor=None) is not a valid"
428428
" configuration. No quantity for top_k to track."
429429
)
430-
if self.save_last:
431-
rank_zero_warn(
432-
"ModelCheckpoint(save_last=True, save_top_k=None, monitor=None) is a redundant configuration."
433-
" You can save the last checkpoint with ModelCheckpoint(save_top_k=None, monitor=None)."
434-
)
430+
435431
if self.save_top_k == -1 and self.save_last:
436432
rank_zero_info(
437433
"ModelCheckpoint(save_last=True, save_top_k=-1, monitor=None)"

tests/checkpointing/test_model_checkpoint.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -516,15 +516,6 @@ def test_none_monitor_top_k(tmpdir):
516516
ModelCheckpoint(dirpath=tmpdir, save_top_k=1)
517517

518518

519-
def test_none_monitor_save_last(tmpdir):
520-
"""Test that a warning appears for save_last=True with monitor=None."""
521-
with pytest.warns(UserWarning, match=r"ModelCheckpoint.*is a redundant.*"):
522-
ModelCheckpoint(dirpath=tmpdir, save_last=True)
523-
# These should not fail
524-
ModelCheckpoint(dirpath=tmpdir, save_last=None)
525-
ModelCheckpoint(dirpath=tmpdir, save_last=False)
526-
527-
528519
def test_invalid_every_n_epochs(tmpdir):
529520
"""Make sure that a MisconfigurationException is raised for a negative every_n_epochs argument."""
530521
with pytest.raises(MisconfigurationException, match=r".*Must be >= 0"):

0 commit comments

Comments
 (0)