Eager mode evaluation¶
An onnxscript function can be executed directly as a Python function (for example, with a Python debugger). This is useful for debugging an onnxscript function definition. This execution makes use of a backend implementation of the ONNX ops used in the function definition. Currently, the backend implementation uses onnxruntime to execute each op invocation. This mode of execution is referred to as eager mode evaluation.
The example below illustrates this. We first define an onnxscript function:
/opt/hostedtoolcache/Python/3.10.15/x64/lib/python3.10/site-packages/onnxscript/converter.py:820: FutureWarning: 'onnxscript.values.Op.param_schemas' is deprecated in version 0.1 and will be removed in the future. Please use '.op_signature' instead.
param_schemas = callee.param_schemas()
Create inputs for evaluating the function:
np.random.seed(0)
m = 4
k = 16
n = 4
a = np.random.rand(k, m).astype("float32").T
w = np.random.rand(n, k).astype("float32").T
b = np.random.rand(n).astype("float32").T
Evaluate the function:
[[3.7695956 3.8361263 5.116064 5.2047744]
[4.5182567 4.2103305 4.54666 5.6752048]
[4.0728097 3.1566992 4.821034 4.7809625]
[4.925565 3.558134 4.7679787 5.3899584]]
/opt/hostedtoolcache/Python/3.10.15/x64/lib/python3.10/site-packages/onnxscript/evaluator.py:277: FutureWarning: 'onnxscript.values.OnnxFunction.param_schemas' is deprecated in version 0.1 and will be removed in the future. Please use '.op_signature' instead.
param_schemas = function.param_schemas()