nn.dropout 导致报错 one of the variables needed for gradient computation has been modified...

跑pytorch遇到如下错误:

RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor ..., 

经过修改,发现问题在如下代码:

n.Dropout(inplace=True)

改为:

n.Dropout(inplace=False)

即可解决问题。

出现这个问题的解决办法可以参考:

https://www.jianshu.com/p/dca997906d89
https://zhuanlan.zhihu.com/p/363512324

你可能感兴趣的:(深度学习,深度学习,pytorch,python)