# tensorplay.autograd.gradcheck.gradgradcheck

Source: https://www.tensorplay.cn/docs/generated/tensorplay.autograd.gradcheck.gradgradcheck.html

# tensorplay.autograd.gradcheck.gradgradcheck

tensorplay.autograd.gradcheck.gradgradcheck(func, inputs, grad_outputs=None, *, eps: [float](https://docs.python.org/3/library/functions.html#float) = 1e-06, atol: [float](https://docs.python.org/3/library/functions.html#float) = 1e-05, rtol: [float](https://docs.python.org/3/library/functions.html#float) = 0.001, gen_non_contig_grad_outputs: [bool](https://docs.python.org/3/library/functions.html#bool) = False, raise_exception: [bool](https://docs.python.org/3/library/functions.html#bool) = True, nondet_tol: [float](https://docs.python.org/3/library/functions.html#float) = 0.0, check_undefined_grad: [bool](https://docs.python.org/3/library/functions.html#bool) = True, check_grad_dtypes: [bool](https://docs.python.org/3/library/functions.html#bool) = False, check_batched_grad: [bool](https://docs.python.org/3/library/functions.html#bool) = False, check_fwd_over_rev: [bool](https://docs.python.org/3/library/functions.html#bool) = False, check_rev_over_rev: [bool](https://docs.python.org/3/library/functions.html#bool) = True, fast_mode: [bool](https://docs.python.org/3/library/functions.html#bool) = False, masked: [bool](https://docs.python.org/3/library/functions.html#bool) = False) &#x2192; [bool](https://docs.python.org/3/library/functions.html#bool)[[source]](../_modules/tensorplay/autograd/gradcheck.html#gradgradcheck)

Check gradients of gradients computed via small finite differences
against analytical gradients wrt tensors in inputs and
grad_outputs that are of floating point or complex type and with
requires_grad=True.

This function checks that backpropagating through the gradients computed
to the given grad_outputs are correct.

The check between numerical and analytical gradients uses allclose().

Note

The default values are designed for input and
grad_outputs of double precision. This check will likely fail if
they are of less precision, e.g., FloatTensor.

Parameters:

- func ( function ) – a Python function that takes Tensor inputs and returns a Tensor or a tuple of Tensors

- inputs ([tuple](https://docs.python.org/3/library/stdtypes.html#tuple) of Tensor or Tensor ) – inputs to the function

- grad_outputs ([tuple](https://docs.python.org/3/library/stdtypes.html#tuple) of [ Tensor or None ] or Tensor , optional ) – The gradients with respect to the function’s outputs.

- eps ([float](https://docs.python.org/3/library/functions.html#float) , optional ) – perturbation for finite differences

- atol ([float](https://docs.python.org/3/library/functions.html#float) , optional ) – absolute tolerance

- rtol ([float](https://docs.python.org/3/library/functions.html#float) , optional ) – relative tolerance

- gen_non_contig_grad_outputs ([bool](https://docs.python.org/3/library/functions.html#bool) , optional ) – Not supported by this engine yet; True raises [NotImplementedError](https://docs.python.org/3/library/exceptions.html#NotImplementedError).

- raise_exception ([bool](https://docs.python.org/3/library/functions.html#bool) , optional ) – indicating whether to raise an exception if the check fails. The exception gives more information about the exact nature of the failure. This is helpful when debugging gradchecks.

- nondet_tol ([float](https://docs.python.org/3/library/functions.html#float) , optional ) – tolerance for non-determinism. When running identical inputs through the differentiation, the results must either match exactly (default, 0.0) or be within this tolerance. Note that a small amount of nondeterminism in the gradient will lead to larger inaccuracies in the second derivative.

- check_undefined_grad ([bool](https://docs.python.org/3/library/functions.html#bool) , optional ) – if True, check if undefined output grads are supported and treated as zeros

- check_batched_grad ([bool](https://docs.python.org/3/library/functions.html#bool) , optional ) – Not supported by this engine yet.

- fast_mode ([bool](https://docs.python.org/3/library/functions.html#bool) , optional ) – Not supported by this engine yet.

- masked ([bool](https://docs.python.org/3/library/functions.html#bool) , optional ) – Kept for signature parity with torch.

Returns:

True if all differences satisfy allclose condition
