Copy
tensorplay.autograd.functional.vhp
- tensorplay.autograd.functional.vhp(func, inputs, v=None, create_graph=False, strict=False)[source]
Compute the dot product between vector
vand Hessian of a given scalar function at a specified point.- Parameters:
func (function) – a Python function that takes Tensor inputs and returns a Tensor with a single element.
inputs (tuple of Tensors or Tensor) – inputs to the function
func.v (tuple of Tensors or Tensor) – The vector for which the vector Hessian product is computed. Must be the same size as the input of
func. This argument is optional whenfunc’s input contains a single element and (if it is not provided) will be set as a Tensor containing a single1.create_graph (bool, optional) – If
True, both the output and result will be computed in a differentiable way. Note that whenstrictisFalse, the result can not require gradients or be disconnected from the inputs. Defaults toFalse.strict (bool, optional) – If
True, an error will be raised when we detect that there exists an input such that all the outputs are independent of it. IfFalse, we return a Tensor of zeros as the vhp for said inputs, which is the expected mathematical value. Defaults toFalse.
- Returns:
- tuple with:
func_output (tuple of Tensors or Tensor): output of
func(inputs)vhp (tuple of Tensors or Tensor): result of the dot product with the same shape as the inputs.
- Return type:
output (tuple)
Example
>>> def pow_reducer(x): ... return x.pow(3).sum() >>> inputs = tensorplay.rand(2, 2) >>> v = tensorplay.ones(2, 2) >>> output = vhp(pow_reducer, inputs, v) >>> output[0] tensor(0.5591) >>> output[1] tensor([[1.0689, 1.2431], [3.0989, 4.4456]])
Help improve this page
Found an error, an unclear step, or a missing example?
