module npy.onnx_numpy_compiler
#
Short summary#
module mlprodict.npy.onnx_numpy_compiler
Implements numpy functions with onnx and a runtime.
Classes#
class |
truncated documentation |
---|---|
Implements a class which runs onnx graph. |
|
Class wrapping a function build with |
|
Overwrites |
|
Overwrites |
Methods#
method |
truncated documentation |
---|---|
Executes the function and returns the results. |
|
Serializes everything but function fct_. Function fct_ is used to build the onnx graph and is not needed … |
|
|
|
|
|
usual |
|
Restores serialized data. |
|
Creates the runtime for the ONNX graph. |
|
|
|
|
|
Subgraph are using inputs not linked to the others nodes. This function retrieves them as they are stored in … |
|
Returns the annotations for function fct_. |
|
Returns the onnx graph produced by function fct_. |
|
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.
- 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_version – ONNX 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.
- __call__(*args, **kwargs)#
Executes the function and returns the results.
- Parameters:
args – arguments
- Returns:
results
- __getstate__()#
Serializes everything but function fct_. Function fct_ is used to build the onnx graph and is not needed anymore.
- __init__(fct, op_version=None, runtime=None, signature=None, version=None, fctsig=None)#
- __repr__()#
usual
- __setstate__(state)#
Restores serialized data.
- _build_runtime(op_version=None, runtime=None, signature=None, version=None)#
Creates the runtime for the ONNX graph.
- Parameters:
op_version – ONNX 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
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_var –
OnnxVar
onx_algebra – OnnxOperator
- Returns:
tuple(dictionary {id(obj): (var, obj)}, all instance of
OnnxVarGraph
)
- _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
- _to_onnx(op_version=None, signature=None, version=None)#
Returns the onnx graph produced by function fct_.
- _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
- 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.
- __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.
- __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 ofOnnxInference
.New in version 0.6.
- __call__(*args, **kwargs)#
Call self as a function.