calc_gradient

paddle.autograd.ir_backward. calc_gradient ( outputs, inputs, grad_outputs, no_grad_set ) [source]

calculate gradient of input

Parameters
  • outputs (Value|list(Value)|tuple(Value)) – the output Value or Value list/tuple of the graph to compute gradients.

  • inputs (Value|list(Value)|tuple(Value)) – the input Value or Value list/tuple of the graph to compute gradients. The returned values of this API are the gradients of inputs .

  • grad_outputs (Value|list(Value|None)|tuple(Value|None), optional) – initial gradient values of outputs . If grad_outputs is None, the initial gradient values of outputs would be Values filled with 1; if grad_outputs is not None, it must have the same length as outputs , and in this case, the initial gradient value of the i-th outputs would be: (1) a Value filled with 1 when the i-th element of grad_outputs is None; (2) the i-th element of grad_outputs when the i-th element of grad_outputs is a Value. Default None.

  • no_grad_set (set(Value), optional) – the Values whose gradients are not needed to compute. Default None.

Returns

A list of gradients for inputs If an input does not affect targets, the corresponding gradient Tensor will be None TODO if allow_unused=False raise TypeError() if input_grad has None

Return type

list[Value]