(args)
| 313 | |
| 314 | |
| 315 | def init_distributed_mode(args): |
| 316 | if "RANK" in os.environ and "WORLD_SIZE" in os.environ: |
| 317 | args.rank = int(os.environ["RANK"]) |
| 318 | args.world_size = int(os.environ["WORLD_SIZE"]) |
| 319 | args.gpu = int(os.environ["LOCAL_RANK"]) |
| 320 | elif "SLURM_PROCID" in os.environ: |
| 321 | args.rank = int(os.environ["SLURM_PROCID"]) |
| 322 | args.gpu = args.rank % torch.cuda.device_count() |
| 323 | else: |
| 324 | print("Not using distributed mode") |
| 325 | args.distributed = False |
| 326 | return |
| 327 | |
| 328 | args.distributed = True |
| 329 | |
| 330 | torch.cuda.set_device(args.gpu) |
| 331 | args.dist_backend = "nccl" |
| 332 | print("| distributed init (rank {}): {}".format(args.rank, args.dist_url), flush=True) |
| 333 | torch.distributed.init_process_group( |
| 334 | backend=args.dist_backend, |
| 335 | init_method=args.dist_url, |
| 336 | world_size=args.world_size, |
| 337 | rank=args.rank, |
| 338 | ) |
| 339 | torch.distributed.barrier() |
| 340 | setup_for_distributed(args.rank == 0) |
| 341 | |
| 342 | |
| 343 | # -------------------------------------------------------- # |
nothing calls this directly
no test coverage detected