Skip to content

Commit

Permalink
Add deprecation path for the old Loop module (#13043)
Browse files Browse the repository at this point in the history
  • Loading branch information
carmocca committed Jun 2, 2022
1 parent e296e4c commit 2a27c6f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

- Raise an error if there are insufficient training batches when using a float value of `limit_train_batches` ([#12885](https://github.com/PyTorchLightning/pytorch-lightning/pull/12885))


- Changed `pytorch_lightning.core.lightning` to `pytorch_lightning.core.module` ([#12740](https://github.com/PyTorchLightning/pytorch-lightning/pull/12740))

### Deprecated

- Deprecated `pytorch_lightning.loggers.base.LightningLoggerBase` in favor of `pytorch_lightning.loggers.logger.Logger`, and deprecated `pytorch_lightning.loggers.base` in favor of `pytorch_lightning.loggers.logger` ([#120148](https://github.com/PyTorchLightning/pytorch-lightning/pull/12014))
Expand All @@ -116,6 +113,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Deprecated `pytorch_lightning.core.lightning.LightningModule` in favor of `pytorch_lightning.core.module.LightningModule` ([#12740](https://github.com/PyTorchLightning/pytorch-lightning/pull/12740))


- Deprecated `pytorch_lightning.loops.base.Loop` in favor of `pytorch_lightning.loops.loop.Loop` ([#13043](https://github.com/PyTorchLightning/pytorch-lightning/pull/13043))


- Deprecated `Trainer.reset_train_val_dataloaders()` in favor of `Trainer.reset_{train,val}_dataloader` ([#12184](https://github.com/PyTorchLightning/pytorch-lightning/pull/12184))

### Removed
Expand Down
6 changes: 2 additions & 4 deletions pytorch_lightning/loops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
# 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.loops.batch import ManualOptimization # noqa: F401
from pytorch_lightning.loops.loop import Loop # noqa: F401 isort: skip (avoids circular imports)
from pytorch_lightning.loops.batch import TrainingBatchLoop # noqa: F401
from pytorch_lightning.loops.dataloader import DataLoaderLoop, EvaluationLoop, PredictionLoop # noqa: F401
from pytorch_lightning.loops.epoch import EvaluationEpochLoop, PredictionEpochLoop, TrainingEpochLoop # noqa: F401
from pytorch_lightning.loops.fit_loop import FitLoop # noqa: F401
from pytorch_lightning.loops.loop import Loop # noqa: F401
from pytorch_lightning.loops.optimization.optimizer_loop import OptimizerLoop # noqa: F401
from pytorch_lightning.loops.optimization import ManualOptimization, OptimizerLoop # noqa: F401
25 changes: 25 additions & 0 deletions pytorch_lightning/loops/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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 pytorch_lightning.loops import Loop as NewLoop
from pytorch_lightning.utilities.rank_zero import rank_zero_deprecation


class Loop(NewLoop):
def __init__(self) -> None:
rank_zero_deprecation(
"pytorch_lightning.loops.base.Loop has been deprecated in v1.7"
" and will be removed in v1.9."
" Use the equivalent class from the pytorch_lightning.loops.loop.Loop class instead."
)
super().__init__()
17 changes: 17 additions & 0 deletions tests/deprecated_api/test_remove_1-9.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@ def test_old_lightningmodule_path():
LightningModule()


def test_old_loop_path():
from pytorch_lightning.loops.base import Loop

class MyLoop(Loop):
def advance(self):
...

def done(self):
...

def reset(self):
...

with pytest.deprecated_call(match="pytorch_lightning.loops.base.Loop has been deprecated in v1.7"):
MyLoop()


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 2a27c6f

Please sign in to comment.