Skip to content

Commit 21a5867

Browse files
awaelchlitchaton
andauthored
Rename ClusterEnvironment.creates_processes (#10106)
Co-authored-by: tchaton <[email protected]>
1 parent f162335 commit 21a5867

17 files changed

+67
-20
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
435435
- Deprecated passing `resume_from_checkpoint` to the `Trainer` constructor in favor of `trainer.fit(ckpt_path=)` ([#10061](https://github.com/PyTorchLightning/pytorch-lightning/pull/10061))
436436

437437

438+
- Deprecated `ClusterEnvironment.creates_children()` in favor of `ClusterEnvironment.creates_processes_externally` (property) ([#10106](https://github.com/PyTorchLightning/pytorch-lightning/pull/10106))
439+
440+
438441
### Removed
439442

440443
- Removed deprecated `metrics` ([#8586](https://github.com/PyTorchLightning/pytorch-lightning/pull/8586/))

docs/source/clouds/cluster.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,9 @@ and node rank (node id). Here is an example of a custom
290290
291291
292292
class MyClusterEnvironment(ClusterEnvironment):
293-
def creates_children(self) -> bool:
294-
# return True if the cluster is managed (you don't launch processes yourself)
293+
@property
294+
def creates_processes_externally(self) -> bool:
295+
"""Return True if the cluster is managed (you don't launch processes yourself)"""
295296
return True
296297
297298
def world_size(self) -> int:

pytorch_lightning/plugins/environments/cluster_environment.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,30 @@
1313
# limitations under the License.
1414
from abc import ABC, abstractmethod
1515

16+
from pytorch_lightning.utilities import rank_zero_deprecation
17+
1618

1719
class ClusterEnvironment(ABC):
1820
"""Specification of a cluster environment."""
1921

22+
@property
2023
@abstractmethod
21-
def creates_children(self) -> bool:
24+
def creates_processes_externally(self) -> bool:
2225
"""Whether the environment creates the subprocesses or not."""
2326

27+
def creates_children(self) -> bool:
28+
"""Whether the environment creates the subprocesses or not.
29+
30+
.. deprecated:: v1.5
31+
This method was deprecated in v1.5 and will be removed in v1.6. Use the property
32+
:attr:`creates_processes_externally` instead.
33+
"""
34+
rank_zero_deprecation(
35+
f"`{self.__class__.__name__}.creates_children()` was deprecated in v1.5 and will be removed in v1.6."
36+
" Use the property :attr:`creates_processes_externally` instead."
37+
)
38+
return self.creates_processes_externally
39+
2440
@abstractmethod
2541
def master_address(self) -> str:
2642
"""The master address through which all processes connect and communicate."""

pytorch_lightning/plugins/environments/kubeflow_environment.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def is_using_kubeflow() -> bool:
3535
excluded_env_vars = ("GROUP_RANK", "LOCAL_RANK", "LOCAL_WORLD_SIZE")
3636
return all(v in os.environ for v in required_env_vars) and not any(v in os.environ for v in excluded_env_vars)
3737

38-
def creates_children(self) -> bool:
38+
@property
39+
def creates_processes_externally(self) -> bool:
3940
return True
4041

4142
def master_address(self) -> str:

pytorch_lightning/plugins/environments/lightning_environment.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ def __init__(self):
4040
self._global_rank: int = 0
4141
self._world_size: int = 1
4242

43-
def creates_children(self) -> bool:
43+
@property
44+
def creates_processes_externally(self) -> bool:
4445
"""Returns whether the cluster creates the processes or not.
4546
4647
If at least :code:`LOCAL_RANK` is available as environment variable, Lightning assumes the user acts as the

pytorch_lightning/plugins/environments/lsf_environment.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def is_using_lsf() -> bool:
5252
required_env_vars = ("LSB_JOBID", "LSB_HOSTS", "JSM_NAMESPACE_LOCAL_RANK", "JSM_NAMESPACE_SIZE")
5353
return all(v in os.environ for v in required_env_vars)
5454

55-
def creates_children(self) -> bool:
55+
@property
56+
def creates_processes_externally(self) -> bool:
5657
return True
5758

5859
def master_address(self):

pytorch_lightning/plugins/environments/slurm_environment.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
class SLURMEnvironment(ClusterEnvironment):
2525
"""Cluster environment for training on a cluster managed by SLURM."""
2626

27-
def creates_children(self) -> bool:
27+
@property
28+
def creates_processes_externally(self) -> bool:
2829
return True
2930

3031
def master_address(self) -> str:

pytorch_lightning/plugins/environments/torchelastic_environment.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def is_using_torchelastic() -> bool:
3131
required_env_vars = ("RANK", "GROUP_RANK", "LOCAL_RANK", "LOCAL_WORLD_SIZE")
3232
return all(v in os.environ for v in required_env_vars)
3333

34-
def creates_children(self) -> bool:
34+
@property
35+
def creates_processes_externally(self) -> bool:
3536
return True
3637

3738
def master_address(self) -> str:

pytorch_lightning/plugins/training_type/ddp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def _is_single_process_single_device(self) -> bool:
177177

178178
def setup_environment(self) -> None:
179179
# start the other scripts
180-
if not self.cluster_environment.creates_children():
180+
if not self.cluster_environment.creates_processes_externally:
181181
self._call_children_scripts()
182182

183183
# set the task idx
@@ -277,7 +277,7 @@ def _check_can_spawn_children(self):
277277
raise RuntimeError(
278278
"Lightning attempted to launch new distributed processes with `local_rank > 0`. This should not happen."
279279
" Possible reasons: 1) LOCAL_RANK environment variable was incorrectly modified by the user,"
280-
" 2) `ClusterEnvironment.creates_children()` incorrectly implemented."
280+
" 2) `ClusterEnvironment.creates_processes_externally` incorrectly implemented."
281281
)
282282

283283
def set_world_ranks(self) -> None:

tests/accelerators/test_accelerator_connector.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@ class CustomCluster(LightningEnvironment):
369369
def master_address(self):
370370
return "asdf"
371371

372-
def creates_children(self) -> bool:
372+
@property
373+
def creates_processes_externally(self) -> bool:
373374
return True
374375

375376
trainer = Trainer(

0 commit comments

Comments
 (0)