From 41b0ffe1f4f8b4d0fd94b2791bf75b3cdb0e975f 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 | 1 + .../plugins/environments/torchelastic_environment.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93c5389e84..5ec3e7e8f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Fixed the number of references of `LightningModule` so it can be deleted ([#12897](https://github.com/PyTorchLightning/pytorch-lightning/pull/12897)) - Fixed `materialize_module` setting a module's child recursively ([#12870](https://github.com/PyTorchLightning/pytorch-lightning/pull/12870)) - Fixed issue where the CLI could not pass a `Profiler` to the `Trainer` ([#13084](https://github.com/PyTorchLightning/pytorch-lightning/pull/13084)) +- Fixed torchelastic detection with non-distributed installations ([#13142](https://github.com/PyTorchLightning/pytorch-lightning/pull/13142)) ## [1.6.3] - 2022-05-03 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())