Skip to content

Error messages for removed Logger APIs #15067

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

Merged
merged 15 commits into from
Oct 11, 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
1 change: 1 addition & 0 deletions src/pytorch_lightning/_graveyard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
# limitations under the License.

import pytorch_lightning._graveyard.callbacks
import pytorch_lightning._graveyard.loggers
import pytorch_lightning._graveyard.trainer
import pytorch_lightning._graveyard.training_type # noqa: F401
50 changes: 50 additions & 0 deletions src/pytorch_lightning/_graveyard/loggers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 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 Any

import pytorch_lightning as pl
from pytorch_lightning.loggers import Logger


class LoggerCollection:
# TODO: Remove in v2.0.0
def __init__(self, _: Any):
raise RuntimeError(
"`LoggerCollection` was deprecated in v1.6 and removed in v1.8. Directly pass a list of loggers"
" to the `Trainer` and access the list via the `trainer.loggers` attribute."
)


def _update_agg_funcs(logger: Logger, *__: Any, **___: Any) -> None:
# TODO: Remove in v2.0.0
raise NotImplementedError(
f"`{type(logger).__name__}.update_agg_funcs` was deprecated in v1.6 and is no longer supported as of v1.8."
)


def _agg_and_log_metrics(logger: Logger, *__: Any, **___: Any) -> None:
# TODO: Remove in v2.0.0
raise NotImplementedError(
f"`{type(logger).__name__}.update_agg_funcs` was deprecated in v1.6 and is no longer supported as of v1.8."
)


# Methods
Logger.update_agg_funcs = _update_agg_funcs
Logger.agg_and_log_metrics = _agg_and_log_metrics

# Classes
pl.loggers.logger.LoggerCollection = LoggerCollection
pl.loggers.base.LoggerCollection = LoggerCollection
17 changes: 17 additions & 0 deletions src/pytorch_lightning/trainer/configuration_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import pytorch_lightning as pl
from lightning_lite.utilities.warnings import PossibleUserWarning
from pytorch_lightning.accelerators.ipu import IPUAccelerator
from pytorch_lightning.loggers import Logger
from pytorch_lightning.strategies import DataParallelStrategy
from pytorch_lightning.trainer.states import TrainerFn
from pytorch_lightning.utilities.exceptions import MisconfigurationException
Expand Down Expand Up @@ -54,6 +55,8 @@ def verify_loop_configurations(trainer: "pl.Trainer") -> None:
_check_on_epoch_start_end(model)
# TODO: Delete this check in v2.0
_check_on_pretrain_routine(model)
# TODO: Delete this check in v2.0
_check_deprecated_logger_methods(trainer)


def __verify_train_val_loop_configuration(trainer: "pl.Trainer", model: "pl.LightningModule") -> None:
Expand Down Expand Up @@ -261,3 +264,17 @@ def _check_deprecated_callback_hooks(trainer: "pl.Trainer") -> None:
raise RuntimeError(
f"The `Callback.{hook}` hook was removed in v1.8. Please use `Callback.on_fit_start` instead."
)


def _check_deprecated_logger_methods(trainer: "pl.Trainer") -> None:
for logger in trainer.loggers:
if is_overridden(method_name="update_agg_funcs", instance=logger, parent=Logger):
raise RuntimeError(
f"`{type(logger).__name__}.update_agg_funcs` was deprecated in v1.6 and is no longer supported as of"
" v1.8."
)
if is_overridden(method_name="agg_and_log_metrics", instance=logger, parent=Logger):
raise RuntimeError(
f"`{type(logger).__name__}.agg_and_log_metrics` was deprecated in v1.6 and is no longer supported as of"
" v1.8."
)
64 changes: 64 additions & 0 deletions tests/tests_pytorch/graveyard/test_loggers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# 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.
import pytest

from pytorch_lightning import Trainer
from pytorch_lightning.demos.boring_classes import BoringModel
from pytorch_lightning.loggers import CSVLogger


def test_v2_0_0_unsupported_agg_and_log_metrics(tmpdir):
class AggAndLogMetricsLogger(CSVLogger):
def agg_and_log_metrics(self, metrics, step):
pass

model = BoringModel()
logger = AggAndLogMetricsLogger(tmpdir)

trainer = Trainer(logger=logger)

with pytest.raises(
RuntimeError,
match="`AggAndLogMetricsLogger.agg_and_log_metrics` was deprecated in v1.6 and is no longer supported",
):
trainer.fit(model)


def test_v2_0_0_unsupported_update_agg_funcs(tmpdir):
class UpdateAggFuncsLogger(CSVLogger):
def update_agg_funcs(self, metrics, step):
pass

model = BoringModel()
logger = UpdateAggFuncsLogger(tmpdir)

trainer = Trainer(logger=logger)

with pytest.raises(
RuntimeError,
match="`UpdateAggFuncsLogger.update_agg_funcs` was deprecated in v1.6 and is no longer supported",
):
trainer.fit(model)


def test_v2_0_0_unsupported_logger_collection_class():
from pytorch_lightning.loggers.base import LoggerCollection

with pytest.raises(RuntimeError, match="`LoggerCollection` was deprecated in v1.6 and removed in v1.8."):
LoggerCollection(None)

from pytorch_lightning.loggers.logger import LoggerCollection

with pytest.raises(RuntimeError, match="`LoggerCollection` was deprecated in v1.6 and removed in v1.8."):
LoggerCollection(None)