warp.autograd.gradcheck_tape#

warp.autograd.gradcheck_tape(
tape,
*,
eps=1e-4,
atol=1e-3,
rtol=1e-2,
raise_exception=True,
input_output_masks=None,
blacklist_kernels=None,
whitelist_kernels=None,
max_inputs_per_var=-1,
max_outputs_per_var=-1,
plot_relative_error=False,
plot_absolute_error=False,
show_summary=True,
reverse_launches=False,
skip_to_launch_index=0,
)[source]#

Checks whether the autodiff gradients for kernels recorded on the Warp tape match finite differences.

Given the autodiff (\(\nabla_\text{AD}\)) and finite difference gradients (\(\nabla_\text{FD}\)), the check succeeds if the autodiff gradients contain no NaN values and the following condition holds:

\[|\nabla_\text{AD} - \nabla_\text{FD}| \leq atol + rtol \cdot |\nabla_\text{FD}|.\]

Note

Only Warp kernels recorded on the tape are checked but not arbitrary functions that have been recorded, e.g. via warp.Tape.record_func().

Only Warp arrays with requires_grad=True are considered for the Jacobian computation.

Structs arguments are not yet supported by this function to compute Jacobians.

Parameters:
  • tape (Tape) – The Warp tape to perform the gradient check on.

  • eps – The finite-difference step size.

  • atol – The absolute tolerance for the gradient check.

  • rtol – The relative tolerance for the gradient check.

  • raise_exception – If True, raises a ValueError if the gradient check fails.

  • input_output_masks (dict[str, list[tuple[str | int, str | int]]] | None) – Dictionary of input-output masks for each kernel in the tape, mapping from kernel keys to input-output masks. Inputs and outputs can be identified either by their integer indices of where they appear in the kernel input/output arguments, or by the respective argument names as strings. If None, computes the Jacobian for all input-output pairs.

  • blacklist_kernels (list[str] | None) – List of kernel keys to exclude from the gradient check.

  • whitelist_kernels (list[str] | None) – List of kernel keys to include in the gradient check. If not empty or None, only kernels in this list are checked.

  • max_inputs_per_var – Maximum number of input dimensions over which to evaluate the Jacobians for the input-output pairs. Evaluates all input dimensions if value <= 0.

  • max_outputs_per_var – Maximum number of output dimensions over which to evaluate the Jacobians for the input-output pairs. Evaluates all output dimensions if value <= 0.

  • plot_relative_error – If True, visualizes the relative error of the Jacobians in a plot (requires matplotlib).

  • plot_absolute_error – If True, visualizes the absolute error of the Jacobians in a plot (requires matplotlib).

  • show_summary (bool) – If True, prints a summary table of the gradient check results.

  • reverse_launches (bool) – If True, reverses the order of the kernel launches on the tape to check.

  • skip_to_launch_index (int)

Returns:

True if the gradient check passes for all kernels on the tape, False otherwise.

Return type:

bool