module npy.onnx_numpy_compiler#

Inheritance diagram of mlprodict.npy.onnx_numpy_compiler

Short summary#

module mlprodict.npy.onnx_numpy_compiler

Implements numpy functions with onnx and a runtime.

Classes#

class

truncated documentation

OnnxNumpyCompiler

Implements a class which runs onnx graph.

OnnxNumpyFunction

Class wrapping a function build with OnnxNumpyCompiler.

OnnxNumpyFunctionInferenceSession

Overwrites OnnxNumpyFunction to run an instance of InferenceSession from onnxruntime.

OnnxNumpyFunctionOnnxInference

Overwrites OnnxNumpyFunction to run an instance of OnnxInference.

Methods#

method

truncated documentation

__call__

Executes the function and returns the results.

__call__

__call__

__getstate__

Serializes everything but function fct_. Function fct_ is used to build the onnx graph and is not needed …

__init__

__init__

__init__

__init__

__repr__

usual

__setstate__

Restores serialized data.

_build_runtime

Creates the runtime for the ONNX graph.

_check_

_check_

_check_

_find_hidden_algebras

Subgraph are using inputs not linked to the others nodes. This function retrieves them as they are stored in …

_parse_annotation

Returns the annotations for function fct_.

_to_onnx

Returns the onnx graph produced by function fct_.

_to_onnx_shape

to_onnx

Returns the ONNX graph for the wrapped function. It takes additional arguments to distinguish between multiple graphs. …

Documentation#

Implements numpy functions with onnx and a runtime.

New in version 0.6.

source on GitHub

class mlprodict.npy.onnx_numpy_compiler.OnnxNumpyCompiler(fct, op_version=None, runtime=None, signature=None, version=None, fctsig=None)#

Bases: object

Implements a class which runs onnx graph.

Parameters:
  • fct – a function with annotations which returns an ONNX graph, it can also be an ONNX graph.

  • op_versionONNX opset to use, None for the latest one

  • runtime – runtime to choose to execute the onnx graph, python, onnxruntime, onnxruntime1

  • signature – used when the function is not annotated

  • version – the same function can be instantiated with different type, this parameter is None or a numpy type if the signature allows multiple types, it must an instance of type FctVersion

  • fctsig – function used to overwrite the fct signature in case this one is using *args, **kwargs

New in version 0.6.

source on GitHub

__call__(*args, **kwargs)#

Executes the function and returns the results.

Parameters:

args – arguments

Returns:

results

source on GitHub

__getstate__()#

Serializes everything but function fct_. Function fct_ is used to build the onnx graph and is not needed anymore.

source on GitHub

__init__(fct, op_version=None, runtime=None, signature=None, version=None, fctsig=None)#
__repr__()#

usual

__setstate__(state)#

Restores serialized data.

source on GitHub

_build_runtime(op_version=None, runtime=None, signature=None, version=None)#

Creates the runtime for the ONNX graph.

Parameters:
  • op_versionONNX opset to use, None for the latest one

  • runtime – runtime to choose to execute the onnx graph, python, onnxruntime, onnxruntime1

  • signature – used when the function is not annotated

source on GitHub

_find_hidden_algebras(onx_var, onx_algebra)#

Subgraph are using inputs not linked to the others nodes. This function retrieves them as they are stored in attributes alg_hidden_var_. The function looks into every node linked to the inputs and their predecessors.

Parameters:
  • onx_varOnnxVar

  • onx_algebra – OnnxOperator

Returns:

tuple(dictionary {id(obj): (var, obj)}, all instance of OnnxVarGraph)

source on GitHub

_parse_annotation(signature, version)#

Returns the annotations for function fct_.

Parameters:
  • signature – needed if the annotation is missing, then version might be needed to specify which type to use if the signature allows many

  • version – version inside the many signatures possible

Returns:

tuple(inputs, outputs, kwargs), each of them is a list of tuple with the name and the dtype, kwargs is the list of additional parameters

source on GitHub

_to_onnx(op_version=None, signature=None, version=None)#

Returns the onnx graph produced by function fct_.

source on GitHub

_to_onnx_shape(shape)#
to_onnx(**kwargs)#

Returns the ONNX graph for the wrapped function. It takes additional arguments to distinguish between multiple graphs. This happens when a function needs to support multiple type.

Returns:

ONNX graph

source on GitHub

class mlprodict.npy.onnx_numpy_compiler.OnnxNumpyFunction(compiler, rt, inputs, outputs, n_optional, n_variables)#

Bases: object

Class wrapping a function build with OnnxNumpyCompiler.

New in version 0.6.

source on GitHub

__init__(compiler, rt, inputs, outputs, n_optional, n_variables)#
_check_(*args, **kwargs)#
class mlprodict.npy.onnx_numpy_compiler.OnnxNumpyFunctionInferenceSession(compiler, rt, inputs, outputs, n_optional, n_variables)#

Bases: OnnxNumpyFunction

Overwrites OnnxNumpyFunction to run an instance of InferenceSession from onnxruntime.

New in version 0.6.

source on GitHub

__call__(*args, **kwargs)#

Call self as a function.

class mlprodict.npy.onnx_numpy_compiler.OnnxNumpyFunctionOnnxInference(compiler, rt, inputs, outputs, n_optional, n_variables)#

Bases: OnnxNumpyFunction

Overwrites OnnxNumpyFunction to run an instance of OnnxInference.

New in version 0.6.

source on GitHub

__call__(*args, **kwargs)#

Call self as a function.