reference#

ExtendedReferenceEvaluator#

class onnx_array_api.reference.ExtendedReferenceEvaluator(proto: Any, opsets: Dict[str, int] | None = None, functions: List[ReferenceEvaluator | FunctionProto] | None = None, verbose: int = 0, new_ops: List[OpRun] | None = None, **kwargs)[source]#

This class replaces the python implementation by custom implementation. The Array API extends many operator to all types not supported by the onnx specifications. The evaluator allows to test scenarios outside what an onnx backend bound to the official onnx operators definition could do.

from onnx.reference import ReferenceEvaluator
from onnx.reference.c_ops import Conv
ref = ReferenceEvaluator(..., new_ops=[Conv])
run(*args, **kwargs)[source]#

See onnx.reference.ReferenceEvaluator.run().

ResultType#

class onnx_array_api.reference.ResultType(value)[source]#

An enumeration.

ResultExecution#

class onnx_array_api.reference.ResultExecution(kind: ResultType, dtype: object, shape: tuple, summary: str, op_type: str, name: str, value: Any | None = None)[source]#

The description of a result.

YieldEvaluator#

class onnx_array_api.reference.YieldEvaluator(onnx_model: ~onnx.onnx_ml_pb2.ModelProto, recursive: bool = False, cls=<class 'onnx_array_api.reference.evaluator.ExtendedReferenceEvaluator'>)[source]#

This class implements method enumerate_results which iterates on intermediates results. By default, it uses onnx_array_api.reference.ExtendedReferenceEvaluator.

Parameters:
  • onnx_model – model to run

  • recursive – dig into subgraph and functions as well

enumerate_results(output_names: List[str] | None = None, feed_inputs: Dict[str, Any] | None = None, raise_exc: bool = True) Iterator[Tuple[ResultType, str, Any]][source]#

Executes the onnx model and enumerate all the intermediate results.

Args:

output_names: requested outputs by names, None for all feed_inputs: dictionary { input name: input value }

Returns:

iterator on tuple(result kind, name, value, node.op_type or None)

enumerate_summarized(output_names: List[str] | None = None, feed_inputs: Dict[str, Any] | None = None, raise_exc: bool = True, keep_tensor: bool = False) Iterator[ResultExecution][source]#

Executes the onnx model and enumerate intermediate results without their names.

Parameters:
  • output_names – requested outputs by names, None for all

  • feed_inputs – dictionary { input name: input value }

  • raise_exc – raises an exception if the execution fails or stop where it is

  • keep_tensor – keep the tensor in order to compute precise distances

Returns:

iterator on ResultExecution

DistanceExecution#

class onnx_array_api.reference.DistanceExecution(max_lag: int = 50)[source]#

Computes a distance between two results.

distance_pair(r1: ResultExecution, r2: ResultExecution) float[source]#

(ResultType.RESULT, np.dtype(“float32”), (2, 2), “CEIO”, “Abs”),

Parameters:
  • r1 – first result

  • r2 – second result

Returns:

distance

distance_sequence(s1: List[ResultExecution], s2: List[ResultExecution]) Tuple[float, List[Tuple[int, int]]][source]#

Computes the distance between two sequences of results.

Parameters:
  • s1 – first sequence

  • s2 – second sequence

Returns:

distance and alignment

to_str(s1: List[ResultExecution], s2: List[ResultExecution], alignment: List[Tuple[int, int]], column_size: int = 60) str[source]#

Prints out the alignment between two sequences into a string. :param s1: first sequence :param s2: second sequence :param alignment: alignment :param column_size: column size :return: test

compare_onnx_execution#

onnx_array_api.reference.compare_onnx_execution(model1: ModelProto, model2: ModelProto, inputs: List[Any] | Tuple[Dict[str, Any]] | None = None, verbose: int = 0, raise_exc: bool = True, mode: str = 'execute', keep_tensor: bool = False) Tuple[List[ResultExecution], List[ResultExecution], List[Tuple[int, int]]][source]#

Compares the execution of two onnx models. The function assumes both models takes the same inputs. See Compares the conversions of the same model with different options to see a full example using this function.

Parameters:
  • model1 – first model

  • model2 – second model

  • inputs – inputs to use, a list of inputs if both models have the same number of inputs or two dictionaries, one for each model

  • verbose – verbosity

  • raise_exc – raise exception if the execution fails or stop at the error

  • mode – the model should be executed but the function can be executed but the comparison may append on nodes only

  • keep_tensor – keeps the tensor in order to compute a precise distance

Returns:

four results, a sequence of results for the first model and the second model, the alignment between the two, DistanceExecution