{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Generating a LibProto\n\nThe examples below show how we can define a library consisting of multiple functions,\nand export it.\n\n**This is preliminary. Proto extensions are required to fully support LibProto.**\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from onnxscript import export_onnx_lib, script\nfrom onnxscript import opset15 as op\nfrom onnxscript.values import Opset" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The domain/version of the library functions defined below\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "opset = Opset(\"com.mydomain\", 1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The definitions of the functions:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "@script(opset)\ndef l2norm(X):\n return op.ReduceSum(X * X, keepdims=1)\n\n\n@script(opset)\ndef square_loss(X, Y):\n return l2norm(op.Sub(X, Y))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Export the functions as an ONNX library.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "export_onnx_lib([l2norm, square_loss], \"mylib.onnxlib\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.14" } }, "nbformat": 4, "nbformat_minor": 0 }