
Contents
More
Translates an ONNX proto into a code usingLight API for ONNX: everything in one lineto describe the ONNX graph.
proto – model to translate
single_line – as a single line or not
api – API to export into,default is“light” and this is handle by classonnx_array_api.translate_api.light_emitter.LightEmitter,another value is“onnx” which is the inner API implementedin onnx package,“builder” follows the syntax for theclassonnx_array_api.graph_api.GraphBuilder
code
<<<
fromonnx_array_api.light_apiimportstartfromonnx_array_api.translate_apiimporttranslateonx=(start().vin("X").reshape((-1,1)).Transpose(perm=[1,0]).rename("Y").vout().to_onnx())code=translate(onx)print(code)
>>>
(start(opset=22).cst(np.array([-1,1],dtype=np.int64)).rename('r').vin('X',elem_type=TensorProto.FLOAT).bring('X','r').Reshape().rename('r0_0').bring('r0_0').Transpose(perm=[1,0]).rename('Y').bring('Y').vout(elem_type=TensorProto.FLOAT).to_onnx())
The inner API from onnx package is also available.
<<<
fromonnx_array_api.light_apiimportstartfromonnx_array_api.translate_apiimporttranslateonx=(start().vin("X").reshape((-1,1)).Transpose(perm=[1,0]).rename("Y").vout().to_onnx())code=translate(onx,api="onnx")print(code)
>>>
opset_imports=[make_opsetid('',22),]inputs=[]outputs=[]nodes=[]initializers=[]sparse_initializers=[]functions=[]initializers.append(from_array(np.array([-1,1],dtype=np.int64),name='r'))inputs.append(make_tensor_value_info('X',TensorProto.FLOAT,shape=[]))nodes.append(make_node_extended('Reshape',['X','r'],['r0_0']))nodes.append(make_node_extended('Transpose',['r0_0'],['Y'],perm=[1,0]))outputs.append(make_tensor_value_info('Y',TensorProto.FLOAT,shape=[]))graph=make_graph(nodes,'light_api',inputs,outputs,initializers,sparse_initializer=sparse_initializers,)model=make_model(graph,functions=functions,opset_imports=opset_imports)
TheGraphBuilder API returns this:
<<<
fromonnx_array_api.light_apiimportstartfromonnx_array_api.translate_apiimporttranslateonx=(start().vin("X").reshape((-1,1)).Transpose(perm=[1,0]).rename("Y").vout().to_onnx())code=translate(onx,api="builder")print(code)
>>>
deflight_api(op:"GraphBuilder",X:"FLOAT[]",):r=np.array([-1,1],dtype=np.int64)r0_0=op.Reshape(X,r)Y=op.Transpose(r0_0,perm=[1,0])op.Identity(Y,outputs=["Y"])returnYg=GraphBuilder({'':22},ir_version=11)g.make_tensor_input("X",TensorProto.FLOAT,())light_api(g.op,"X")g.make_tensor_output("Y",TensorProto.FLOAT,(),is_dimension=False,indexed=False)model=g.to_onnx()
Constructs a NodeProto.
op_type – The name of the operator to construct
inputs – list of input names
outputs – list of output names
name – optional unique identifier for NodeProto
doc_string – optional documentation string for NodeProto
domain – optional domain for NodeProto.If it’s None, we will just use default domain (which is empty)
kwargs – the attributes of the node.
node proto
Creates an attribute.
key – atttribute name
attr_type – attribute type
ref_attr_name – if not None, link this attributeto a function attribute
attribute
Translates an ONNX graph into a code following the light API.