MCPcopy Create free account
hub / github.com/bic-L/MaxFormer / init_distributed_mode

Function init_distributed_mode

event/utils.py:232–255  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

230
231
232def init_distributed_mode(args):
233 if 'RANK' in os.environ and 'WORLD_SIZE' in os.environ:
234 args.rank = int(os.environ["RANK"])
235 args.world_size = int(os.environ['WORLD_SIZE'])
236 args.gpu = int(os.environ['LOCAL_RANK'])
237 elif 'SLURM_PROCID' in os.environ:
238 args.rank = int(os.environ['SLURM_PROCID'])
239 args.gpu = args.rank % torch.cuda.device_count()
240 elif hasattr(args, "rank"):
241 pass
242 else:
243 print('Not using distributed mode')
244 args.distributed = False
245 return
246
247 args.distributed = True
248
249 torch.cuda.set_device(args.gpu)
250 args.dist_backend = 'nccl'
251 print('| distributed init (rank {}): {}'.format(
252 args.rank, args.dist_url), flush=True)
253 torch.distributed.init_process_group(backend=args.dist_backend, init_method=args.dist_url,
254 world_size=args.world_size, rank=args.rank)
255 setup_for_distributed(args.rank == 0)
256
257

Callers

nothing calls this directly

Calls 2

printFunction · 0.70
setup_for_distributedFunction · 0.70

Tested by

no test coverage detected