From 9131748f9d4f127eb5ea2313e2350cf592c6ef20 Mon Sep 17 00:00:00 2001 From: Carlos Mocholi Date: Tue, 22 Jun 2021 23:01:56 +0200 Subject: [PATCH 1/3] Deprecate moved warning functions --- pytorch_lightning/utilities/distributed.py | 18 ++++++++++++++++++ tests/deprecated_api/test_remove_1-6.py | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/pytorch_lightning/utilities/distributed.py b/pytorch_lightning/utilities/distributed.py index eb35cdec6c13d..93c65fca52558 100644 --- a/pytorch_lightning/utilities/distributed.py +++ b/pytorch_lightning/utilities/distributed.py @@ -65,6 +65,24 @@ def _get_rank() -> int: rank_zero_only.rank = getattr(rank_zero_only, 'rank', _get_rank()) +def rank_zero_warn(*args, stacklevel: int = 5, **kwargs): + from pytorch_lightning.utilities.warnings import rank_zero_deprecation, rank_zero_warn + rank_zero_deprecation( + '`pytorch_lightning.utilities.distributed.rank_zero_warn` has been moved to' + ' `pytorch_lightning.utilities.rank_zero_warn` in v1.3.8 and will be removed in v1.6' + ) + return rank_zero_warn(*args, stacklevel=stacklevel, **kwargs) + + +def rank_zero_deprecation(*args, stacklevel: int = 5, **kwargs): + from pytorch_lightning.utilities.warnings import rank_zero_deprecation + rank_zero_deprecation( + '`pytorch_lightning.utilities.distributed.rank_zero_warn` has been moved to' + ' `pytorch_lightning.utilities.rank_zero_warn` in v1.3.8 and will be removed in v1.6' + ) + return rank_zero_deprecation(*args, stacklevel=stacklevel, **kwargs) + + def _info(*args, stacklevel: int = 2, **kwargs): if python_version() >= "3.8.0": kwargs['stacklevel'] = stacklevel diff --git a/tests/deprecated_api/test_remove_1-6.py b/tests/deprecated_api/test_remove_1-6.py index d4974eac2f527..892cfeffe474f 100644 --- a/tests/deprecated_api/test_remove_1-6.py +++ b/tests/deprecated_api/test_remove_1-6.py @@ -17,6 +17,7 @@ from pytorch_lightning import Trainer from pytorch_lightning.callbacks.early_stopping import EarlyStopping from pytorch_lightning.plugins.training_type import DDPPlugin, DDPSpawnPlugin +from pytorch_lightning.utilities.distributed import rank_zero_deprecation, rank_zero_warn from pytorch_lightning.utilities.model_helpers import is_overridden from tests.helpers import BoringDataModule, BoringModel @@ -235,3 +236,10 @@ def test_v1_6_0_train_loop(tmpdir): match=r"`Trainer.train_loop` has been renamed to `Trainer.fit_loop` and will be removed in v1.6." ): _ = trainer.train_loop + + +def test_v1_6_0_rank_zero_warnings_moved(): + with pytest.deprecated_call(match='in v1.3.8 and will be removed in v1.6'): + rank_zero_warn('test') + with pytest.deprecated_call(match='in v1.3.8 and will be removed in v1.6'): + rank_zero_deprecation('test') From a0d55dd34468731440e4e571141273a145291086 Mon Sep 17 00:00:00 2001 From: Carlos Mocholi Date: Tue, 22 Jun 2021 23:06:28 +0200 Subject: [PATCH 2/3] CHANGELOG --- CHANGELOG.md | 3 +++ pytorch_lightning/utilities/distributed.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29daa1a0748c4..ac6df041869a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -234,6 +234,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Deprecated default value of `monitor` argument in EarlyStopping callback to enforce `monitor` as a required argument ([#7907](https://github.com/PyTorchLightning/pytorch-lightning/pull/7907)) +- Deprecated importing `rank_zero_{warn,deprecation}` directly from `pytorch_lightning.utilities.distributed` ([#8085](https://github.com/PyTorchLightning/pytorch-lightning/pull/8085)) + + - Deprecated the use of `CheckpointConnector.hpc_load()` in favor of `CheckpointConnector.restore()` ([#7652](https://github.com/PyTorchLightning/pytorch-lightning/pull/7652)) diff --git a/pytorch_lightning/utilities/distributed.py b/pytorch_lightning/utilities/distributed.py index 93c65fca52558..241bb180bdaf6 100644 --- a/pytorch_lightning/utilities/distributed.py +++ b/pytorch_lightning/utilities/distributed.py @@ -77,8 +77,8 @@ def rank_zero_warn(*args, stacklevel: int = 5, **kwargs): def rank_zero_deprecation(*args, stacklevel: int = 5, **kwargs): from pytorch_lightning.utilities.warnings import rank_zero_deprecation rank_zero_deprecation( - '`pytorch_lightning.utilities.distributed.rank_zero_warn` has been moved to' - ' `pytorch_lightning.utilities.rank_zero_warn` in v1.3.8 and will be removed in v1.6' + '`pytorch_lightning.utilities.distributed.rank_zero_deprecation` has been moved to' + ' `pytorch_lightning.utilities.rank_zero_deprecation` in v1.3.8 and will be removed in v1.6' ) return rank_zero_deprecation(*args, stacklevel=stacklevel, **kwargs) From e4e38bb462198a0f5c64bc8e0d0839e9767ad7e6 Mon Sep 17 00:00:00 2001 From: Carlos Mocholi Date: Tue, 22 Jun 2021 23:38:17 +0200 Subject: [PATCH 3/3] Change version number --- pytorch_lightning/utilities/distributed.py | 4 ++-- tests/deprecated_api/test_remove_1-6.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pytorch_lightning/utilities/distributed.py b/pytorch_lightning/utilities/distributed.py index 241bb180bdaf6..ae977bd03bac8 100644 --- a/pytorch_lightning/utilities/distributed.py +++ b/pytorch_lightning/utilities/distributed.py @@ -69,7 +69,7 @@ def rank_zero_warn(*args, stacklevel: int = 5, **kwargs): from pytorch_lightning.utilities.warnings import rank_zero_deprecation, rank_zero_warn rank_zero_deprecation( '`pytorch_lightning.utilities.distributed.rank_zero_warn` has been moved to' - ' `pytorch_lightning.utilities.rank_zero_warn` in v1.3.8 and will be removed in v1.6' + ' `pytorch_lightning.utilities.rank_zero_warn` in v1.3.7 and will be removed in v1.6' ) return rank_zero_warn(*args, stacklevel=stacklevel, **kwargs) @@ -78,7 +78,7 @@ def rank_zero_deprecation(*args, stacklevel: int = 5, **kwargs): from pytorch_lightning.utilities.warnings import rank_zero_deprecation rank_zero_deprecation( '`pytorch_lightning.utilities.distributed.rank_zero_deprecation` has been moved to' - ' `pytorch_lightning.utilities.rank_zero_deprecation` in v1.3.8 and will be removed in v1.6' + ' `pytorch_lightning.utilities.rank_zero_deprecation` in v1.3.7 and will be removed in v1.6' ) return rank_zero_deprecation(*args, stacklevel=stacklevel, **kwargs) diff --git a/tests/deprecated_api/test_remove_1-6.py b/tests/deprecated_api/test_remove_1-6.py index 892cfeffe474f..4868a938dd38d 100644 --- a/tests/deprecated_api/test_remove_1-6.py +++ b/tests/deprecated_api/test_remove_1-6.py @@ -239,7 +239,7 @@ def test_v1_6_0_train_loop(tmpdir): def test_v1_6_0_rank_zero_warnings_moved(): - with pytest.deprecated_call(match='in v1.3.8 and will be removed in v1.6'): + with pytest.deprecated_call(match='in v1.3.7 and will be removed in v1.6'): rank_zero_warn('test') - with pytest.deprecated_call(match='in v1.3.8 and will be removed in v1.6'): + with pytest.deprecated_call(match='in v1.3.7 and will be removed in v1.6'): rank_zero_deprecation('test')