Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
Raise exceptions when torch distributed is not available (Lightning-A…
Browse files Browse the repository at this point in the history
…I#10418)

* Raise exceptions when torch distributed is not avalible

* add changelog
  • Loading branch information
four4fish authored and Raalsky committed Nov 23, 2021
1 parent e7a4a12 commit 13dc9c2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Changed

-
- Raise exception in `init_dist_connection()` when torch distibuted is not available ([#10418](https://github.com/PyTorchLightning/pytorch-lightning/issues/10418))


-
Expand Down
4 changes: 3 additions & 1 deletion pytorch_lightning/utilities/distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,9 @@ def init_dist_connection(
world_size = world_size if world_size is not None else cluster_environment.world_size()
os.environ["MASTER_ADDR"] = cluster_environment.main_address
os.environ["MASTER_PORT"] = str(cluster_environment.main_port)
if torch.distributed.is_available() and not torch.distributed.is_initialized():
if not torch.distributed.is_available():
raise RuntimeError("torch.distributed is not available. Cannot initialize distributed process group")
if not torch.distributed.is_initialized():
log.info(f"initializing distributed: GLOBAL_RANK: {global_rank}, MEMBER: {global_rank + 1}/{world_size}")
torch.distributed.init_process_group(
torch_distributed_backend, rank=global_rank, world_size=world_size, **kwargs
Expand Down

0 comments on commit 13dc9c2

Please sign in to comment.