oneflow.Tensor.is_leaf¶
-
Tensor.is_leaf¶ All Tensors that have
requires_gradwhich isFalsewill be leaf Tensors by convention.For Tensor that have
requires_gradwhich isTrue, they will be leaf Tensors if they were created by source operations.Only leaf Tensors will have their
gradpopulated during a call tobackward(). To getgradpopulated for non-leaf Tensors, you can useretain_grad().Compatible with PyTorch.
For example:
>>> 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