From 94349fbd888f92b6f4460521b73fb64d605e7e62 Mon Sep 17 00:00:00 2001 From: awaelchli Date: Tue, 16 Aug 2022 21:09:36 +0200 Subject: [PATCH 1/2] Fix access to logger attribute when multiple loggers are used --- src/pytorch_lightning/core/module.py | 3 ++- tests/tests_pytorch/deprecated_api/test_remove_1-8.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/pytorch_lightning/core/module.py b/src/pytorch_lightning/core/module.py index 612bcc72d2806..ac15f2aac07cd 100644 --- a/src/pytorch_lightning/core/module.py +++ b/src/pytorch_lightning/core/module.py @@ -38,7 +38,7 @@ from pytorch_lightning.core.saving import ModelIO from pytorch_lightning.loggers import Logger, LoggerCollection from pytorch_lightning.trainer.connectors.logger_connector.fx_validator import _FxValidator -from pytorch_lightning.utilities import _IS_WINDOWS, _TORCH_GREATER_EQUAL_1_10, GradClipAlgorithmType, warnings +from pytorch_lightning.utilities import _IS_WINDOWS, _TORCH_GREATER_EQUAL_1_10, GradClipAlgorithmType from pytorch_lightning.utilities.apply_func import apply_to_collection, convert_to_tensors from pytorch_lightning.utilities.cloud_io import get_filesystem from pytorch_lightning.utilities.distributed import distributed_available, sync_ddp @@ -48,6 +48,7 @@ from pytorch_lightning.utilities.signature_utils import is_param_in_hook_signature from pytorch_lightning.utilities.types import _METRIC_COLLECTION, EPOCH_OUTPUT, LRSchedulerTypeUnion, STEP_OUTPUT from pytorch_lightning.utilities.warnings import WarningCache +import warnings warning_cache = WarningCache() log = logging.getLogger(__name__) diff --git a/tests/tests_pytorch/deprecated_api/test_remove_1-8.py b/tests/tests_pytorch/deprecated_api/test_remove_1-8.py index 91be34c55078f..a69071fd67610 100644 --- a/tests/tests_pytorch/deprecated_api/test_remove_1-8.py +++ b/tests/tests_pytorch/deprecated_api/test_remove_1-8.py @@ -692,6 +692,12 @@ def test_v1_8_0_logger_collection(tmpdir): with pytest.deprecated_call(match="`LoggerCollection` is deprecated in v1.6"): _ = LoggerCollection([logger1, logger2]) + model = BoringModel() + trainer = Trainer(logger=[logger1, logger2]) + model.trainer = trainer + with pytest.deprecated_call(match="logger` will return the first logger"): + _ = model.logger + def test_v1_8_0_precision_plugin_checkpoint_hooks(tmpdir): class PrecisionPluginSaveHook(PrecisionPlugin): From 1f681b33908c2aab43cf603246fef4abbc2e3bfc Mon Sep 17 00:00:00 2001 From: awaelchli Date: Tue, 16 Aug 2022 21:14:50 +0200 Subject: [PATCH 2/2] add changelog --- src/pytorch_lightning/CHANGELOG.md | 3 +++ src/pytorch_lightning/core/module.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pytorch_lightning/CHANGELOG.md b/src/pytorch_lightning/CHANGELOG.md index 6aa6a9c7d8037..41efa0cd763c3 100644 --- a/src/pytorch_lightning/CHANGELOG.md +++ b/src/pytorch_lightning/CHANGELOG.md @@ -101,6 +101,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Avoided requiring the FairScale package to use precision with the fsdp native strategy ([#14092](https://github.com/Lightning-AI/lightning/pull/14092)) +- Fixed an `AttributeError` when accessing `LightningModule.logger` and the Trainer has multiple loggers ([#14234](https://github.com/Lightning-AI/lightning/pull/14234)) + + ## [1.7.1] - 2022-08-09 ### Fixed diff --git a/src/pytorch_lightning/core/module.py b/src/pytorch_lightning/core/module.py index ac15f2aac07cd..c57328303818d 100644 --- a/src/pytorch_lightning/core/module.py +++ b/src/pytorch_lightning/core/module.py @@ -18,6 +18,7 @@ import numbers import os import tempfile +import warnings import weakref from contextlib import contextmanager from pathlib import Path @@ -48,7 +49,6 @@ from pytorch_lightning.utilities.signature_utils import is_param_in_hook_signature from pytorch_lightning.utilities.types import _METRIC_COLLECTION, EPOCH_OUTPUT, LRSchedulerTypeUnion, STEP_OUTPUT from pytorch_lightning.utilities.warnings import WarningCache -import warnings warning_cache = WarningCache() log = logging.getLogger(__name__)