| 154 | return args, config |
| 155 | |
| 156 | def init_distributed(args): |
| 157 | if "WORLD_SIZE" not in os.environ or int(os.environ["WORLD_SIZE"]) < 1: |
| 158 | return False |
| 159 | |
| 160 | torch.cuda.set_device(args.local_rank) |
| 161 | |
| 162 | assert os.environ["MASTER_PORT"], "set the MASTER_PORT variable or use pytorch launcher" |
| 163 | assert os.environ["RANK"], "use pytorch launcher and explicityly state the rank of the process" |
| 164 | |
| 165 | torch.manual_seed(args.seed) |
| 166 | torch.cuda.manual_seed(args.seed) |
| 167 | torch.cuda.manual_seed_all(args.seed) |
| 168 | np.random.seed(args.seed) |
| 169 | random.seed(args.seed) |
| 170 | cudnn.deterministic = True |
| 171 | cudnn.benchmark = False |
| 172 | os.environ['PYTHONHASHSEED'] = str(args.seed) |
| 173 | os.environ['TORCH_DISTRIBUTED_DEBUG'] = 'DETAIL' |
| 174 | torch.distributed.init_process_group(backend="nccl", init_method="env://") |
| 175 | |
| 176 | return True |
| 177 | |
| 178 | def main(): |
| 179 | args, cfg = parse_args_and_config() |