Pytorch在1.9版本的官方文档中,明确说明了不再建议使用nn.DataParallel,或者是multiprocessing,而是推荐使用nn.parallel.DistributedDataParllel。即使只有一个GPU核,同样也推荐使用nn.paralle.DistributeDataParalle。官方文档给出的理由是:
The difference between
DistributedDataParallelandDataParallelis:DistributedDataParalleluses multiprocessing where a process is created for each GPU, whileDataParalleluses multithreading. By using multiprocessing, each GPU has its dedicated process, this avoids the performance overhead caused by GIL of Python interpreter.
大意是,DistributedDataParallel比较优秀,是因为他对每个GPU分配一个固定的进程;而DataParallel不推荐,因为使用的是多线程的方法,这可能会导致来自于GIL或者Python解释器的性能开销。
另一个Basic文档里面提到,对于torch.multiprocessing或者是torch.nn.DataParallel来说,用户必须要显式的对每个进程创建一个独立的、关于主训练脚本的副本。这不方便。

Pytorch 1.9官方文档建议停止使用nn.DataParallel和multiprocessing,转而推荐nn.parallel.DistributedDataParallel,即使在单GPU环境下也是如此。原因是DistributedDataParallel采用多进程方式,避免了Python GIL和解释器的性能开销,而DataParallel使用的多线程可能导致性能下降。
4563

被折叠的 条评论
为什么被折叠?



