Pytorch之torch.nn.parallel.DistributedDataParallel

开始之前:https://pytorch.org/tutorials/beginner/dist_overview.html

CLASS torch.nn.parallel.DistributedDataParallel(moduledevice_ids=Noneoutput_device=Nonedim=0broadcast_buffers=Trueprocess_group=Nonebucket_cap_mb=25find_unused_parameters=Falsecheck_reduction=Falsegradient_as_bucket_view=False)

基于torch.distributed包,在模块水平实现分布式数据并行。

该容器通过在批处理维度中分组,将输入分割到指定的设备上,从而并行化给定的模块。模块被复制到每台机器和每台设备上,每个这样的副本处理输入的一部分。在反向传播时,每个节点的梯度被平均。

批处理大小应该大于本地使用的GPU数量。

另请参阅: Basics 和 Use nn.parallel.DistributedDataParallel instead of multiprocessing or nn.DataParallel. 如 torch.nn.DataParallel那样对输入的限制同样适用于torch.nn.parallel.DistributedDataParallel.

Creation of this class requires that torch.distributed to be already initialized, by calling torch.distributed.init_process_group().

DistributedDataParallel is proven to be significantly faster than torch.nn.DataParallel for single-node multi-GPU data parallel training.

To use DistributedDataParallel on a host with N GPUs, you should spawn up N processes, ensuring that each process exclusively works on a singl

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
torch.nn.parallel.DataParallelPyTorch中的一个模块,用于在单个节点上进行多GPU数据并行训练。它能够自动将输入数据划分为多个小批次,并将这些小批次分发到不同的GPU上进行计算。每个GPU上都有一个模型副本,每个副本都独立地计算损失和梯度,并将梯度聚合后进行参数更新。 然而,torch.nn.parallel.DataParallel有一些限制,例如需要在每个GPU上有足够的显存来存储模型和梯度,因为它会复制模型到每个GPU上。此外,它还要求输入数据能够被划分为多个小批次,并且每个小批次的大小是相同的。 相比之下,torch.nn.parallel.DistributedDataParallel是一个更高级的模块,可以在单节点或多节点上进行多进程的分布式训练。每个模型副本由独立的进程控制,可以在不同的机器上运行。它不需要将模型复制到每个GPU上,而是通过进程间通信来在各个进程之间共享模型参数和梯度。这样可以更好地利用多个GPU和多个机器的计算资源,提高训练速度。 值得注意的是,torch.nn.parallel.DistributedDataParallel的初始化和使用方法与torch.nn.parallel.DataParallel略有不同,需要进行一些额外的设置和配置。但是,对于单节点的多GPU数据并行训练,torch.nn.parallel.DistributedDataParallel已被证明比torch.nn.parallel.DataParallel更快。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Pytorchtorch.nn.parallel.DistributedDataParallel](https://blog.csdn.net/baidu_35120637/article/details/110816619)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [torch.nn.parallel.DistributedDataParallel](https://blog.csdn.net/weixin_45216013/article/details/125472676)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值