Skip to content

Commit

Permalink
Add deprecation path for the old LightningModule module (#12740)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitgr7 committed May 12, 2022
1 parent 9e5e88e commit 75a7c58
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))


-
Expand Down
27 changes: 27 additions & 0 deletions pytorch_lightning/core/lightning.py
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 10 additions & 0 deletions tests/deprecated_api/test_remove_1-9.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down

0 comments on commit 75a7c58

Please sign in to comment.