TensorPlay
latest (dev)
Copy
View Markdown

Latest development documentation · Updated 2026-10-15

tensorplay.autograd.backward

tensorplay.autograd.backward(tensors: Tensor | Sequence[Tensor], grad_tensors: Tensor | Sequence[Tensor] | None = None, retain_graph: bool | None = None, create_graph: bool = False, grad_variables: Tensor | Sequence[Tensor] | None = None, inputs: Tensor | Sequence[Tensor] | None = None) → None[source]

Compute the sum of gradients of given tensors with respect to graph leaves.

The gradients are accumulated in the leaves’ .grad. If any of tensors is non-scalar and requires gradient, grad_tensors gives the “vector” of the vector-Jacobian product for each of them (None for scalars and tensors that do not need one).

Parameters:
  • tensors (Sequence[Tensor] or Tensor) – Tensors whose derivative is computed.

  • grad_tensors (Sequence[Tensor or None] or Tensor, optional) – The “vector” in the vector-Jacobian product, usually gradients w.r.t. each element of corresponding tensors.

  • retain_graph (bool, optional) – If False, the graph used to compute the grad will be freed. Defaults to the value of create_graph.

  • create_graph (bool, optional) – If True, the graph of the derivative is constructed, allowing higher order derivative products.

  • grad_variables (Sequence[Tensor or None] or Tensor, optional) – Deprecated spelling of grad_tensors.

  • inputs (Sequence[Tensor] or Tensor or dict, optional) – Tensors w.r.t. which the gradient will be accumulated into .grad. All other tensors are ignored, and only the part of the graph that leads to these runs. A non-leaf named here keeps its gradient as if it had called retain_grad(). A dict (e.g. dict(model.named_parameters())) names its values.

On this page

Ask DeepWiki