关于y.grad报错

来源:3-32 Pytorch与autograd中的几个重要概念-autograd例子

qq_Theonlywinne_0

2022-08-25

UserWaring:The .grad attribute of a Tensor thatis not a leaf Tensor is being accessed.Its .grad attribute won’t be populated during autograd.backward().If you Indeed want the .grad field to be populated for a non-leaf Tensor,use .retain_grad() on the non-leaf Tensor.If you access the non-leaf Tensor by mistake ,make sure you access the leaf Tensor instead.See github.com/pytorch/pytorch/pull/30531 for more information
在print(y.grad)这一句报错,注释了就没错了
![图片描述![图片描述](http://img.mukewang.com/szimg/630765fe086d12ae17021276.jpg图片描述

写回答

1回答

会写代码的好厨师

2022-08-25

这个不是报错,是警告。可以不用管他。

0
0

PyTorch入门到进阶 实战计算机视觉与自然语言处理项目

理论基础+技术讲解+实战开发,快速掌握PyTorch框架

1190 学习 · 293 问题

查看课程