xlnstorch.LNSTensor.backward#
- LNSTensor.backward(gradient=None, retain_graph=None, create_graph=False, inputs=None)#
Computes the gradients of the current LNSTensor with respect to the graph leaves. This method is analogous to the standard PyTorch backward method, but works with LNSTensor objects. See
https://docs.pytorch.org/docs/stable/generated/torch.Tensor.backward.html
for more details on the parameters. Note that the gradient and inputs parameters here are LNSTensor objects, not regular PyTorch tensors.
- Parameters:
gradient (LNSTensor, optional) – Gradient of the function being differentiated w.r.t. self. This argument should be omitted if self is a scalar. In this case, the gradient is set to 1.
retain_graph (bool, optional) – If True, the graph used to compute the gradient will be retained, allowing for further backward passes, by default None.
create_graph (bool, optional) – If True, the graph of the derivative will be constructed, allowing to compute higher order derivative products, by default False.
inputs (sequence of LNSTensor, optional) – Inputs with respect to which the gradient will be accumulated into their .grad attributes, all other tensors will be ignored. If not provided, the gradient is accumulated into all the leaf Tensors that were used to compute the tensors.