pytorch bug: a leaf Variable that requires grad has been used in an in-place operation

pytorch

写的好好的代码运行到某一块突然显示

a leaf Variable that requires grad has been used in an in-place operation

这个bug的意思是 需要梯度的叶子变量被用在了原位操作里

指的是 如果是原位操作,就会覆盖原来的值。

因为并不是计算过程,是赋值,梯度是多少这个没有一个定义(或许是一个跳变过程,梯度无穷大)。

所以产生了错误,可以加上 torch.no_grad() 来规避掉梯度问题

发布了21 篇原创文章 · 获赞 17 · 访问量 3702

猜你喜欢

转载自blog.csdn.net/qq_33892106/article/details/100109099