PyTorch】常见错误: RuntimeError:one of the variables needed for gradient computation has been modified

找到网络模型中的 inplace 操作,将inplace=True改成 inplace=False;
将网络结构中的+=操作进行修改,如下所示:

out = out + res    	# not inplace
out += res			# inplace

你可能感兴趣的:(PyTorch】常见错误: RuntimeError:one of the variables needed for gradient computation has been modified)