From 403ffdb26ded14c0fb5753df997a41a357b6f554 Mon Sep 17 00:00:00 2001 From: thomas chaton Date: Wed, 3 Mar 2021 16:14:46 +0000 Subject: [PATCH 1/4] resolve bug --- pytorch_lightning/trainer/evaluation_loop.py | 4 ++++ tests/trainer/{logging_ => logging}/__init__.py | 0 .../trainer/{logging_ => logging}/test_distributed_logging.py | 0 .../{logging_ => logging}/test_eval_loop_logging_1_0.py | 2 ++ tests/trainer/{logging_ => logging}/test_logger_connector.py | 0 .../{logging_ => logging}/test_progress_bar_logging.py | 0 .../{logging_ => logging}/test_train_loop_logging_1_0.py | 0 7 files changed, 6 insertions(+) rename tests/trainer/{logging_ => logging}/__init__.py (100%) rename tests/trainer/{logging_ => logging}/test_distributed_logging.py (100%) rename tests/trainer/{logging_ => logging}/test_eval_loop_logging_1_0.py (99%) rename tests/trainer/{logging_ => logging}/test_logger_connector.py (100%) rename tests/trainer/{logging_ => logging}/test_progress_bar_logging.py (100%) rename tests/trainer/{logging_ => logging}/test_train_loop_logging_1_0.py (100%) diff --git a/pytorch_lightning/trainer/evaluation_loop.py b/pytorch_lightning/trainer/evaluation_loop.py index 087741aa69c2b..76a91bb5ea75d 100644 --- a/pytorch_lightning/trainer/evaluation_loop.py +++ b/pytorch_lightning/trainer/evaluation_loop.py @@ -203,6 +203,10 @@ def __run_eval_epoch_end(self, num_dataloaders): # with a single dataloader don't pass an array outputs = self.outputs + + # free memory + self.outputs = [] + eval_results = outputs if num_dataloaders == 1: eval_results = outputs[0] diff --git a/tests/trainer/logging_/__init__.py b/tests/trainer/logging/__init__.py similarity index 100% rename from tests/trainer/logging_/__init__.py rename to tests/trainer/logging/__init__.py diff --git a/tests/trainer/logging_/test_distributed_logging.py b/tests/trainer/logging/test_distributed_logging.py similarity index 100% rename from tests/trainer/logging_/test_distributed_logging.py rename to tests/trainer/logging/test_distributed_logging.py diff --git a/tests/trainer/logging_/test_eval_loop_logging_1_0.py b/tests/trainer/logging/test_eval_loop_logging_1_0.py similarity index 99% rename from tests/trainer/logging_/test_eval_loop_logging_1_0.py rename to tests/trainer/logging/test_eval_loop_logging_1_0.py index e5cf596a78eca..0337b78f29454 100644 --- a/tests/trainer/logging_/test_eval_loop_logging_1_0.py +++ b/tests/trainer/logging/test_eval_loop_logging_1_0.py @@ -110,6 +110,7 @@ def training_step(self, batch, batch_idx): return acc def validation_step(self, batch, batch_idx): + self.batch_idx = batch_idx acc = self.step(batch, batch_idx) acc = acc + batch_idx self.log('c', acc) @@ -126,6 +127,7 @@ def validation_step_end(self, acc): def validation_epoch_end(self, outputs): self.log('g', torch.tensor(2, device=self.device), on_epoch=True) self.validation_epoch_end_called = True + assert len(self.trainer.evaluation_loop.outputs) == 0 def backward(self, loss, optimizer, optimizer_idx): return LightningModule.backward(self, loss, optimizer, optimizer_idx) diff --git a/tests/trainer/logging_/test_logger_connector.py b/tests/trainer/logging/test_logger_connector.py similarity index 100% rename from tests/trainer/logging_/test_logger_connector.py rename to tests/trainer/logging/test_logger_connector.py diff --git a/tests/trainer/logging_/test_progress_bar_logging.py b/tests/trainer/logging/test_progress_bar_logging.py similarity index 100% rename from tests/trainer/logging_/test_progress_bar_logging.py rename to tests/trainer/logging/test_progress_bar_logging.py diff --git a/tests/trainer/logging_/test_train_loop_logging_1_0.py b/tests/trainer/logging/test_train_loop_logging_1_0.py similarity index 100% rename from tests/trainer/logging_/test_train_loop_logging_1_0.py rename to tests/trainer/logging/test_train_loop_logging_1_0.py From 008d1e90931ef5cdde6a67c98e4624dec1496675 Mon Sep 17 00:00:00 2001 From: tchaton Date: Wed, 3 Mar 2021 16:16:27 +0000 Subject: [PATCH 2/4] resolve flake8 --- pytorch_lightning/trainer/evaluation_loop.py | 4 ++-- tests/callbacks/test_pruning.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pytorch_lightning/trainer/evaluation_loop.py b/pytorch_lightning/trainer/evaluation_loop.py index 76a91bb5ea75d..e1b3688ef36e6 100644 --- a/pytorch_lightning/trainer/evaluation_loop.py +++ b/pytorch_lightning/trainer/evaluation_loop.py @@ -203,10 +203,10 @@ def __run_eval_epoch_end(self, num_dataloaders): # with a single dataloader don't pass an array outputs = self.outputs - + # free memory self.outputs = [] - + eval_results = outputs if num_dataloaders == 1: eval_results = outputs[0] diff --git a/tests/callbacks/test_pruning.py b/tests/callbacks/test_pruning.py index 23b2fcbb52235..0e63fc29d49b1 100644 --- a/tests/callbacks/test_pruning.py +++ b/tests/callbacks/test_pruning.py @@ -11,7 +11,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import os from collections import OrderedDict from logging import INFO @@ -22,7 +21,7 @@ from torch.nn import Sequential from pytorch_lightning import seed_everything, Trainer -from pytorch_lightning.callbacks import ModelPruning, ModelCheckpoint +from pytorch_lightning.callbacks import ModelCheckpoint, ModelPruning from pytorch_lightning.utilities.exceptions import MisconfigurationException from tests.helpers import BoringModel from tests.helpers.runif import RunIf @@ -274,6 +273,7 @@ def test_permanent_when_model_is_saved_multiple_times(tmpdir, caplog): seed_everything(0) class TestPruning(ModelPruning): + def on_save_checkpoint(self, trainer, pl_module, checkpoint): super().on_save_checkpoint(trainer, pl_module, checkpoint) assert "layer.mlp_3.weight_orig" not in checkpoint["state_dict"] From 9fe9b725b049790f7bccc2ecad4c423aa45db771 Mon Sep 17 00:00:00 2001 From: tchaton Date: Wed, 3 Mar 2021 17:10:27 +0000 Subject: [PATCH 3/4] revert name --- tests/trainer/{logging => logging_}/__init__.py | 0 .../{logging => logging_}/test_distributed_logging.py | 0 .../{logging => logging_}/test_eval_loop_logging_1_0.py | 0 .../trainer/{logging => logging_}/test_logger_connector.py | 6 ++---- .../{logging => logging_}/test_progress_bar_logging.py | 0 .../{logging => logging_}/test_train_loop_logging_1_0.py | 0 6 files changed, 2 insertions(+), 4 deletions(-) rename tests/trainer/{logging => logging_}/__init__.py (100%) rename tests/trainer/{logging => logging_}/test_distributed_logging.py (100%) rename tests/trainer/{logging => logging_}/test_eval_loop_logging_1_0.py (100%) rename tests/trainer/{logging => logging_}/test_logger_connector.py (99%) rename tests/trainer/{logging => logging_}/test_progress_bar_logging.py (100%) rename tests/trainer/{logging => logging_}/test_train_loop_logging_1_0.py (100%) diff --git a/tests/trainer/logging/__init__.py b/tests/trainer/logging_/__init__.py similarity index 100% rename from tests/trainer/logging/__init__.py rename to tests/trainer/logging_/__init__.py diff --git a/tests/trainer/logging/test_distributed_logging.py b/tests/trainer/logging_/test_distributed_logging.py similarity index 100% rename from tests/trainer/logging/test_distributed_logging.py rename to tests/trainer/logging_/test_distributed_logging.py diff --git a/tests/trainer/logging/test_eval_loop_logging_1_0.py b/tests/trainer/logging_/test_eval_loop_logging_1_0.py similarity index 100% rename from tests/trainer/logging/test_eval_loop_logging_1_0.py rename to tests/trainer/logging_/test_eval_loop_logging_1_0.py diff --git a/tests/trainer/logging/test_logger_connector.py b/tests/trainer/logging_/test_logger_connector.py similarity index 99% rename from tests/trainer/logging/test_logger_connector.py rename to tests/trainer/logging_/test_logger_connector.py index 47ffa6649ffc4..3db0a8eaa065b 100644 --- a/tests/trainer/logging/test_logger_connector.py +++ b/tests/trainer/logging_/test_logger_connector.py @@ -478,6 +478,7 @@ def test_auto_add_dataloader_idx(tmpdir, add_dataloader_idx): """ test that auto_add_dataloader_idx argument works """ class TestModel(BoringModel): + def val_dataloader(self): dl = super().val_dataloader() return [dl, dl] @@ -495,10 +496,7 @@ def validation_step(self, *args, **kwargs): model = TestModel() model.validation_epoch_end = None - trainer = Trainer( - default_root_dir=tmpdir, - max_steps=5 - ) + trainer = Trainer(default_root_dir=tmpdir, max_steps=5) trainer.fit(model) logged = trainer.logged_metrics diff --git a/tests/trainer/logging/test_progress_bar_logging.py b/tests/trainer/logging_/test_progress_bar_logging.py similarity index 100% rename from tests/trainer/logging/test_progress_bar_logging.py rename to tests/trainer/logging_/test_progress_bar_logging.py diff --git a/tests/trainer/logging/test_train_loop_logging_1_0.py b/tests/trainer/logging_/test_train_loop_logging_1_0.py similarity index 100% rename from tests/trainer/logging/test_train_loop_logging_1_0.py rename to tests/trainer/logging_/test_train_loop_logging_1_0.py From e8c56d896bb1e40f8344620d01c90787de293aa0 Mon Sep 17 00:00:00 2001 From: tchaton Date: Wed, 3 Mar 2021 17:24:38 +0000 Subject: [PATCH 4/4] address comments --- tests/trainer/logging_/test_eval_loop_logging_1_0.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/trainer/logging_/test_eval_loop_logging_1_0.py b/tests/trainer/logging_/test_eval_loop_logging_1_0.py index 0337b78f29454..72084454ba10d 100644 --- a/tests/trainer/logging_/test_eval_loop_logging_1_0.py +++ b/tests/trainer/logging_/test_eval_loop_logging_1_0.py @@ -110,7 +110,6 @@ def training_step(self, batch, batch_idx): return acc def validation_step(self, batch, batch_idx): - self.batch_idx = batch_idx acc = self.step(batch, batch_idx) acc = acc + batch_idx self.log('c', acc)