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

Deprecate LightningLoggerBase.close #9422

Merged
merged 27 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1467afe
deprecate loggerbase.close
jjenniferdai Sep 9, 2021
4ce8cca
deprecate warning
jjenniferdai Sep 9, 2021
535b990
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 9, 2021
637dbcd
add to changelog
jjenniferdai Sep 9, 2021
06d7646
Merge branch 'deprecate-loggerbase-close' of https://github.com/jjenn…
jjenniferdai Sep 9, 2021
dc1da14
fix import
jjenniferdai Sep 9, 2021
0e3474a
fix import alphabetize
jjenniferdai Sep 9, 2021
76f1c26
spacing?
jjenniferdai Sep 10, 2021
c8f4618
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 10, 2021
c707a9f
copy-paste avoid pre-commit.ci?
jjenniferdai Sep 10, 2021
d6d16ff
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 10, 2021
5c77e69
literally match the other comment
jjenniferdai Sep 10, 2021
dcb62e6
unindent
jjenniferdai Sep 10, 2021
f6889e0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 10, 2021
843e72c
suggest finalize instead of save
jjenniferdai Sep 10, 2021
6d12d69
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 10, 2021
df63517
Update tests/loggers/test_base.py
ananthsub Sep 10, 2021
237bad8
format but to be formatted
jjenniferdai Sep 10, 2021
bf8d22e
Update pytorch_lightning/loggers/base.py
awaelchli Sep 11, 2021
28540e7
Merge branch 'master' into deprecate-loggerbase-close
awaelchli Sep 11, 2021
9b4ada8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 11, 2021
5bf9f62
Update pytorch_lightning/loggers/base.py
awaelchli Sep 12, 2021
dd0f947
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 12, 2021
651196c
Update pytorch_lightning/loggers/base.py
tchaton Sep 14, 2021
d0f7ae7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 14, 2021
0b1a55c
Merge branch 'master' into deprecate-loggerbase-close
awaelchli Sep 14, 2021
1c6aea8
extra line
jjenniferdai Sep 20, 2021
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Deprecated passing `process_position` to the `Trainer` constructor in favor of adding the `ProgressBar` callback with `process_position` directly to the list of callbacks ([#9222](https://github.com/PyTorchLightning/pytorch-lightning/pull/9222))


- Deprecated `LightningLoggerBase.close`, `LoggerCollection.close` in favor of `LightningLoggerBase.finalize`, `LoggerCollection.finalize` ([#9422](https://github.com/PyTorchLightning/pytorch-lightning/pull/9422))




### Removed

Expand Down
20 changes: 19 additions & 1 deletion pytorch_lightning/loggers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import pytorch_lightning as pl
from pytorch_lightning.callbacks.model_checkpoint import ModelCheckpoint
from pytorch_lightning.utilities import rank_zero_only
from pytorch_lightning.utilities.warnings import rank_zero_deprecation


def rank_zero_experiment(fn: Callable) -> Callable:
Expand Down Expand Up @@ -310,7 +311,15 @@ def finalize(self, status: str) -> None:
self.save()

def close(self) -> None:
"""Do any cleanup that is necessary to close an experiment."""
"""Do any cleanup that is necessary to close an experiment.

.. deprecated:: v1.5 This method is deprecated in v1.5 and will be removed in v1.7. Please use
`LightningLoggerBase.finalize` instead.
tchaton marked this conversation as resolved.
Show resolved Hide resolved
"""
rank_zero_deprecation(
"`LightningLoggerBase.close` method is deprecated in v1.5 and will be removed in v1.7."
" Please use `LightningLoggerBase.finalize` instead."
)
self.save()

@property
Expand Down Expand Up @@ -392,6 +401,15 @@ def finalize(self, status: str) -> None:
logger.finalize(status)

def close(self) -> None:
"""
.. deprecated:: v1.5
This method is deprecated in v1.5 and will be removed in v1.7.
Please use `LoggerCollection.finalize` instead.
"""
rank_zero_deprecation(
"`LoggerCollection.close` method is deprecated in v1.5 and will be removed in v1.7."
" Please use `LoggerCollection.finalize` instead."
)
for logger in self._logger_iterable:
logger.close()

ananthsub marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
16 changes: 15 additions & 1 deletion tests/deprecated_api/test_remove_1-7.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
import torch

from pytorch_lightning import Callback, LightningDataModule, Trainer
from pytorch_lightning.loggers import TestTubeLogger
from pytorch_lightning.loggers import LoggerCollection, TestTubeLogger
from tests.deprecated_api import _soft_unimport_module
from tests.helpers import BoringModel
from tests.helpers.datamodules import MNISTDataModule
from tests.helpers.runif import RunIf
from tests.loggers.test_base import CustomLogger


def test_v1_7_0_deprecated_lightning_module_summarize(tmpdir):
Expand Down Expand Up @@ -219,3 +220,16 @@ def test_v1_7_0_deprecate_add_get_queue(tmpdir):

with pytest.deprecated_call(match=r"`LightningModule.get_from_queue` method was deprecated in v1.5"):
trainer.fit(model)


def test_v1_7_0_lightning_logger_base_close(tmpdir):
logger = CustomLogger()
with pytest.deprecated_call(
match="`LightningLoggerBase.close` method is deprecated in v1.5 and will be removed in v1.7."
):
logger.close()
with pytest.deprecated_call(
match="`LoggerCollection.close` method is deprecated in v1.5 and will be removed in v1.7."
):
logger = LoggerCollection([logger])
logger.close()
8 changes: 4 additions & 4 deletions tests/loggers/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def test_logger_collection():
mock1.agg_and_log_metrics.assert_called_once_with({"test": 2.0}, 4)
mock2.agg_and_log_metrics.assert_called_once_with({"test": 2.0}, 4)

logger.close()
mock1.close.assert_called_once()
mock2.close.assert_called_once()
logger.finalize("success")
mock1.finalize.assert_called_once()
mock2.finalize.assert_called_once()


class CustomLogger(LightningLoggerBase):
Expand Down Expand Up @@ -208,7 +208,7 @@ def log_metrics(self, metrics, step):
logger.agg_and_log_metrics({"loss": loss}, step=int(i / 5))

assert logger.history == {0: {"loss": 0.5623850983416314}}
logger.close()
logger.save()
assert logger.history == {0: {"loss": 0.5623850983416314}, 1: {"loss": 0.4778883735637184}}


Expand Down