Skip to content

Commit 210ff84

Browse files
awaelchlipre-commit-ci[bot]justusschockcarmocca
authored
Mark Trainer.run_stage as protected (#11000)
Co-authored-by: Carlos Mocholí <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Justus Schock <[email protected]> Co-authored-by: Carlos Mocholí <[email protected]>
1 parent c66cd12 commit 210ff84

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
158158
- Deprecated `ModelIO.on_hpc_{save/load}` in favor of `CheckpointHooks.on_{save/load}_checkpoint` ([#10911](https://github.com/PyTorchLightning/pytorch-lightning/pull/10911))
159159

160160

161-
- Deprecated `Trainer.should_rank_save_checkpoint` Trainer property ([#11068](https://github.com/PyTorchLightning/pytorch-lightning/pull/11068))
161+
- Deprecated `Trainer.run_stage` in favor of `Trainer.{fit,validate,test,predict}` ([#11000](https://github.com/PyTorchLightning/pytorch-lightning/pull/11000))
162+
162163

164+
- Deprecated `Trainer.should_rank_save_checkpoint` Trainer property ([#11068](https://github.com/PyTorchLightning/pytorch-lightning/pull/11068))
163165

164166
### Removed
165167

pytorch_lightning/trainer/trainer.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ def _run(
11301130
setup accelerator ||
11311131
and strategy || LIGHTNING
11321132
| ||
1133-
{self.run_stage} || FLOW
1133+
{self._run_stage} || FLOW
11341134
| ||
11351135
{self._run_train} || DIRECTION
11361136
or {self._run_evaluate} ||
@@ -1165,7 +1165,7 @@ def _run(
11651165

11661166
self.checkpoint_connector.resume_end()
11671167

1168-
results = self.run_stage()
1168+
results = self._run_stage()
11691169
self._teardown()
11701170

11711171
# ----------------------------
@@ -1238,7 +1238,14 @@ def _teardown(self):
12381238
self.logger_connector.teardown()
12391239
self.signal_connector.teardown()
12401240

1241-
def run_stage(self):
1241+
def run_stage(self) -> None:
1242+
rank_zero_deprecation(
1243+
"`Trainer.run_stage` is deprecated in v1.6 and will be removed in v1.8. Use"
1244+
" `Trainer.{fit,validate,test,predict}` instead."
1245+
)
1246+
return self._run_stage()
1247+
1248+
def _run_stage(self):
12421249
self.training_type_plugin.barrier("run-stage")
12431250
self.training_type_plugin.dispatch(self)
12441251
self.__setup_profiler()

tests/deprecated_api/test_remove_1-8.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
"""Test deprecated functionality which will be removed in v1.8.0."""
15+
from unittest.mock import Mock
1516

1617
import pytest
1718
import torch
@@ -108,6 +109,13 @@ def on_hpc_load(self):
108109
trainer.fit(load_model)
109110

110111

112+
def test_v1_8_0_deprecated_run_stage():
113+
trainer = Trainer()
114+
trainer._run_stage = Mock()
115+
with pytest.deprecated_call(match="`Trainer.run_stage` is deprecated in v1.6 and will be removed in v1.8."):
116+
trainer.run_stage()
117+
118+
111119
def test_v1_8_0_deprecated_trainer_should_rank_save_checkpoint(tmpdir):
112120
trainer = Trainer()
113121
with pytest.deprecated_call(

0 commit comments

Comments
 (0)