AndrewZhaoLuo commented on a change in pull request #9186:
URL: https://github.com/apache/tvm/pull/9186#discussion_r724389698



##########
File path: python/tvm/relay/frontend/onnx.py
##########
@@ -873,6 +874,73 @@ def flatten_to_nd(x, x_shape, nd=3):
         return _op.nn.dense(inputs[0], input_1_t)
 
 
+class MatMulInteger16(OnnxOpConverter):
+    """Operator converter for MatMulInteger16 from Microsoft onnxruntime 
contrib opset."""
+
+    @classmethod
+    def _impl_v10(cls, inputs, attr, params):
+        assert len(inputs) == 2, "MatMul op take 2 inputs, {} 
given".format(len(inputs))
+        a_shape = shape_of(inputs[0])
+        a_rank = infer_shape(a_shape)[0]
+        b_shape = shape_of(inputs[1])
+        b_rank = infer_shape(b_shape)[0]
+        a_dtype = infer_type(inputs[0]).checked_type.dtype

Review comment:
       To grab the rank and dtype you only need one pass of infer_type. 
infer_shape calls infer_type internally so you can get rid of a call by doing 
something like
   
   a_relay_type = infer_type(a).checked_type
   a_dtype = a_relay_type.dtype 
   a_rank = len(a_relay-type.shape)

##########
File path: python/tvm/relay/frontend/onnx.py
##########
@@ -873,6 +874,73 @@ def flatten_to_nd(x, x_shape, nd=3):
         return _op.nn.dense(inputs[0], input_1_t)
 
 
+class MatMulInteger16(OnnxOpConverter):
+    """Operator converter for MatMulInteger16 from Microsoft onnxruntime 
contrib opset."""
+
+    @classmethod
+    def _impl_v10(cls, inputs, attr, params):
+        assert len(inputs) == 2, "MatMul op take 2 inputs, {} 
given".format(len(inputs))
+        a_shape = shape_of(inputs[0])
+        a_rank = infer_shape(a_shape)[0]
+        b_shape = shape_of(inputs[1])
+        b_rank = infer_shape(b_shape)[0]
+        a_dtype = infer_type(inputs[0]).checked_type.dtype
+        b_dtype = infer_type(inputs[1]).checked_type.dtype
+        # Check input data types
+        assert a_dtype in ("int16", "uint16"), "MatMulInteger16: invalid dtype 
for first input"
+        assert b_dtype in ("int16", "uint16"), "MatMulInteger16: invalid dtype 
for second input"
+        out_dtype = "int32"
+        if a_dtype == "uint16" and b_dtype == "uint16":
+            out_dtype = "uint32"
+        if a_rank > 2 or b_rank > 2:
+            b_type = infer_type(inputs[1])

Review comment:
       If you do the above, this will no longer be needed to since you'll 
already have a variable in scope

##########
File path: python/tvm/relay/frontend/onnx.py
##########
@@ -873,6 +874,73 @@ def flatten_to_nd(x, x_shape, nd=3):
         return _op.nn.dense(inputs[0], input_1_t)
 
 
+class MatMulInteger16(OnnxOpConverter):
+    """Operator converter for MatMulInteger16 from Microsoft onnxruntime 
contrib opset."""
+
+    @classmethod
+    def _impl_v10(cls, inputs, attr, params):
+        assert len(inputs) == 2, "MatMul op take 2 inputs, {} 
given".format(len(inputs))
+        a_shape = shape_of(inputs[0])

Review comment:
       A lot of this is just identical to MatMul except for the logic on types. 
Can you refactor Matmul to make it extensible and use it in this situation 
instead of copying most of the code?




-- 
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