Generating a LibProto¶

The examples below show how we can define a library consisting of multiple functions, and export it.

This is preliminary. Proto extensions are required to fully support LibProto.

from onnxscript import export_onnx_lib, script
from onnxscript import opset15 as op
from onnxscript.values import Opset

The domain/version of the library functions defined below

opset = Opset("com.mydomain", 1)

The definitions of the functions:

@script(opset)
def l2norm(X):
    return op.ReduceSum(X * X, keepdims=1)


@script(opset)
def square_loss(X, Y):
    return l2norm(op.Sub(X, Y))
/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()
/opt/hostedtoolcache/Python/3.10.15/x64/lib/python3.10/site-packages/onnxscript/converter.py:820: 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 = callee.param_schemas()

Export the functions as an ONNX library.

export_onnx_lib([l2norm, square_loss], "mylib.onnxlib")