-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathutils.py
More file actions
31 lines (22 loc) · 759 Bytes
/
utils.py
File metadata and controls
31 lines (22 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os
import shutil
import torch
import torch.distributed as dist
def copy_source(file, output_dir):
shutil.copyfile(file, os.path.join(output_dir, os.path.basename(file)))
def broadcast_params(params):
for param in params:
dist.broadcast(param.data, src=0)
def init_processes(rank, size, fn, args):
""" Initialize the distributed environment. """
os.environ['MASTER_ADDR'] = args.master_address
os.environ['MASTER_PORT'] = args.master_port
torch.cuda.set_device(args.local_rank)
gpu = args.local_rank
dist.init_process_group(
backend='nccl', init_method='env://', rank=rank, world_size=size)
fn(rank, gpu, args)
dist.barrier()
cleanup()
def cleanup():
dist.destroy_process_group()