MCPcopy Index your code
hub / github.com/OpenDriveLab/ReSim / init_distributed_mode

Function init_distributed_mode

SwissArmyTransformer/examples/mae/util/misc.py:216–248  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

printFunction · 0.70
setup_for_distributedFunction · 0.70

Tested by

no test coverage detected