From 987dd54b2962a3c3fb5ccb278dbb9a51715b0985 Mon Sep 17 00:00:00 2001 From: awaelchli Date: Thu, 18 Aug 2022 15:17:26 +0200 Subject: [PATCH] Fix access to logger attribute when multiple loggers are used (#14234) * Fix access to logger attribute when multiple loggers are used --- src/pytorch_lightning/CHANGELOG.md | 2 +- src/pytorch_lightning/core/module.py | 3 ++- tests/tests_pytorch/deprecated_api/test_remove_1-8.py | 6 ++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/pytorch_lightning/CHANGELOG.md b/src/pytorch_lightning/CHANGELOG.md index 197528f5eb0c6..67eb0080940b0 100644 --- a/src/pytorch_lightning/CHANGELOG.md +++ b/src/pytorch_lightning/CHANGELOG.md @@ -9,7 +9,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Fixed - Fixed an assertion error when using a `ReduceOnPlateau` scheduler with the Horovod strategy ([#14215](https://github.com/Lightning-AI/lightning/pull/14215)) - +- Fixed an `AttributeError` when accessing `LightningModule.logger` and the Trainer has multiple loggers ([#14234](https://github.com/Lightning-AI/lightning/pull/14234)) ## [1.7.2] - 2022-08-16 diff --git a/src/pytorch_lightning/core/module.py b/src/pytorch_lightning/core/module.py index 30e3562067ba7..1f89609e82e82 100644 --- a/src/pytorch_lightning/core/module.py +++ b/src/pytorch_lightning/core/module.py @@ -19,6 +19,7 @@ import numbers import os import tempfile +import warnings import weakref from contextlib import contextmanager from pathlib import Path @@ -39,7 +40,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 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 e39b75b24d264..9c21b3f97ff6f 100644 --- a/tests/tests_pytorch/deprecated_api/test_remove_1-8.py +++ b/tests/tests_pytorch/deprecated_api/test_remove_1-8.py @@ -764,6 +764,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):