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()

你可能感兴趣的:(pytorch)