oneflow.Tensor.is_leaf¶
-
Tensor.
is_leaf
¶ All Tensors that have
requires_grad
which isFalse
will be leaf Tensors by convention.For Tensor that have
requires_grad
which isTrue
, they will be leaf Tensors if they were created by source operations.Only leaf Tensors will have their
grad
populated during a call tobackward()
. To getgrad
populated 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