Skip to content

Commit

Permalink
Add dist env detection via env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
gkroiz committed Apr 8, 2024
1 parent 95111cd commit 876a65d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/litdata/utilities/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,16 @@ def detect(cls) -> "_DistributedEnv":
global_rank = 0
num_nodes = 1

if world_size is None or world_size == -1:
if os.environ["WORLD_SIZE"] is not None:
world_size = os.environ["WORLD_SIZE"]

if os.environ["GLOBAL_RANK"] is not None:
global_rank = os.environ["GLOBAL_RANK"]

if os.environ["NNODES"] is not None:
num_nodes = os.environ["NNODES"]

if world_size is in [None, -1, 0]:
world_size = 1

return cls(world_size=world_size, global_rank=global_rank, num_nodes=num_nodes)
Expand Down

0 comments on commit 876a65d

Please sign in to comment.