From c5938f8fbc9d942986718b0973afe27eaedaa8bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mochol=C3=AD?= Date: Wed, 25 May 2022 12:23:41 +0200 Subject: [PATCH] Fix torchelastic detection with non-distributed installations (#13142) * Fix torchelastic detection under Mac * CHANGELOG --- CHANGELOG.md | 3 +++ .../plugins/environments/torchelastic_environment.py | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbc513279f..7257b8157d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -223,6 +223,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Avoid redundant callback restore warning while tuning ([#13026](https://github.com/PyTorchLightning/pytorch-lightning/pull/13026)) +- Fixed torchelastic detection with non-distributed installations ([#13142](https://github.com/PyTorchLightning/pytorch-lightning/pull/13142)) + + - Fixed an issue wrt unnecessary usage of habana mixed precision package for fp32 types ([#13028](https://github.com/PyTorchLightning/pytorch-lightning/pull/13028)) diff --git a/pytorch_lightning/plugins/environments/torchelastic_environment.py b/pytorch_lightning/plugins/environments/torchelastic_environment.py index 1740d529c6..98cad39a0a 100644 --- a/pytorch_lightning/plugins/environments/torchelastic_environment.py +++ b/pytorch_lightning/plugins/environments/torchelastic_environment.py @@ -62,7 +62,8 @@ class TorchElasticEnvironment(ClusterEnvironment): def detect() -> bool: """Returns ``True`` if the current process was launched using the torchelastic command.""" if _TORCH_GREATER_EQUAL_1_9_1: - return torch.distributed.is_torchelastic_launched() + # if not available (for example on MacOS), `is_torchelastic_launched` is not defined + return torch.distributed.is_available() and torch.distributed.is_torchelastic_launched() required_env_vars = {"RANK", "GROUP_RANK", "LOCAL_RANK", "LOCAL_WORLD_SIZE"} return required_env_vars.issubset(os.environ.keys())