TaylorHere commented on issue #11783:
URL: https://github.com/apache/tvm/issues/11783#issuecomment-1163402246

   ```python
   import numpy as np
   import onnx
   from tvm.driver import tvmc
   
   def create_initializer_tensor(
       name: str,
       tensor_array: np.ndarray,
       data_type: onnx.TensorProto = onnx.TensorProto.FLOAT,
   ) -> onnx.TensorProto:
       return onnx.helper.make_tensor(
           name=name,
           data_type=data_type,
           dims=tensor_array.shape,
           vals=tensor_array.flatten().tolist(),
       )
   
   
   input_4001_np = np.ones(shape=(1,)).astype(np.int64)
   
   input_4001 = create_initializer_tensor(
       name="input_4001", tensor_array=input_4001_np, 
data_type=onnx.TensorProto.INT64
   )
   
   attr_value = onnx.helper.make_tensor("input_value", onnx.TensorProto.INT64, 
[1], [1])
   
   output_892 = onnx.helper.make_tensor_value_info(
       "output_892", onnx.TensorProto.INT64, [1]
   )
   
   
   ConstantOfShape_704 = onnx.helper.make_node(
       name="ConstantOfShape_704",
       op_type="ConstantOfShape",
       inputs=["input_4001"],
       outputs=["output_892"],
       value=attr_value,
   )
   
   input_4000_np = np.ones(shape=(3, 2)).astype(np.int64)
   
   input_4000 = create_initializer_tensor(
       name="input_4000", tensor_array=input_4000_np, 
data_type=onnx.TensorProto.INT64
   )
   
   output_893 = onnx.helper.make_tensor_value_info(
       "output_893", onnx.TensorProto.INT64, [3, 2]
   )
   
   Expand_705 = onnx.helper.make_node(
       name="Expand_705",
       op_type="Expand",
       inputs=["input_4000", "output_892"],
       outputs=["output_893"],
   )
   
   # Create the graph (GraphProto)
   graph_def = onnx.helper.make_graph(
       nodes=[ConstantOfShape_704, Expand_705],
       name="constantOfShape->Expand",
       inputs=[],
       outputs=[output_893],
       initializer=[input_4001, input_4000],
   )
   
   # Create the model (ModelProto)
   model_def = onnx.helper.make_model(graph_def, producer_name="onnx-example")
   model_def.opset_import[0].version = 13
   
   model_def = onnx.shape_inference.infer_shapes(model_def)
   
   onnx.checker.check_model(model_def)
   
   onnx.save(model_def, "convnet.onnx")
   
   mod = tvmc.load('convnet.onnx')
   tvmc.compile(mod, 'llvm')
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to