diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a22cda7e957f..2e39a51694931 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -282,6 +282,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Deprecated the `Trainer.train_loop` property in favor of `Trainer.fit_loop` ([#8025](https://github.com/PyTorchLightning/pytorch-lightning/pull/8025)) +- Deprecated the `Trainer.disable_validation` property in favor of `not Trainer.enable_validation` ([#8291](https://github.com/PyTorchLightning/pytorch-lightning/pull/8291)) + + - Deprecated `mode` parameter in `ModelSummary` in favor of `max_depth` ([#8062](https://github.com/PyTorchLightning/pytorch-lightning/pull/8062)) diff --git a/pytorch_lightning/loops/fit_loop.py b/pytorch_lightning/loops/fit_loop.py index f4fa04070a961..555b9bf6b76a3 100644 --- a/pytorch_lightning/loops/fit_loop.py +++ b/pytorch_lightning/loops/fit_loop.py @@ -235,7 +235,7 @@ def on_advance_end(self) -> None: self.epoch_loop.update_lr_schedulers('epoch', update_plateau_schedulers=True) - did_train_only = self.trainer.disable_validation or self.epoch_loop.val_loop.skip + did_train_only = not self.trainer.enable_validation or self.epoch_loop.val_loop.skip if did_train_only: self.global_step -= 1 self._check_checkpoint_callback(True) diff --git a/pytorch_lightning/trainer/properties.py b/pytorch_lightning/trainer/properties.py index f57110368ef2e..a519b82234a43 100644 --- a/pytorch_lightning/trainer/properties.py +++ b/pytorch_lightning/trainer/properties.py @@ -38,7 +38,7 @@ from pytorch_lightning.trainer.connectors.logger_connector import LoggerConnector from pytorch_lightning.trainer.connectors.logger_connector.result import ResultCollection from pytorch_lightning.trainer.states import RunningStage, TrainerFn, TrainerState, TrainerStatus -from pytorch_lightning.utilities import DeviceType, DistributedType, rank_zero_warn +from pytorch_lightning.utilities import DeviceType, DistributedType, rank_zero_deprecation, rank_zero_warn from pytorch_lightning.utilities.argparse import ( add_argparse_args, from_argparse_args, @@ -296,6 +296,10 @@ def progress_bar_dict(self) -> dict: @property def disable_validation(self) -> bool: """ Check if validation is disabled during training. """ + rank_zero_deprecation( + "`trainer.disable_validation` is deprecated in v1.4 and will be removed in v1.6." + " Use `not trainer.enable_validation` instead." + ) return not self.enable_validation @property diff --git a/tests/deprecated_api/test_remove_1-6.py b/tests/deprecated_api/test_remove_1-6.py index ba033a0ebeced..ac5b56ea00086 100644 --- a/tests/deprecated_api/test_remove_1-6.py +++ b/tests/deprecated_api/test_remove_1-6.py @@ -275,3 +275,9 @@ def test_v1_6_0_deprecated_model_summary_mode(tmpdir): with pytest.deprecated_call(match="Argument `mode` in `LightningModule.summarize` is deprecated in v1.4"): model.summarize(mode="top") + + +def test_v1_6_0_deprecated_disable_validation(): + trainer = Trainer() + with pytest.deprecated_call(match="disable_validation` is deprecated in v1.4"): + _ = trainer.disable_validation diff --git a/tests/trainer/test_dataloaders.py b/tests/trainer/test_dataloaders.py index 762405c6710bc..9e91c8dfe6e53 100644 --- a/tests/trainer/test_dataloaders.py +++ b/tests/trainer/test_dataloaders.py @@ -582,7 +582,7 @@ def test_dataloaders_with_fast_dev_run(tmpdir, fast_dev_run): assert trainer.max_epochs == 1 trainer.fit(model) - assert not trainer.disable_validation + assert trainer.enable_validation assert trainer.num_training_batches == fast_dev_run assert trainer.num_val_batches == [fast_dev_run] * len(trainer.val_dataloaders)