# tensorplay.autograd.functional.hessian Source: https://www.tensorplay.cn/docs/generated/tensorplay.autograd.functional.hessian.html ```python tensorplay.autograd.functional.hessian(func, inputs, create_graph=False, strict=False, vectorize=False, outer_jacobian_strategy='reverse-mode') ``` Compute the Hessian of a given scalar function. Parameters: - func (function) – a Python function that takes Tensor inputs and returns a Tensor with a single element. - inputs ([tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of Tensors or [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – inputs to the function func. - create_graph ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If True, the Hessian will be computed in a differentiable manner. Note that when strict is False, the result can not require gradients or be disconnected from the inputs. Defaults to False. - strict ([bool](https://docs.python.org/3/builtins/functions.html#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. If False, we return a Tensor of zeros as the hessian for said inputs, which is the expected mathematical value. Defaults to False. - vectorize ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – Not supported by this engine yet; passing True raises [NotImplementedError](https://docs.python.org/3/builtins/exceptions.html#NotImplementedError). - outer_jacobian_strategy ([str](https://docs.python.org/3/builtins/stdtypes.html#str), optional) – Only "reverse-mode" is supported; forward-mode AD raises [NotImplementedError](https://docs.python.org/3/builtins/exceptions.html#NotImplementedError). Returns: if there is a single input, this will be a single Tensor containing the Hessian for the input. If it is a tuple, then the Hessian will be a tuple of tuples where Hessian[i][j] will contain the Hessian of the ith input and jth input with size the sum of the size of the ith input plus the size of the jth input. Hessian[i][j] will have the same dtype and device as the corresponding ith input. Return type: Hessian ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or a tuple of [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of Tensors) Example ``` >>> def pow_reducer(x): ... return x.pow(3).sum() >>> inputs = tensorplay.rand(2, 2) >>> hessian(pow_reducer, inputs) tensor([[[[5.2265, 0.0000], [0.0000, 0.0000]], [[0.0000, 4.8221], [0.0000, 0.0000]]], [[[0.0000, 0.0000], [1.9456, 0.0000]], [[0.0000, 0.0000], [0.0000, 3.2550]]]]) ```