Skip to content

Commit daf7cec

Browse files
Remove deprecated ClustertEnvironment methods (#13458)
* Remove deprecated ClustertEnvironment methods * update changelog * ignore typing error Co-authored-by: Akihiro Nitta <[email protected]>
1 parent feb8e7d commit daf7cec

File tree

9 files changed

+11
-140
lines changed

9 files changed

+11
-140
lines changed

src/pytorch_lightning/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
281281
- Removed support for the `DDP2Strategy` ([#12705](https://github.com/PyTorchLightning/pytorch-lightning/pull/12705))
282282

283283

284+
- Removed deprecated ClusterEnvironment properties `master_address` and `master_port` in favor of `main_address` and `main_port` ([#13458](https://github.com/PyTorchLightning/pytorch-lightning/pull/13458))
285+
286+
287+
- Removed deprecated ClusterEnvironment methods `KubeflowEnvironment.is_using_kubelfow()`, `LSFEnvironment.is_using_lsf()` and `TorchElasticEnvironment.is_using_torchelastic()` in favor of the `detect()` method ([#13458](https://github.com/PyTorchLightning/pytorch-lightning/pull/13458))
288+
289+
284290
- Removed deprecated `Callback.on_keyboard_interrupt` ([#13438](https://github.com/Lightning-AI/lightning/pull/13438))
285291

286292

src/pytorch_lightning/plugins/environments/cluster_environment.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,11 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
from abc import ABC, abstractmethod
15-
from typing import Any, Type
16-
17-
from pytorch_lightning.utilities import rank_zero_deprecation
1815

1916

2017
class ClusterEnvironment(ABC):
2118
"""Specification of a cluster environment."""
2219

23-
def __new__(cls, *args: Any, **kwargs: Any) -> "ClusterEnvironment":
24-
# TODO: remove in 1.7
25-
_check_for_deprecated_methods(cls)
26-
return super().__new__(cls)
27-
2820
@property
2921
@abstractmethod
3022
def creates_processes_externally(self) -> bool:
@@ -72,16 +64,3 @@ def node_rank(self) -> int:
7264
def teardown(self) -> None:
7365
"""Clean up any state set after execution finishes."""
7466
pass
75-
76-
77-
def _check_for_deprecated_methods(cls: Type[ClusterEnvironment]) -> None:
78-
if hasattr(cls, "master_address") and callable(cls.master_address):
79-
rank_zero_deprecation(
80-
f"`{cls.__name__}.master_address` has been deprecated in v1.6 and will be removed in v1.7."
81-
" Implement the property `main_address` instead (do not forget to add the `@property` decorator)."
82-
)
83-
if hasattr(cls, "master_port") and callable(cls.master_port):
84-
rank_zero_deprecation(
85-
f"`{cls.__name__}.master_port` has been deprecated in v1.6 and will be removed in v1.7."
86-
" Implement the property `main_port` instead (do not forget to add the `@property` decorator)."
87-
)

src/pytorch_lightning/plugins/environments/kubeflow_environment.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import os
1717

1818
from pytorch_lightning.plugins.environments.cluster_environment import ClusterEnvironment
19-
from pytorch_lightning.utilities import rank_zero_deprecation
2019

2120
log = logging.getLogger(__name__)
2221

@@ -28,16 +27,6 @@ class KubeflowEnvironment(ClusterEnvironment):
2827
.. _Kubeflow: https://www.kubeflow.org
2928
"""
3029

31-
def __init__(self) -> None:
32-
super().__init__()
33-
# TODO: remove in 1.7
34-
if hasattr(self, "is_using_kubeflow") and callable(self.is_using_kubeflow):
35-
rank_zero_deprecation(
36-
f"`{self.__class__.__name__}.is_using_kubeflow` has been deprecated in v1.6 and will be removed in"
37-
f" v1.7. Implement the static method `detect()` instead (do not forget to add the `@staticmethod`"
38-
f" decorator)."
39-
)
40-
4130
@property
4231
def creates_processes_externally(self) -> bool:
4332
return True

src/pytorch_lightning/plugins/environments/lsf_environment.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
from pytorch_lightning import _logger as log
2020
from pytorch_lightning.plugins.environments import ClusterEnvironment
21-
from pytorch_lightning.utilities import rank_zero_deprecation
2221
from pytorch_lightning.utilities.cloud_io import get_filesystem
2322

2423

@@ -48,12 +47,6 @@ class LSFEnvironment(ClusterEnvironment):
4847

4948
def __init__(self) -> None:
5049
super().__init__()
51-
# TODO: remove in 1.7
52-
if hasattr(self, "is_using_lsf") and callable(self.is_using_lsf):
53-
rank_zero_deprecation(
54-
f"`{self.__class__.__name__}.is_using_lsf` has been deprecated in v1.6 and will be removed in v1.7."
55-
" Implement the static method `detect()` instead (do not forget to add the `@staticmethod` decorator)."
56-
)
5750
self._main_address = self._get_main_address()
5851
self._main_port = self._get_main_port()
5952
self._node_rank = self._get_node_rank()

src/pytorch_lightning/plugins/environments/torchelastic_environment.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,14 @@
1919

2020
from pytorch_lightning.plugins.environments.cluster_environment import ClusterEnvironment
2121
from pytorch_lightning.utilities.imports import _TORCH_GREATER_EQUAL_1_9_1
22-
from pytorch_lightning.utilities.rank_zero import rank_zero_deprecation, rank_zero_warn
22+
from pytorch_lightning.utilities.rank_zero import rank_zero_warn
2323

2424
log = logging.getLogger(__name__)
2525

2626

2727
class TorchElasticEnvironment(ClusterEnvironment):
2828
"""Environment for fault-tolerant and elastic training with `torchelastic <https://pytorch.org/elastic/>`_"""
2929

30-
def __init__(self) -> None:
31-
super().__init__()
32-
# TODO: remove in 1.7
33-
if hasattr(self, "is_using_torchelastic") and callable(self.is_using_torchelastic):
34-
rank_zero_deprecation(
35-
f"`{self.__class__.__name__}.is_using_torchelastic` has been deprecated in v1.6 and will be removed in"
36-
" v1.7. Implement the static method `detect()` instead (do not forget to add the `@staticmethod`"
37-
" decorator)."
38-
)
39-
4030
@property
4131
def creates_processes_externally(self) -> bool:
4232
return True

src/pytorch_lightning/trainer/connectors/accelerator_connector.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,8 @@ def _choose_and_init_cluster_environment(self) -> ClusterEnvironment:
546546
return SLURMEnvironment()
547547
for env_type in (BaguaEnvironment, TorchElasticEnvironment, KubeflowEnvironment, LSFEnvironment):
548548
if env_type.detect():
549-
return env_type()
549+
# Ignore type error because it is a false positive: https://github.com/python/mypy/issues/13044
550+
return env_type() # type: ignore[abstract]
550551
return LightningEnvironment()
551552

552553
def _is_slurm_managing_tasks(self) -> bool:

tests/tests_pytorch/deprecated_api/test_remove_1-7.py

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,13 @@
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.7.0."""
15-
import os
1615
from re import escape
17-
from unittest import mock
1816

1917
import pytest
2018
import torch
2119

2220
from pytorch_lightning import Trainer
23-
from pytorch_lightning.plugins.environments import (
24-
KubeflowEnvironment,
25-
LightningEnvironment,
26-
LSFEnvironment,
27-
SLURMEnvironment,
28-
TorchElasticEnvironment,
29-
)
3021
from pytorch_lightning.strategies import SingleDeviceStrategy
31-
from tests_pytorch.plugins.environments.test_lsf_environment import _make_rankfile
3222

3323

3424
def test_v1_7_0_deprecate_lightning_distributed(tmpdir):
@@ -47,83 +37,6 @@ def test_v1_7_0_deprecated_max_steps_none(tmpdir):
4737
trainer.fit_loop.max_steps = None
4838

4939

50-
@pytest.mark.parametrize(
51-
"cls",
52-
[
53-
KubeflowEnvironment,
54-
LightningEnvironment,
55-
SLURMEnvironment,
56-
TorchElasticEnvironment,
57-
],
58-
)
59-
def test_v1_7_0_cluster_environment_master_address(cls):
60-
class MyClusterEnvironment(cls):
61-
def master_address(self):
62-
pass
63-
64-
with pytest.deprecated_call(
65-
match="MyClusterEnvironment.master_address` has been deprecated in v1.6 and will be removed in v1.7"
66-
):
67-
MyClusterEnvironment()
68-
69-
70-
@pytest.mark.parametrize(
71-
"cls",
72-
[
73-
KubeflowEnvironment,
74-
LightningEnvironment,
75-
SLURMEnvironment,
76-
TorchElasticEnvironment,
77-
],
78-
)
79-
def test_v1_7_0_cluster_environment_master_port(cls):
80-
class MyClusterEnvironment(cls):
81-
def master_port(self):
82-
pass
83-
84-
with pytest.deprecated_call(
85-
match="MyClusterEnvironment.master_port` has been deprecated in v1.6 and will be removed in v1.7"
86-
):
87-
MyClusterEnvironment()
88-
89-
90-
@pytest.mark.parametrize(
91-
"cls,method_name",
92-
[
93-
(KubeflowEnvironment, "is_using_kubeflow"),
94-
(LSFEnvironment, "is_using_lsf"),
95-
(TorchElasticEnvironment, "is_using_torchelastic"),
96-
],
97-
)
98-
def test_v1_7_0_cluster_environment_detection(cls, method_name, tmp_path):
99-
class MyClusterEnvironment(cls):
100-
@staticmethod
101-
def is_using_kubeflow():
102-
pass
103-
104-
@staticmethod
105-
def is_using_lsf():
106-
pass
107-
108-
@staticmethod
109-
def is_using_torchelastic():
110-
pass
111-
112-
environ = {
113-
"LSB_DJOB_RANKFILE": _make_rankfile(tmp_path),
114-
"LSB_JOBID": "1234",
115-
"JSM_NAMESPACE_SIZE": "4",
116-
"JSM_NAMESPACE_RANK": "3",
117-
"JSM_NAMESPACE_LOCAL_RANK": "1",
118-
}
119-
with mock.patch.dict(os.environ, environ):
120-
with mock.patch("socket.gethostname", return_value="10.10.10.2"):
121-
with pytest.deprecated_call(
122-
match=f"MyClusterEnvironment.{method_name}` has been deprecated in v1.6 and will be removed in v1.7"
123-
):
124-
MyClusterEnvironment()
125-
126-
12740
def test_v1_7_0_post_dispatch_hook():
12841
class CustomPlugin(SingleDeviceStrategy):
12942
def post_dispatch(self, trainer):

tests/tests_pytorch/plugins/environments/test_lightning_environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def test_node_rank_from_group_rank():
6666

6767

6868
@mock.patch.dict(os.environ, {}, clear=True)
69-
def test_random_master_port():
69+
def test_random_main_port():
7070
"""Test randomly chosen main port when no main port was given by user."""
7171
env = LightningEnvironment()
7272
port = env.main_port

tests/tests_pytorch/plugins/environments/test_slurm_environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def test_attributes_from_environment_variables(caplog):
8383
"slurm_node_list,expected",
8484
[("alpha,beta,gamma", "alpha"), ("alpha beta gamma", "alpha"), ("1.2.3.[100-110]", "1.2.3.100")],
8585
)
86-
def test_master_address_from_slurm_node_list(slurm_node_list, expected):
86+
def test_main_address_from_slurm_node_list(slurm_node_list, expected):
8787
"""Test extracting the main node from different formats for the SLURM_NODELIST."""
8888
with mock.patch.dict(os.environ, {"SLURM_NODELIST": slurm_node_list}):
8989
env = SLURMEnvironment()

0 commit comments

Comments
 (0)