Python报错:RuntimeError: one of the variables needed for gradient computation has been modified by

Python报错:

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

解决办法:
在inplace为True的时候,将其改为Flase,如dropout时;或者直接去掉所有的inplace操作。

#修改前
""self.dropout = torch.nn.Dropout(p=drop, inplace=True)""
#修改后
self.dropout = torch.nn.Dropout(p=drop)

问题即可解决。

你可能感兴趣的:(Python常见报错,python,开发语言,pytorch)