Skip to content

Commit 7938293

Browse files
committed
Add deprecation path for the old Loop module (Lightning-AI#13043)
1 parent a8a6a5b commit 7938293

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
9696

9797
- 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))
9898

99-
100-
- Changed `pytorch_lightning.core.lightning` to `pytorch_lightning.core.module` ([#12740](https://github.com/PyTorchLightning/pytorch-lightning/pull/12740))
101-
10299
### Deprecated
103100

104101
- 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))
@@ -116,6 +113,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
116113
- Deprecated `pytorch_lightning.core.lightning.LightningModule` in favor of `pytorch_lightning.core.module.LightningModule` ([#12740](https://github.com/PyTorchLightning/pytorch-lightning/pull/12740))
117114

118115

116+
- Deprecated `pytorch_lightning.loops.base.Loop` in favor of `pytorch_lightning.loops.loop.Loop` ([#13043](https://github.com/PyTorchLightning/pytorch-lightning/pull/13043))
117+
118+
119119
- Deprecated `Trainer.reset_train_val_dataloaders()` in favor of `Trainer.reset_{train,val}_dataloader` ([#12184](https://github.com/PyTorchLightning/pytorch-lightning/pull/12184))
120120

121121
### Removed

pytorch_lightning/loops/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
15-
from pytorch_lightning.loops.batch import ManualOptimization # noqa: F401
14+
from pytorch_lightning.loops.loop import Loop # noqa: F401 isort: skip (avoids circular imports)
1615
from pytorch_lightning.loops.batch import TrainingBatchLoop # noqa: F401
1716
from pytorch_lightning.loops.dataloader import DataLoaderLoop, EvaluationLoop, PredictionLoop # noqa: F401
1817
from pytorch_lightning.loops.epoch import EvaluationEpochLoop, PredictionEpochLoop, TrainingEpochLoop # noqa: F401
1918
from pytorch_lightning.loops.fit_loop import FitLoop # noqa: F401
20-
from pytorch_lightning.loops.loop import Loop # noqa: F401
21-
from pytorch_lightning.loops.optimization.optimizer_loop import OptimizerLoop # noqa: F401
19+
from pytorch_lightning.loops.optimization import ManualOptimization, OptimizerLoop # noqa: F401

pytorch_lightning/loops/base.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright The PyTorch Lightning team.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
from pytorch_lightning.loops import Loop as NewLoop
15+
from pytorch_lightning.utilities.rank_zero import rank_zero_deprecation
16+
17+
18+
class Loop(NewLoop):
19+
def __init__(self) -> None:
20+
rank_zero_deprecation(
21+
"pytorch_lightning.loops.base.Loop has been deprecated in v1.7"
22+
" and will be removed in v1.9."
23+
" Use the equivalent class from the pytorch_lightning.loops.loop.Loop class instead."
24+
)
25+
super().__init__()

tests/deprecated_api/test_remove_1-9.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,23 @@ def test_old_lightningmodule_path():
9595
LightningModule()
9696

9797

98+
def test_old_loop_path():
99+
from pytorch_lightning.loops.base import Loop
100+
101+
class MyLoop(Loop):
102+
def advance(self):
103+
...
104+
105+
def done(self):
106+
...
107+
108+
def reset(self):
109+
...
110+
111+
with pytest.deprecated_call(match="pytorch_lightning.loops.base.Loop has been deprecated in v1.7"):
112+
MyLoop()
113+
114+
98115
def test_lightningCLI_seed_everything_default_to_None_deprecation_warning():
99116
with mock.patch("sys.argv", ["any.py"]), pytest.deprecated_call(
100117
match="Setting `LightningCLI.seed_everything_default` to `None` is deprecated in v1.7 "

0 commit comments

Comments
 (0)