Pytorch使用DDP,同一个BN被调用多次会产生的问题。

在使用DDP时,同一个BN被调用一次以上,会报错:

RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation

这是因为BN包含了buffer,只要在调用DDP时,将broadcast_buffers参数设置为False即可。

相似的问题和解决方案在这里进行了讨论:https://github.com/pytorch/pytorch/issues/22095

posted @ 2021-04-21 10:38  Legendongary  阅读(751)  评论(0)    收藏  举报