Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the deprecated pl.loggers.base module #16120

Merged
merged 2 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/pytorch_lightning/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,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))
Expand Down
53 changes: 51 additions & 2 deletions src/pytorch_lightning/_graveyard/loggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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(
Expand All @@ -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
4 changes: 1 addition & 3 deletions src/pytorch_lightning/loggers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
70 changes: 0 additions & 70 deletions src/pytorch_lightning/loggers/base.py

This file was deleted.

64 changes: 0 additions & 64 deletions tests/tests_pytorch/deprecated_api/test_remove_1-9.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
27 changes: 27 additions & 0 deletions tests/tests_pytorch/graveyard/test_loggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()