oneflow.Tensor.requires_grad_

Tensor.requires_grad_(requires_grad=True)Tensor

Sets this tensor’s requires_grad attribute in-place. Returns this tensor.

Compatible with PyTorch.

Parameters

requires_grad (bool) – Change the requires_grad flag for this Tensor. Default is True.

For example:

>>> import oneflow as flow
>>> a = flow.rand(10, requires_grad=False)
>>> a.requires_grad
False
>>> a = a.requires_grad_(requires_grad=True)
>>> a.requires_grad
True