From de9eaee06fb7e06ceafc272c8c16c52a5d627189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20W=C3=A4lchli?= Date: Mon, 6 Sep 2021 13:02:16 +0200 Subject: [PATCH 1/5] fix signature in timer to prevent deprecation warning --- pytorch_lightning/callbacks/timer.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pytorch_lightning/callbacks/timer.py b/pytorch_lightning/callbacks/timer.py index f68ddb8611264..aff6b917096b5 100644 --- a/pytorch_lightning/callbacks/timer.py +++ b/pytorch_lightning/callbacks/timer.py @@ -148,7 +148,9 @@ def on_train_batch_end(self, trainer: "pl.Trainer", *args, **kwargs) -> None: return self._check_time_remaining(trainer) - def on_train_epoch_end(self, trainer: "pl.Trainer", *args, **kwargs) -> None: + def on_train_epoch_end( + self, trainer: "pl.Trainer", pl_module: "pl.LightningModule", unused: Optional = None + ) -> None: if self._interval != Interval.epoch or self._duration is None: return self._check_time_remaining(trainer) From 00fe34360085fd5805bf021b6f62051bffabaee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20W=C3=A4lchli?= Date: Mon, 6 Sep 2021 13:06:50 +0200 Subject: [PATCH 2/5] update changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21c2c1e5e3cb0..eb9a730c67cd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). +## [1.4.6] - unreleased + +- Fixed signature of `Timer.on_train_epoch_end` to prevent unwanted depreation warnings ([#9347](https://github.com/PyTorchLightning/pytorch-lightning/pull/9347)) + + ## [1.4.5] - 2021-08-31 - Fixed reduction using `self.log(sync_dict=True, reduce_fx={mean,max})` ([#9142](https://github.com/PyTorchLightning/pytorch-lightning/pull/9142)) From b672b73a7cc94ead5c945a80e627aa434d192104 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20W=C3=A4lchli?= Date: Mon, 6 Sep 2021 13:14:56 +0200 Subject: [PATCH 3/5] include fix for swa --- CHANGELOG.md | 2 +- pytorch_lightning/callbacks/stochastic_weight_avg.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb9a730c67cd4..c04c299c2342d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ## [1.4.6] - unreleased -- Fixed signature of `Timer.on_train_epoch_end` to prevent unwanted depreation warnings ([#9347](https://github.com/PyTorchLightning/pytorch-lightning/pull/9347)) +- Fixed signature of `Timer.on_train_epoch_end` and `StochasticWeightAveraging.on_train_epoch_end` to prevent unwanted depreation warnings ([#9347](https://github.com/PyTorchLightning/pytorch-lightning/pull/9347)) ## [1.4.5] - 2021-08-31 diff --git a/pytorch_lightning/callbacks/stochastic_weight_avg.py b/pytorch_lightning/callbacks/stochastic_weight_avg.py index 28c19944ebd37..dbf173ccb6e51 100644 --- a/pytorch_lightning/callbacks/stochastic_weight_avg.py +++ b/pytorch_lightning/callbacks/stochastic_weight_avg.py @@ -216,7 +216,7 @@ def on_train_epoch_start(self, trainer: "pl.Trainer", pl_module: "pl.LightningMo trainer.accumulate_grad_batches = trainer.num_training_batches - def on_train_epoch_end(self, trainer: "pl.Trainer", *args): + def on_train_epoch_end(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule", unused: Optional = None): trainer.fit_loop._skip_backward = False def on_train_end(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule"): From 1e9996f0ea97608eedb7d7e0591869b34fde50c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20W=C3=A4lchli?= Date: Mon, 6 Sep 2021 13:20:41 +0200 Subject: [PATCH 4/5] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c04c299c2342d..493be1077398e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ## [1.4.6] - unreleased -- Fixed signature of `Timer.on_train_epoch_end` and `StochasticWeightAveraging.on_train_epoch_end` to prevent unwanted depreation warnings ([#9347](https://github.com/PyTorchLightning/pytorch-lightning/pull/9347)) +- Fixed signature of `Timer.on_train_epoch_end` and `StochasticWeightAveraging.on_train_epoch_end` to prevent unwanted deprecation warnings ([#9347](https://github.com/PyTorchLightning/pytorch-lightning/pull/9347)) ## [1.4.5] - 2021-08-31 From 02a2a406f6f9ae34bbc05bc88f23c5460574ea30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20W=C3=A4lchli?= Date: Mon, 6 Sep 2021 13:25:35 +0200 Subject: [PATCH 5/5] add test --- tests/callbacks/test_timer.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/callbacks/test_timer.py b/tests/callbacks/test_timer.py index c7b636d3f843a..4d93733eea36e 100644 --- a/tests/callbacks/test_timer.py +++ b/tests/callbacks/test_timer.py @@ -24,6 +24,7 @@ from pytorch_lightning.utilities.exceptions import MisconfigurationException from tests.helpers import BoringModel from tests.helpers.runif import RunIf +from tests.helpers.utils import no_warning_call def test_trainer_flag(caplog): @@ -106,7 +107,9 @@ def test_timer_stops_training(tmpdir, caplog): timer = Timer(duration=duration) trainer = Trainer(default_root_dir=tmpdir, max_epochs=1000, callbacks=[timer]) - with caplog.at_level(logging.INFO): + with caplog.at_level(logging.INFO), no_warning_call( + DeprecationWarning, match="The signature of `Callback.on_train_epoch_end` has changed in v1.3" + ): trainer.fit(model) assert trainer.global_step > 1 assert trainer.current_epoch < 999