MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / pytorch_worker_info

Function pytorch_worker_info

SwissArmyTransformer/sat/data_utils/webds.py:20–45  ·  view source on GitHub ↗

Return node and worker info for PyTorch and some distributed environments.

(group=None)

Source from the content-addressed store, hash-verified

18from webdataset.gopen import gopen_schemes, gopen
19
20def pytorch_worker_info(group=None): # sourcery skip: use-contextlib-suppress
21 """Return node and worker info for PyTorch and some distributed environments."""
22 rank = 0
23 world_size = 1
24 worker = 0
25 num_workers = 1
26 try:
27 import torch.distributed
28
29 if torch.distributed.is_available() and torch.distributed.is_initialized():
30 group = group or torch.distributed.group.WORLD
31 rank = torch.distributed.get_rank(group=group)
32 world_size = torch.distributed.get_world_size(group=group)
33 except ModuleNotFoundError:
34 pass
35 try:
36 import torch.utils.data
37
38 worker_info = torch.utils.data.get_worker_info()
39 if worker_info is not None:
40 worker = worker_info.id
41 num_workers = worker_info.num_workers
42 except ModuleNotFoundError:
43 pass
44
45 return rank, world_size, worker, num_workers
46
47
48def pytorch_worker_seed(group=None):

Callers 1

pytorch_worker_seedFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected