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

Function pytorch_worker_info

sat/sgm/webds.py:17–42  ·  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

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

Callers 1

pytorch_worker_seedFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected