算是自己经常使用的两种方法吧,其他的非分布式的方法就不介绍了。
一. PyTorch
torch.distributed,分配n个进程,分别运行在n个GPU上
- 单机多卡:CUDA_VISIBLE_DEVICES=0,1,2,3 python -m torch.distributed.launch –nproc_per_node=4 ––master_port=29501 main.py (最好指定端口,否则出现端口被占用)
- 多机多卡:
- 机器1: CUDA_VISIBLE_DEVICES=0,1,2,3 python -m torch.distributed.launch –nproc_per_node=4 –nnodes=2 –node_rank=0 –master_addr=”156.132.1.2″ –master_port=1234 main.py
- 机器2: CUDA_VISIBLE_DEVICES=0,1,2,3 python -m torch.distributed.launch –nproc_per_node=4 –nnodes=2 –node_rank=1 –master_addr=”156.132.1.2″ –master_port=1234 main.py
参考:pytorch DistributedDataParallel多卡并行训练 torch.distributed(该页末尾) 当代研究生应当掌握的并行训练方法(单机多卡)
二. Tensorflow
使用horovod
- 单机多卡:horovodrun -np 8 -H localhost:8 python run_classifier.py
- 多机多卡:
- 机器1: horovodrun -np 16 -H localhost:8,172.31.60.175:8 python run_classifier.py
- 机器2: horovodrun -np 16 -H 机器1的ip:8,172.31.60.175:8 python run_classifier.py
参考:private_bert
Difference between hvd.rank() and hvd.local_rank()
2+