可以结合这篇文章,更好地了解理论知识:https://blog.csdn.net/weixin_42468475/article/details/108369795
目录
方法1 tensor.backward()
Central to all neural networks in PyTorch is the autograd package.
Tensor
torch.Tensor is the central class of the package. If you set its attribute .requires_grad as True, it starts to track all operations on it. When you finish your computation you can call .backward() and have all the gradients computed automatically. The gradient for this tensor will be accumulated into .grad attribute.
To stop a tensor from tracking history, you can call .deta