sciai.operators.grad

View Source On Gitee
sciai.operators.grad(net, output_index=0, input_index=- 1)[source]

Gradient function. Refer to _Grad.

Parameters
  • net (Cell) – Net to be auto-differentiated.

  • output_index (int) – Output index starting from 0. Default: 0.

  • input_index (Union(int, tuple[int])) – Input index(es) starting from 0, and only forward indexes are allowed. If -1, all specified inputs would be differentiated respectively. Default: -1.

Inputs:
  • *inputs (tuple[Tensor]) - The inputs of the original network.

Outputs:

Union(Tensor, tuple[Tensor]), The outputs of the fist order derivative net.

Raises
  • TypeError – If out_index is not int.

  • TypeError – If input_index is neither int nor tuple/list of int.

  • TypeError – If output of the network are neither Tensor, not tuple of Tensors.

  • TypeError – If input_index type is neither int nor tuple of int.

  • IndexError – If input_index or output_index is out of range.