diff --git a/src/pytorch_lightning/CHANGELOG.md b/src/pytorch_lightning/CHANGELOG.md index cabc3f3711a978..712a57ba085dc8 100644 --- a/src/pytorch_lightning/CHANGELOG.md +++ b/src/pytorch_lightning/CHANGELOG.md @@ -107,6 +107,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Removed the deprecated `pytorch_lightning.utilities.cli` module in favor of `pytorch_lightning.cli` ([#16116](https://github.com/PyTorchLightning/pytorch-lightning/pull/16116)) +- Removed the deprecated `pytorch_lightning.loggers.base` module in favor of `pytorch_lightning.loggers.logger` ([#16120](https://github.com/PyTorchLightning/pytorch-lightning/pull/16120)) + + ### Fixed - Enhanced `reduce_boolean_decision` to accommodate `any`-analogous semantics expected by the `EarlyStopping` callback ([#15253](https://github.com/Lightning-AI/lightning/pull/15253)) diff --git a/src/pytorch_lightning/_graveyard/loggers.py b/src/pytorch_lightning/_graveyard/loggers.py index 9ef8cff2b1e14a..57bc65cda06268 100644 --- a/src/pytorch_lightning/_graveyard/loggers.py +++ b/src/pytorch_lightning/_graveyard/loggers.py @@ -11,13 +11,60 @@ # 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 sys from typing import Any import pytorch_lightning as pl from pytorch_lightning.loggers import Logger +def _patch_sys_modules() -> None: + # TODO: Remove in v2.0.0 + self = sys.modules[__name__] + sys.modules["pytorch_lightning.loggers.base"] = self + + +def rank_zero_experiment(*_: Any, **__: Any) -> None: + raise NotImplementedError( + "`pytorch_lightning.loggers.base.rank_zero_experiment` was deprecated in v1.7.0 and removed as of v1.9.0." + " Please use `pytorch_lightning.loggers.logger.rank_zero_experiment` instead" + ) + + +class LightningLoggerBase: + # TODO: Remove in v2.0.0 + def __init__(self, *_: Any, **__: Any) -> None: + raise NotImplementedError( + "`pytorch_lightning.loggers.base.LightningLoggerBase` was deprecated in v1.7.0 and removed as of v1.9.0." + " Please use `pytorch_lightning.loggers.Logger` instead" + ) + + +class DummyExperiment: + # TODO: Remove in v2.0.0 + def __init__(self, *_: Any, **__: Any) -> None: + raise NotImplementedError( + "`pytorch_lightning.loggers.base.DummyExperiment` was deprecated in v1.7.0 and removed as of v1.9.0." + " Please use `pytorch_lightning.loggers.logger.DummyExperiment` instead" + ) + + +class DummyLogger: + # TODO: Remove in v2.0.0 + def __init__(self, *_: Any, **__: Any) -> None: + raise NotImplementedError( + "`pytorch_lightning.loggers.base.DummyLogger` was deprecated in v1.7.0 and removed as of v1.9.0." + " Please use `pytorch_lightning.loggers.logger.DummyLogger` instead" + ) + + +def merge_dicts(*_: Any, **__: Any) -> None: + raise NotImplementedError( + "`pytorch_lightning.loggers.base.merge_dicts` was deprecated in v1.7.0 and removed as of v1.9.0." + " Please use `pytorch_lightning.loggers.logger.merge_dicts` instead" + ) + + class LoggerCollection: # TODO: Remove in v2.0.0 def __init__(self, _: Any): @@ -27,6 +74,9 @@ def __init__(self, _: Any): ) +_patch_sys_modules() + + def _update_agg_funcs(logger: Logger, *__: Any, **___: Any) -> None: # TODO: Remove in v2.0.0 raise NotImplementedError( @@ -47,4 +97,3 @@ def _agg_and_log_metrics(logger: Logger, *__: Any, **___: Any) -> None: # Classes pl.loggers.logger.LoggerCollection = LoggerCollection -pl.loggers.base.LoggerCollection = LoggerCollection diff --git a/src/pytorch_lightning/loggers/__init__.py b/src/pytorch_lightning/loggers/__init__.py index b9f5d2919d61ec..132e571c40cca3 100644 --- a/src/pytorch_lightning/loggers/__init__.py +++ b/src/pytorch_lightning/loggers/__init__.py @@ -13,8 +13,6 @@ # limitations under the License. import os -# LightningLoggerBase imported for backward compatibility -from pytorch_lightning.loggers.base import LightningLoggerBase from pytorch_lightning.loggers.comet import _COMET_AVAILABLE, CometLogger # noqa: F401 from pytorch_lightning.loggers.csv_logs import CSVLogger from pytorch_lightning.loggers.logger import Logger @@ -23,7 +21,7 @@ from pytorch_lightning.loggers.tensorboard import TensorBoardLogger from pytorch_lightning.loggers.wandb import WandbLogger # noqa: F401 -__all__ = ["CSVLogger", "LightningLoggerBase", "Logger", "TensorBoardLogger"] +__all__ = ["CSVLogger", "Logger", "TensorBoardLogger"] if _COMET_AVAILABLE: __all__.append("CometLogger") diff --git a/src/pytorch_lightning/loggers/base.py b/src/pytorch_lightning/loggers/base.py deleted file mode 100644 index 9672f4488e07d8..00000000000000 --- a/src/pytorch_lightning/loggers/base.py +++ /dev/null @@ -1,70 +0,0 @@ -# Copyright The PyTorch Lightning team. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# 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. - -from typing import Callable, Dict, Mapping, Optional, Sequence - -import numpy as np - -import pytorch_lightning.loggers.logger as logger -from pytorch_lightning.utilities.rank_zero import rank_zero_deprecation - - -def rank_zero_experiment(fn: Callable) -> Callable: - rank_zero_deprecation( - "The `pytorch_lightning.loggers.base.rank_zero_experiment` is deprecated in v1.7" - " and will be removed in v1.9. Please use `pytorch_lightning.loggers.logger.rank_zero_experiment` instead." - ) - return logger.rank_zero_experiment(fn) - - -class LightningLoggerBase(logger.Logger): - """Base class for experiment loggers.""" - - def __init__(self, *args, **kwargs) -> None: # type: ignore[no-untyped-def] - rank_zero_deprecation( - "The `pytorch_lightning.loggers.base.LightningLoggerBase` is deprecated in v1.7" - " and will be removed in v1.9. Please use `pytorch_lightning.loggers.logger.Logger` instead." - ) - super().__init__(*args, **kwargs) - - -class DummyExperiment(logger.DummyExperiment): - def __init__(self, *args, **kwargs) -> None: # type: ignore[no-untyped-def] - rank_zero_deprecation( - "The `pytorch_lightning.loggers.base.DummyExperiment` is deprecated in v1.7" - " and will be removed in v1.9. Please use `pytorch_lightning.loggers.logger.DummyExperiment` instead." - ) - super().__init__(*args, **kwargs) - - -class DummyLogger(logger.DummyLogger): - def __init__(self, *args, **kwargs) -> None: # type: ignore[no-untyped-def] - rank_zero_deprecation( - "The `pytorch_lightning.loggers.base.DummyLogger` is deprecated in v1.7" - " and will be removed in v1.9. Please use `pytorch_lightning.loggers.logger.DummyLogger` instead." - ) - - super().__init__(*args, **kwargs) - - -def merge_dicts( - dicts: Sequence[Mapping], - agg_key_funcs: Optional[Mapping] = None, - default_func: Callable[[Sequence[float]], float] = np.mean, -) -> Dict: - rank_zero_deprecation( - "The `pytorch_lightning.loggers.base.merge_dicts` is deprecated in v1.7" - " and will be removed in v1.9. Please use `pytorch_lightning.loggers.logger.merge_dicts` instead." - ) - return logger.merge_dicts(dicts=dicts, agg_key_funcs=agg_key_funcs, default_func=default_func) diff --git a/tests/tests_pytorch/deprecated_api/test_remove_1-9.py b/tests/tests_pytorch/deprecated_api/test_remove_1-9.py index eb5292f3008e89..ffdfb8c9d67715 100644 --- a/tests/tests_pytorch/deprecated_api/test_remove_1-9.py +++ b/tests/tests_pytorch/deprecated_api/test_remove_1-9.py @@ -16,73 +16,9 @@ import pytest -import pytorch_lightning.loggers.base as logger_base from pytorch_lightning import Trainer from pytorch_lightning.cli import LightningCLI from pytorch_lightning.core.module import LightningModule -from pytorch_lightning.utilities.rank_zero import rank_zero_only - - -def test_lightning_logger_base_deprecation_warning(): - class CustomDeprecatedLogger(logger_base.LightningLoggerBase): - def __init__(self): - super().__init__() - - @rank_zero_only - def log_hyperparams(self, params): - pass - - @rank_zero_only - def log_metrics(self, metrics, step): - pass - - @property - def name(self): - pass - - @property - def version(self): - pass - - with pytest.deprecated_call( - match="The `pytorch_lightning.loggers.base.LightningLoggerBase` is deprecated in v1.7" - " and will be removed in v1.9." - ): - CustomDeprecatedLogger() - - -def test_lightning_logger_base_rank_zero_experiment_deprecation_warning(): - with pytest.deprecated_call( - match="The `pytorch_lightning.loggers.base.rank_zero_experiment` is deprecated in v1.7" - " and will be removed in v1.9." - ): - logger_base.rank_zero_experiment(None) - - -def test_lightning_logger_base_dummy_experiment_deprecation_warning(): - with pytest.deprecated_call( - match="The `pytorch_lightning.loggers.base.DummyExperiment` is deprecated in v1.7 and will be removed in v1.9." - ): - _ = logger_base.DummyExperiment() - - -def test_lightning_logger_base_dummy_logger_deprecation_warning(): - with pytest.deprecated_call( - match="The `pytorch_lightning.loggers.base.DummyLogger` is deprecated in v1.7 and will be removed in v1.9." - ): - _ = logger_base.DummyLogger() - - -def test_lightning_logger_base_merge_dicts_deprecation_warning(): - with pytest.deprecated_call( - match="The `pytorch_lightning.loggers.base.merge_dicts` is deprecated in v1.7 and will be removed in v1.9." - ): - d1 = {"a": 1.7, "b": 2.0, "c": 1, "d": {"d1": 1, "d3": 3}} - d2 = {"a": 1.1, "b": 2.2, "v": 1, "d": {"d1": 2, "d2": 3}} - d3 = {"a": 1.1, "v": 2.3, "d": {"d3": 3, "d4": {"d5": 1}}} - dflt_func = min - agg_funcs = {"a": min, "v": max, "d": {"d1": sum}} - logger_base.merge_dicts([d1, d2, d3], agg_funcs, dflt_func) def test_old_lightningmodule_path(): diff --git a/tests/tests_pytorch/graveyard/test_loggers.py b/tests/tests_pytorch/graveyard/test_loggers.py index cc35690f8634f1..3f950b5e041f9d 100644 --- a/tests/tests_pytorch/graveyard/test_loggers.py +++ b/tests/tests_pytorch/graveyard/test_loggers.py @@ -72,3 +72,30 @@ def test_v2_0_0_unsupported_logger_collection_class(): with pytest.raises(RuntimeError, match="`LoggerCollection` was deprecated in v1.6 and removed as of v1.8."): LoggerCollection(None) + + +def test_lightning_logger_base_removal(): + from pytorch_lightning.loggers.base import LightningLoggerBase + + with pytest.raises(RuntimeError, match="LightningLoggerBase` was deprecated in v1.7.0 and removed as of v1.9"): + LightningLoggerBase() + + from pytorch_lightning.loggers.base import rank_zero_experiment + + with pytest.raises(RuntimeError, match="rank_zero_experiment` was deprecated in v1.7.0 and removed as of v1.9"): + rank_zero_experiment() + + from pytorch_lightning.loggers.base import DummyExperiment + + with pytest.raises(RuntimeError, match="DummyExperiment` was deprecated in v1.7.0 and removed as of v1.9"): + DummyExperiment() + + from pytorch_lightning.loggers.base import DummyLogger + + with pytest.raises(RuntimeError, match="DummyLogger` was deprecated in v1.7.0 and removed as of v1.9"): + DummyLogger() + + from pytorch_lightning.loggers.base import merge_dicts + + with pytest.raises(RuntimeError, match="merge_dicts` was deprecated in v1.7.0 and removed as of v1.9"): + merge_dicts()