{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# ModelProto Properties\n\nA ModelProto, in ONNX, usually stores extra information beyond the\ncomputational graph, such as `ir_version` or `producer_name`.\nSuch properties of a generated ModelProto can be set by passing in extra named\nparameters to the call to script (or the call to `to_model_proto`),\nas illustrated by the example below.\nOnly the valid fields defined in the protobuf message ModelProto should\nbe specified in this fashion.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "First, we define the implementation of a square-loss function in onnxscript.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import onnx\n\nfrom onnxscript import FLOAT, script\nfrom onnxscript import opset15 as op\n\n\n@script(ir_version=7, producer_name=\"OnnxScript\", producer_version=\"0.1\")\ndef square_loss(X: FLOAT[\"N\"], Y: FLOAT[\"N\"]) -> FLOAT[1]:  # noqa: F821\n    diff = X - Y\n    return op.ReduceSum(diff * diff, keepdims=1)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Let's see what the generated model looks like.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "model = square_loss.to_model_proto()\nprint(onnx.printer.to_text(model))"
      ]
    }
  ],
  "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.16"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}