多GPU并行计算,训练和推理
先来回顾一下Python的多进程multiprocessing和多线程Threading
多进程
https://zhuanlan.zhihu.com/p/85821779
多线程
适合IO密集型任务,不适合CPU密集型任务(如循环,计数)
https://python.land/python-concurrency/the-python-gil
多线程 VS 多进程
https://zhuanlan.zhihu.com/p/20953544
接下来再看下torch实现多GPU并行计算的几种方法
DDP DistributedDataParallel VS DataParallel
- DDP 多进程,多线程; DP 单进程,多线程
- DDP 可以分布式计算,DP只能单台机器计算
- DDP 可以model paralle,DP不可
https://blog.csdn.net/qq_37541097/article/details/109736159
在Pytorch中使用多GPU的常用启动方式一种是torch.distributed.launch
一种是torch.multiprocessing
模块。