pytorch利用DDP进行加速的报错问题

pytorch利用DDP加速时,出现提示信息为:
[W reducer.cpp:362] Warning: Grad strides do not match bucket view strides。This may indicate grad was not created according to the gradient layout contract, or that the param’s strides changed since DDP was constructed。 This is not an error, but may impair performance.

原因是因为输入tensor进行过transpose或permute等变形操作后,内部的内存地址变得不连续导致的。

处理方式很简单,在tensor进行transpose或permute等变形操作后,加一句语句.contiguous(),可使内存地址变连续。

例如:

# 原代码为:
input_tensor = ori_tensor.transpose(1, 3)

# 改为:
input_tensor = ori_tensor.transpose(1, 3).contiguous()

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
乘风的头像乘风管理团队
上一篇 2022年3月25日 下午4:15
下一篇 2022年3月27日 下午3:35

相关推荐