From 0423771c9acbb42dec2e1aeeba715fa234415f62 Mon Sep 17 00:00:00 2001 From: shantam-8 Date: Sun, 3 Jul 2022 01:21:18 +0100 Subject: [PATCH 1/5] Removal of depreciated code from decorators --- src/pytorch_lightning/core/decorators.py | 8 +------- tests/tests_pytorch/deprecated_api/test_remove_1-7.py | 9 --------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/src/pytorch_lightning/core/decorators.py b/src/pytorch_lightning/core/decorators.py index 33c83b4b10d6d..67e5c104e0065 100644 --- a/src/pytorch_lightning/core/decorators.py +++ b/src/pytorch_lightning/core/decorators.py @@ -11,13 +11,7 @@ # 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 pytorch_lightning.utilities.rank_zero import rank_zero_deprecation, rank_zero_warn - -rank_zero_deprecation( - "Using `pytorch_lightning.core.decorators.parameter_validation` is deprecated in v1.5, " - "and will be removed in v1.7. It has been replaced by automatic parameters tying with " - "`pytorch_lightning.utilities.params_tying.set_shared_parameters`" -) +from pytorch_lightning.utilities.rank_zero import rank_zero_warn from functools import wraps # noqa: E402 from typing import Callable # noqa: E402 diff --git a/tests/tests_pytorch/deprecated_api/test_remove_1-7.py b/tests/tests_pytorch/deprecated_api/test_remove_1-7.py index 0cc1473e79ab9..56bdd05478fd3 100644 --- a/tests/tests_pytorch/deprecated_api/test_remove_1-7.py +++ b/tests/tests_pytorch/deprecated_api/test_remove_1-7.py @@ -99,15 +99,6 @@ def on_post_move_to_device(self): trainer.fit(model) -def test_v1_7_0_deprecate_parameter_validation(): - - _soft_unimport_module("pytorch_lightning.core.decorators") - with pytest.deprecated_call( - match="Using `pytorch_lightning.core.decorators.parameter_validation` is deprecated in v1.5" - ): - from pytorch_lightning.core.decorators import parameter_validation # noqa: F401 - - def test_v1_7_0_deprecated_slurm_job_id(): trainer = Trainer() with pytest.deprecated_call(match="Method `slurm_job_id` is deprecated in v1.6.0 and will be removed in v1.7.0."): From 946e22f90f2956c9bde98ff45e65cb0a48da63d6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 3 Jul 2022 00:51:20 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/pytorch_lightning/core/decorators.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pytorch_lightning/core/decorators.py b/src/pytorch_lightning/core/decorators.py index 67e5c104e0065..6408e5464aee8 100644 --- a/src/pytorch_lightning/core/decorators.py +++ b/src/pytorch_lightning/core/decorators.py @@ -11,10 +11,10 @@ # 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 pytorch_lightning.utilities.rank_zero import rank_zero_warn +from functools import wraps +from typing import Callable -from functools import wraps # noqa: E402 -from typing import Callable # noqa: E402 +from pytorch_lightning.utilities.rank_zero import rank_zero_warn def parameter_validation(fn: Callable) -> Callable: From 56da19868d33851ad1f24702d6bb0385c0b80164 Mon Sep 17 00:00:00 2001 From: Shantam Gilra <64306405+shantam-8@users.noreply.github.com> Date: Sun, 3 Jul 2022 02:28:20 +0100 Subject: [PATCH 3/5] Correction --- src/pytorch_lightning/core/decorators.py | 54 ------------------------ 1 file changed, 54 deletions(-) delete mode 100644 src/pytorch_lightning/core/decorators.py diff --git a/src/pytorch_lightning/core/decorators.py b/src/pytorch_lightning/core/decorators.py deleted file mode 100644 index 6408e5464aee8..0000000000000 --- a/src/pytorch_lightning/core/decorators.py +++ /dev/null @@ -1,54 +0,0 @@ -# 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 functools import wraps -from typing import Callable - -from pytorch_lightning.utilities.rank_zero import rank_zero_warn - - -def parameter_validation(fn: Callable) -> Callable: - """Validates that the module parameter lengths match after moving to the device. It is useful when tying - weights on TPU's. - - Args: - fn: ``model_to_device`` method - - Note: - TPU's require weights to be tied/shared after moving the module to the device. - Failure to do this results in the initialization of new weights which are not tied. - To overcome this issue, weights should be tied using the ``on_post_move_to_device`` model hook - which is called after the module has been moved to the device. - - See Also: - - `XLA Documentation `_ - """ - - @wraps(fn) - def inner_fn(self, *args, **kwargs): - pre_layer_count = len(list(self.model.parameters())) - module = fn(self, *args, **kwargs) - self.model.on_post_move_to_device() - post_layer_count = len(list(self.model.parameters())) - - if not pre_layer_count == post_layer_count: - rank_zero_warn( - "The model layers do not match after moving to the target device." - " If your model employs weight sharing on TPU," - " please tie your weights using the `on_post_move_to_device` model hook.\n" - f"Layer count: [Before: {pre_layer_count} After: {post_layer_count}]" - ) - - return module - - return inner_fn From 6db5271758199337ee5c302f7cfc2240f9c1b9cb Mon Sep 17 00:00:00 2001 From: Shantam Gilra <64306405+shantam-8@users.noreply.github.com> Date: Sun, 3 Jul 2022 02:30:15 +0100 Subject: [PATCH 4/5] Update CHANGELOG.md --- src/pytorch_lightning/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pytorch_lightning/CHANGELOG.md b/src/pytorch_lightning/CHANGELOG.md index 38da5a36a40ab..c604712e41771 100644 --- a/src/pytorch_lightning/CHANGELOG.md +++ b/src/pytorch_lightning/CHANGELOG.md @@ -174,6 +174,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Removed +- Removed deprecated `pytorch_lightning.core.decorators.parameter_validation` from `decorators` ([#13514](https://github.com/Lightning-AI/lightning/pull/13514)) + + - Removed the deprecated `Logger.close` method ([#13149](https://github.com/PyTorchLightning/pytorch-lightning/pull/13149)) From db374ab157549bddfbef4a33e12becd5012dd553 Mon Sep 17 00:00:00 2001 From: Shantam Gilra <64306405+shantam-8@users.noreply.github.com> Date: Sun, 3 Jul 2022 10:53:58 +0100 Subject: [PATCH 5/5] Removed imports --- tests/tests_pytorch/deprecated_api/test_remove_1-7.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/tests_pytorch/deprecated_api/test_remove_1-7.py b/tests/tests_pytorch/deprecated_api/test_remove_1-7.py index 56bdd05478fd3..708e040ca72bc 100644 --- a/tests/tests_pytorch/deprecated_api/test_remove_1-7.py +++ b/tests/tests_pytorch/deprecated_api/test_remove_1-7.py @@ -31,7 +31,6 @@ TorchElasticEnvironment, ) from pytorch_lightning.strategies import SingleDeviceStrategy -from tests_pytorch.deprecated_api import _soft_unimport_module from tests_pytorch.plugins.environments.test_lsf_environment import _make_rankfile