(args)
| 230 | |
| 231 | |
| 232 | def 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 |
nothing calls this directly
no test coverage detected