- x.grad_fn和x.requires_grad为x的属性
- x.grad_fn:积分方法名,默认为None
- x.requires_grad:是否积分的属性,默认为False
- x.requires_grad_():设置积分的方法,设置之后requires_grad为True
"""Tensor"""
import torch
# 创建一个Tensor并设置requires_grad=True
x = torch.ones(2, 2, requires_grad=True)
print(x)
print(x.grad_fn)y = x + 2
print(y)
print(y.grad_fn)print(x.is_leaf, y.is_leaf)