From 75a7c583bfe1e79fb52ef1a375a333203c276325 Mon Sep 17 00:00:00 2001 From: rohitgr7 Date: Thu, 12 May 2022 00:06:31 +0530 Subject: [PATCH] Add deprecation path for the old LightningModule module (#12740) --- CHANGELOG.md | 2 +- pytorch_lightning/core/lightning.py | 27 +++++++++++++++++++++++++ tests/deprecated_api/test_remove_1-9.py | 10 +++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 pytorch_lightning/core/lightning.py diff --git a/CHANGELOG.md b/CHANGELOG.md index e84d5043af33a1..8f350811867623 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -108,7 +108,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Deprecated setting `LightningCLI(seed_everything_default=None)` in favor of `False` ([#12804](https://github.com/PyTorchLightning/pytorch-lightning/issues/12804)). -- +- Deprecated `pytorch_lightning.core.lightning.LightningModule` in favor of `pytorch_lightning.core.module.LightningModule` ([#12740](https://github.com/PyTorchLightning/pytorch-lightning/pull/12740)) - diff --git a/pytorch_lightning/core/lightning.py b/pytorch_lightning/core/lightning.py new file mode 100644 index 00000000000000..bf6fe19c7dfc90 --- /dev/null +++ b/pytorch_lightning/core/lightning.py @@ -0,0 +1,27 @@ +# 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 + +from pytorch_lightning.core.module import LightningModule as NewLightningModule +from pytorch_lightning.utilities import rank_zero_deprecation + + +class LightningModule(NewLightningModule): + def __init__(self, *args: Any, **kwargs: Any) -> None: + rank_zero_deprecation( + "pytorch_lightning.core.lightning.LightningModule has been deprecated in v1.7" + " and will be removed in v1.9." + " Use the equivalent class from the pytorch_lightning.core.module.LightningModule class instead." + ) + super().__init__(*args, **kwargs) diff --git a/tests/deprecated_api/test_remove_1-9.py b/tests/deprecated_api/test_remove_1-9.py index c083c2318b388f..4f52e220a6840c 100644 --- a/tests/deprecated_api/test_remove_1-9.py +++ b/tests/deprecated_api/test_remove_1-9.py @@ -84,6 +84,16 @@ def test_lightning_logger_base_merge_dicts_deprecation_warning(): logger_base.merge_dicts([d1, d2, d3], agg_funcs, dflt_func) +def test_old_lightningmodule_path(): + from pytorch_lightning.core.lightning import LightningModule + + with pytest.deprecated_call( + match="pytorch_lightning.core.lightning.LightningModule has been deprecated in v1.7" + " and will be removed in v1.9." + ): + LightningModule() + + def test_lightningCLI_seed_everything_default_to_None_deprecation_warning(): with mock.patch("sys.argv", ["any.py"]), pytest.deprecated_call( match="Setting `LightningCLI.seed_everything_default` to `None` is deprecated in v1.7 "