【pytorch DistributedDataParallel 及amp 使用过程遇到的问题记录 】

pytorch 分布式训练及混合精度训练中遇到的问题记录

环境

pytorch==2.3.1

问题

单机多卡时:

超时错误

部分报错内容:

Heartbeat monitor timed out! Process will be terminated after dumping debug info. workMetaList_.size()=2
[rank1]:[E ProcessGroupNCCL.cpp:1153] [PG 0 Rank 1] ProcessGroupNCCL preparing to dump debug info.
[rank1]:[F ProcessGroupNCCL.cpp:1169] [PG 0 Rank 1] [PG 0 Rank 1] ProcessGroupNCCL’s watchdog got stuck for 600 seconds without making progress in monitoring enqueued collectives

报错截图:
在这里插入图片描述

解决方法:

代码中:


dist.init_process_group(backend='nccl', init_method='env://',rank=self.opt.local_rank, world_size=self.opt.world_size,)   

改为:

dist.init_process_group(backend='nccl', init_method='env://',rank=self.opt.local_rank, world_size=self.opt.world_size,  timeout=timedelta(seconds=3600),)

存在没有使用梯度的参数

(不使用ddp时正常,使用ddp时报错)

报错内容:

If you already have done the above, then the distributed data parallel module wasn’t able to locate the output tensors in the return value of your module’s forward function. Please include the loss function and the structure of the return value of forward of your module when reporting this issue (e.g. list, dict, iterable).
[rank0]: Parameter indices which did not receive grad for rank 0: 60 6

解决方法:
方法1 找到不参与梯度计算的层没有用处的层,删除

注意: nn.MultiheadAttention 层可能不兼容DDP ,但是这个层对模型有用处就不能使用方法1,这时候使用方法二
参考:https://github.com/pytorch/pytorch/issues/26698

方法2 DistributedDataP
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值