Skip to content

Commit 352e779

Browse files
committed
Remove the deprecated pl.loggers.base module (#16120)
1 parent 19cb9ea commit 352e779

File tree

6 files changed

+82
-139
lines changed

6 files changed

+82
-139
lines changed

src/pytorch_lightning/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
107107
- Removed the deprecated `pytorch_lightning.utilities.cli` module in favor of `pytorch_lightning.cli` ([#16116](https://github.com/PyTorchLightning/pytorch-lightning/pull/16116))
108108

109109

110+
- Removed the deprecated `pytorch_lightning.loggers.base` module in favor of `pytorch_lightning.loggers.logger` ([#16120](https://github.com/PyTorchLightning/pytorch-lightning/pull/16120))
111+
112+
110113
### Fixed
111114

112115
- Enhanced `reduce_boolean_decision` to accommodate `any`-analogous semantics expected by the `EarlyStopping` callback ([#15253](https://github.com/Lightning-AI/lightning/pull/15253))

src/pytorch_lightning/_graveyard/loggers.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,60 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
14+
import sys
1515
from typing import Any
1616

1717
import pytorch_lightning as pl
1818
from pytorch_lightning.loggers import Logger
1919

2020

21+
def _patch_sys_modules() -> None:
22+
# TODO: Remove in v2.0.0
23+
self = sys.modules[__name__]
24+
sys.modules["pytorch_lightning.loggers.base"] = self
25+
26+
27+
def rank_zero_experiment(*_: Any, **__: Any) -> None:
28+
raise NotImplementedError(
29+
"`pytorch_lightning.loggers.base.rank_zero_experiment` was deprecated in v1.7.0 and removed as of v1.9.0."
30+
" Please use `pytorch_lightning.loggers.logger.rank_zero_experiment` instead"
31+
)
32+
33+
34+
class LightningLoggerBase:
35+
# TODO: Remove in v2.0.0
36+
def __init__(self, *_: Any, **__: Any) -> None:
37+
raise NotImplementedError(
38+
"`pytorch_lightning.loggers.base.LightningLoggerBase` was deprecated in v1.7.0 and removed as of v1.9.0."
39+
" Please use `pytorch_lightning.loggers.Logger` instead"
40+
)
41+
42+
43+
class DummyExperiment:
44+
# TODO: Remove in v2.0.0
45+
def __init__(self, *_: Any, **__: Any) -> None:
46+
raise NotImplementedError(
47+
"`pytorch_lightning.loggers.base.DummyExperiment` was deprecated in v1.7.0 and removed as of v1.9.0."
48+
" Please use `pytorch_lightning.loggers.logger.DummyExperiment` instead"
49+
)
50+
51+
52+
class DummyLogger:
53+
# TODO: Remove in v2.0.0
54+
def __init__(self, *_: Any, **__: Any) -> None:
55+
raise NotImplementedError(
56+
"`pytorch_lightning.loggers.base.DummyLogger` was deprecated in v1.7.0 and removed as of v1.9.0."
57+
" Please use `pytorch_lightning.loggers.logger.DummyLogger` instead"
58+
)
59+
60+
61+
def merge_dicts(*_: Any, **__: Any) -> None:
62+
raise NotImplementedError(
63+
"`pytorch_lightning.loggers.base.merge_dicts` was deprecated in v1.7.0 and removed as of v1.9.0."
64+
" Please use `pytorch_lightning.loggers.logger.merge_dicts` instead"
65+
)
66+
67+
2168
class LoggerCollection:
2269
# TODO: Remove in v2.0.0
2370
def __init__(self, _: Any):
@@ -27,6 +74,9 @@ def __init__(self, _: Any):
2774
)
2875

2976

77+
_patch_sys_modules()
78+
79+
3080
def _update_agg_funcs(logger: Logger, *__: Any, **___: Any) -> None:
3181
# TODO: Remove in v2.0.0
3282
raise NotImplementedError(
@@ -47,4 +97,3 @@ def _agg_and_log_metrics(logger: Logger, *__: Any, **___: Any) -> None:
4797

4898
# Classes
4999
pl.loggers.logger.LoggerCollection = LoggerCollection
50-
pl.loggers.base.LoggerCollection = LoggerCollection

src/pytorch_lightning/loggers/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
# limitations under the License.
1414
import os
1515

16-
# LightningLoggerBase imported for backward compatibility
17-
from pytorch_lightning.loggers.base import LightningLoggerBase
1816
from pytorch_lightning.loggers.comet import _COMET_AVAILABLE, CometLogger # noqa: F401
1917
from pytorch_lightning.loggers.csv_logs import CSVLogger
2018
from pytorch_lightning.loggers.logger import Logger
@@ -23,7 +21,7 @@
2321
from pytorch_lightning.loggers.tensorboard import TensorBoardLogger
2422
from pytorch_lightning.loggers.wandb import WandbLogger # noqa: F401
2523

26-
__all__ = ["CSVLogger", "LightningLoggerBase", "Logger", "TensorBoardLogger"]
24+
__all__ = ["CSVLogger", "Logger", "TensorBoardLogger"]
2725

2826
if _COMET_AVAILABLE:
2927
__all__.append("CometLogger")

src/pytorch_lightning/loggers/base.py

Lines changed: 0 additions & 70 deletions
This file was deleted.

tests/tests_pytorch/deprecated_api/test_remove_1-9.py

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -16,73 +16,9 @@
1616

1717
import pytest
1818

19-
import pytorch_lightning.loggers.base as logger_base
2019
from pytorch_lightning import Trainer
2120
from pytorch_lightning.cli import LightningCLI
2221
from pytorch_lightning.core.module import LightningModule
23-
from pytorch_lightning.utilities.rank_zero import rank_zero_only
24-
25-
26-
def test_lightning_logger_base_deprecation_warning():
27-
class CustomDeprecatedLogger(logger_base.LightningLoggerBase):
28-
def __init__(self):
29-
super().__init__()
30-
31-
@rank_zero_only
32-
def log_hyperparams(self, params):
33-
pass
34-
35-
@rank_zero_only
36-
def log_metrics(self, metrics, step):
37-
pass
38-
39-
@property
40-
def name(self):
41-
pass
42-
43-
@property
44-
def version(self):
45-
pass
46-
47-
with pytest.deprecated_call(
48-
match="The `pytorch_lightning.loggers.base.LightningLoggerBase` is deprecated in v1.7"
49-
" and will be removed in v1.9."
50-
):
51-
CustomDeprecatedLogger()
52-
53-
54-
def test_lightning_logger_base_rank_zero_experiment_deprecation_warning():
55-
with pytest.deprecated_call(
56-
match="The `pytorch_lightning.loggers.base.rank_zero_experiment` is deprecated in v1.7"
57-
" and will be removed in v1.9."
58-
):
59-
logger_base.rank_zero_experiment(None)
60-
61-
62-
def test_lightning_logger_base_dummy_experiment_deprecation_warning():
63-
with pytest.deprecated_call(
64-
match="The `pytorch_lightning.loggers.base.DummyExperiment` is deprecated in v1.7 and will be removed in v1.9."
65-
):
66-
_ = logger_base.DummyExperiment()
67-
68-
69-
def test_lightning_logger_base_dummy_logger_deprecation_warning():
70-
with pytest.deprecated_call(
71-
match="The `pytorch_lightning.loggers.base.DummyLogger` is deprecated in v1.7 and will be removed in v1.9."
72-
):
73-
_ = logger_base.DummyLogger()
74-
75-
76-
def test_lightning_logger_base_merge_dicts_deprecation_warning():
77-
with pytest.deprecated_call(
78-
match="The `pytorch_lightning.loggers.base.merge_dicts` is deprecated in v1.7 and will be removed in v1.9."
79-
):
80-
d1 = {"a": 1.7, "b": 2.0, "c": 1, "d": {"d1": 1, "d3": 3}}
81-
d2 = {"a": 1.1, "b": 2.2, "v": 1, "d": {"d1": 2, "d2": 3}}
82-
d3 = {"a": 1.1, "v": 2.3, "d": {"d3": 3, "d4": {"d5": 1}}}
83-
dflt_func = min
84-
agg_funcs = {"a": min, "v": max, "d": {"d1": sum}}
85-
logger_base.merge_dicts([d1, d2, d3], agg_funcs, dflt_func)
8622

8723

8824
def test_old_lightningmodule_path():

tests/tests_pytorch/graveyard/test_loggers.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,30 @@ def test_v2_0_0_unsupported_logger_collection_class():
7272

7373
with pytest.raises(RuntimeError, match="`LoggerCollection` was deprecated in v1.6 and removed as of v1.8."):
7474
LoggerCollection(None)
75+
76+
77+
def test_lightning_logger_base_removal():
78+
from pytorch_lightning.loggers.base import LightningLoggerBase
79+
80+
with pytest.raises(RuntimeError, match="LightningLoggerBase` was deprecated in v1.7.0 and removed as of v1.9"):
81+
LightningLoggerBase()
82+
83+
from pytorch_lightning.loggers.base import rank_zero_experiment
84+
85+
with pytest.raises(RuntimeError, match="rank_zero_experiment` was deprecated in v1.7.0 and removed as of v1.9"):
86+
rank_zero_experiment()
87+
88+
from pytorch_lightning.loggers.base import DummyExperiment
89+
90+
with pytest.raises(RuntimeError, match="DummyExperiment` was deprecated in v1.7.0 and removed as of v1.9"):
91+
DummyExperiment()
92+
93+
from pytorch_lightning.loggers.base import DummyLogger
94+
95+
with pytest.raises(RuntimeError, match="DummyLogger` was deprecated in v1.7.0 and removed as of v1.9"):
96+
DummyLogger()
97+
98+
from pytorch_lightning.loggers.base import merge_dicts
99+
100+
with pytest.raises(RuntimeError, match="merge_dicts` was deprecated in v1.7.0 and removed as of v1.9"):
101+
merge_dicts()

0 commit comments

Comments
 (0)