All Tensors that have
Falsewill be leaf Tensors by convention.
For Tensor that have
True, they will be leaf Tensors if they were created by source operations.
Only leaf Tensors will have their
gradpopulated during a call to
backward(). To get
gradpopulated for non-leaf Tensors, you can use
Compatible with PyTorch.
>>> import oneflow as flow >>> a = flow.rand(10, requires_grad=False) >>> a.is_leaf True >>> a = flow.rand(10, requires_grad=True) >>> a.is_leaf True >>> b = a.cuda() >>> b.is_leaf False >>> c = a + 2 >>> c.is_leaf False