(args)
| 551 | setup_for_distributed(args.rank == 0) |
| 552 | |
| 553 | def init_distributed_mode(args): |
| 554 | if 'WORLD_SIZE' in os.environ and os.environ['WORLD_SIZE'] != '': |
| 555 | local_world_size = int(os.environ['WORLD_SIZE']) |
| 556 | args.world_size = args.world_size * local_world_size |
| 557 | args.gpu = args.local_rank = int(os.environ['LOCAL_RANK']) |
| 558 | args.rank = args.rank * local_world_size + args.local_rank |
| 559 | print('world size: {}, rank: {}, local rank: {}'.format(args.world_size, args.rank, args.local_rank)) |
| 560 | print(json.dumps(dict(os.environ), indent=2)) |
| 561 | elif 'SLURM_PROCID' in os.environ: |
| 562 | args.rank = int(os.environ['SLURM_PROCID']) |
| 563 | args.gpu = args.local_rank = int(os.environ['SLURM_LOCALID']) |
| 564 | args.world_size = int(os.environ['SLURM_NPROCS']) |
| 565 | |
| 566 | print('world size: {}, world rank: {}, local rank: {}, device_count: {}'.format(args.world_size, args.rank, args.local_rank, torch.cuda.device_count())) |
| 567 | print("os.environ['SLURM_JOB_NODELIST']:", os.environ['SLURM_JOB_NODELIST']) |
| 568 | print(json.dumps(dict(os.environ), indent=2)) |
| 569 | print('args:') |
| 570 | print(json.dumps(vars(args), indent=2)) |
| 571 | else: |
| 572 | print('Not using distributed mode') |
| 573 | args.distributed = False |
| 574 | args.world_size = 1 |
| 575 | args.rank = 0 |
| 576 | args.local_rank = 0 |
| 577 | return |
| 578 | |
| 579 | print("world_size:{} rank:{} local_rank:{}".format(args.world_size, args.rank, args.local_rank)) |
| 580 | args.distributed = True |
| 581 | torch.cuda.set_device(args.local_rank) |
| 582 | args.dist_backend = 'nccl' |
| 583 | print('| distributed init (rank {}): {}'.format(args.rank, args.dist_url), flush=True) |
| 584 | torch.distributed.init_process_group(backend=args.dist_backend, init_method=args.dist_url, |
| 585 | world_size=args.world_size, rank=args.rank) |
| 586 | print("Before torch.distributed.barrier()") |
| 587 | torch.distributed.barrier() |
| 588 | print("End torch.distributed.barrier()") |
| 589 | setup_for_distributed(args.rank == 0) |
| 590 | |
| 591 | @torch.no_grad() |
| 592 | def accuracy(output, target, topk=(1, )): |
nothing calls this directly
no test coverage detected