ModelProto Properties¶
A ModelProto, in ONNX, usually stores extra information beyond the
computational graph, such as ir_version
or producer_name
.
Such properties of a generated ModelProto can be set by passing in extra named
parameters to the call to script (or the call to to_model_proto
),
as illustrated by the example below.
Only the valid fields defined in the protobuf message ModelProto should
be specified in this fashion.
First, we define the implementation of a square-loss function in onnxscript.
/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()
Let’s see what the generated model looks like.
model = square_loss.to_model_proto()
print(onnx.printer.to_text(model))
<
ir_version: 7,
opset_import: ["" : 15],
producer_name: "OnnxScript",
producer_version: "0.1"
>
square_loss (float[N] X, float[N] Y) => (float[1] return_val) {
diff = Sub (X, Y)
tmp = Mul (diff, diff)
return_val = ReduceSum <keepdims: int = 1> (tmp)
}