Pytorch 报错汇总

Apr 25, 2024
2 views
Python

unsupported operation: more than one element of the written-to tensor refers to a single memory location. Please clone() the tensor before performing the operation.

image

出现这种情况可能是在.backward()之前使用了 .expand()或者.expand_as()函数。具体原因可以看看这个老哥的提问:link

解决办法:在 .expand()或者.expand_as()函数后面添加.clone()就可以解决。