RuntimeError:一个需要grad的叶子变量的视图被用在了原地操作中



我在Pytorch 0.3中实现的代码上得到此错误。我正在尝试运行代码,但我得到这个错误。

/usr/local/lib/python3.7/dist-packages/torch/nn/functional.py:4044: UserWarning: Default grid_sample and affine_grid behavior has changed to align_corners=False since 1.3.0. Please specify align_corners=True if the old behavior is desired. See the documentation of grid_sample for details.
"Default grid_sample and affine_grid behavior has changed "
/usr/local/lib/python3.7/dist-packages/torch/nn/functional.py:718: UserWarning: Named tensors and all their associated APIs are an experimental feature and subject to change. Please do not use them for anything important until they are released as stable. (Triggered internally at /pytorch/c10/core/TensorImpl.h:1156.)
return torch.max_pool2d(input, kernel_size, stride, padding, dilation, ceil_mode)
Traceback (most recent call last):
File "eval_pf_pascal.py", line 73, in
corr4d = model(batch)
File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 1051, in _call_impl
return forward_call(*input, **kwargs)
File "/content/ncnet/lib/model.py", line 275, in forward
corr4d = self.NeighConsensus(corr4d)
File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 1051, in _call_impl
return forward_call(*input, **kwargs)
File "/content/ncnet/lib/model.py", line 147, in forward
x = self.conv(x)+self.conv(x.permute(0,1,4,5,2,3)).permute(0,1,4,5,2,3)
File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 1051, in _call_impl
return forward_call(*input, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/container.py", line 139, in forward
input = module(input)
File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 1051, in _call_impl
return forward_call(*input, **kwargs)
File "/content/ncnet/lib/conv4d.py", line 126, in forward
use_half=self.use_half,
File "/content/ncnet/lib/conv4d.py", line 52, in conv4d
padding=padding,
RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.

对于如何解决这个问题有什么想法吗?

如果您正在执行操作,例如Tensor1 += tensor2

试tensor1。Data += tensor2

最新更新