MCPcopy Create free account
hub / github.com/LTH14/mar / init_distributed_mode

Function init_distributed_mode

util/misc.py:212–244  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

210
211
212def init_distributed_mode(args):
213 if args.dist_on_itp:
214 args.rank = int(os.environ['OMPI_COMM_WORLD_RANK'])
215 args.world_size = int(os.environ['OMPI_COMM_WORLD_SIZE'])
216 args.gpu = int(os.environ['OMPI_COMM_WORLD_LOCAL_RANK'])
217 args.dist_url = "tcp://%s:%s" % (os.environ['MASTER_ADDR'], os.environ['MASTER_PORT'])
218 os.environ['LOCAL_RANK'] = str(args.gpu)
219 os.environ['RANK'] = str(args.rank)
220 os.environ['WORLD_SIZE'] = str(args.world_size)
221 # ["RANK", "WORLD_SIZE", "MASTER_ADDR", "MASTER_PORT", "LOCAL_RANK"]
222 elif 'RANK' in os.environ and 'WORLD_SIZE' in os.environ:
223 args.rank = int(os.environ["RANK"])
224 args.world_size = int(os.environ['WORLD_SIZE'])
225 args.gpu = int(os.environ['LOCAL_RANK'])
226 elif 'SLURM_PROCID' in os.environ:
227 args.rank = int(os.environ['SLURM_PROCID'])
228 args.gpu = args.rank % torch.cuda.device_count()
229 else:
230 print('Not using distributed mode')
231 setup_for_distributed(is_master=True) # hack
232 args.distributed = False
233 return
234
235 args.distributed = True
236
237 torch.cuda.set_device(args.gpu)
238 args.dist_backend = 'nccl'
239 print('| distributed init (rank {}): {}, gpu {}'.format(
240 args.rank, args.dist_url, args.gpu), flush=True)
241 torch.distributed.init_process_group(backend=args.dist_backend, init_method=args.dist_url,
242 world_size=args.world_size, rank=args.rank)
243 torch.distributed.barrier()
244 setup_for_distributed(args.rank == 0)
245
246
247class NativeScalerWithGradNormCount:

Callers

nothing calls this directly

Calls 2

printFunction · 0.85
setup_for_distributedFunction · 0.85

Tested by

no test coverage detected