Rate this Page

torch.onnx.verification#

Created On: Mar 18, 2025 | Last Updated On: Aug 29, 2025

A set of tools to verify the correctness of ONNX models.

torch.onnx.verification.verify_onnx_program(onnx_program, args=None, kwargs=None, compare_intermediates=False)[source]#

Verify the ONNX model by comparing the values with the expected values from ExportedProgram.

Parameters
  • onnx_program (_onnx_program.ONNXProgram) – The ONNX program to verify.

  • args (tuple[Any, ...] | None) – The input arguments for the model.

  • kwargs (dict[str, Any] | None) – The keyword arguments for the model.

  • compare_intermediates (bool) – Whether to verify intermediate values. This is going to take longer time, so it is disabled by default.

Returns

VerificationInfo objects containing the verification information for each value.

Return type

list[VerificationInfo]

class torch.onnx.verification.VerificationInfo(name, max_abs_diff, max_rel_diff, abs_diff_hist, rel_diff_hist, expected_dtype, actual_dtype)#

Verification information for a value in the ONNX program.

This class contains the maximum absolute difference, maximum relative difference, and histograms of absolute and relative differences between the expected and actual values. It also includes the expected and actual data types.

The histograms are represented as tuples of tensors, where the first tensor is the histogram counts and the second tensor is the bin edges.

Variables
  • name (str) – The name of the value (output or intermediate).

  • max_abs_diff (float) – The maximum absolute difference between the expected and actual values.

  • max_rel_diff (float) – The maximum relative difference between the expected and actual values.

  • abs_diff_hist (tuple[torch.Tensor, torch.Tensor]) – A tuple of tensors representing the histogram of absolute differences. The first tensor is the histogram counts and the second tensor is the bin edges.

  • rel_diff_hist (tuple[torch.Tensor, torch.Tensor]) – A tuple of tensors representing the histogram of relative differences. The first tensor is the histogram counts and the second tensor is the bin edges.

  • expected_dtype (torch.dtype) – The data type of the expected value.

  • actual_dtype (torch.dtype) – The data type of the actual value.

asdict()[source]#

Convert the VerificationInfo object to a dictionary.

Returns

A dictionary representation of the VerificationInfo object.

Return type

dict[str, Any]

classmethod from_tensors(name, expected, actual)[source]#

Create a VerificationInfo object from two tensors.

Parameters
Returns

The VerificationInfo object.

Return type

VerificationInfo