RuntimeError: a leaf Variable that requires grad has been used in an in-place operation.a += torch.o
程序员文章站
2022-06-15 18:42:50
...
叶子节点不能执行in-place(原地)操作,因为在进行前向传播的时候得到的是叶子结点的地址,再进行反向传播的时候这个地址不变才不会报错,地址改变了就会出错
要将
a += torch.ones((1, ))
改为
a = a + torch.ones((1, ))
另外下划线也是原地操作
w.add_(1)
w.grad.zero_()
推荐阅读
-
RuntimeError: a leaf Variable that requires grad has been used in an in-place operation
-
a leaf Variable that requires grad has been used in an in-place operation
-
RuntimeError: a leaf Variable that requires grad has been used in an in-place operation.
-
RuntimeError: a leaf Variable that requires grad has been used in an in-place operation.a += torch.o
-
yolov5报错:RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place
-
RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.