KJlaccHoeUM9l commented on code in PR #13747:
URL: https://github.com/apache/tvm/pull/13747#discussion_r1065951135


##########
python/tvm/relay/frontend/onnx.py:
##########
@@ -4898,6 +4898,90 @@ def _impl_v10(cls, inputs, attr, params):
         return out
 
 
+class QGemm(OnnxOpConverter):
+    """Operator converter for QGemm."""
+
+    @classmethod
+    def _impl_v1(cls, inputs, attr, params):
+        # 
http://www.xavierdupre.fr/app/mlprodict/helpsphinx/onnxops/onnx_commicrosoft_QGemm.html
+
+        a = inputs[0]
+        a_scale = get_scalar(inputs[1], params)
+        a_zp = get_scalar(inputs[2], params, "int32")
+
+        b = inputs[3]
+        #  a scalar or 1D tensor of size 1 or N
+        b_scale = get_scalar_or_1d_tensor(inputs[4], params)
+        #  a scalar or 1D tensor of size 1 or N
+        b_zp = get_scalar_or_1d_tensor(inputs[5], params, "int32")
+
+        # note that if optional and not provided then value will be None.
+        C = inputs[6] if len(inputs) > 6 else None
+        # must be null or a scalar or 1D tensor of size 1
+        y_scale = inputs[7] if len(inputs) > 7 else None
+        # must be null or a scalar or 1D tensor of size 1
+        y_zp = get_scalar(inputs[8], params, "int32") if len(inputs) == 9 else 
None
+
+        assert len(infer_shape(a)) == 2
+        assert len(infer_shape(b)) == 2
+        # zero point and scale of input b should have same shape size
+        assert infer_shape(b_scale) == infer_shape(b_zp)
+
+        alpha = float(attr.get("alpha", 1.0))
+        transA = int(attr.get("transA", 0))
+        transB = int(attr.get("transB", 0))
+
+        # get number of channels
+        channels = infer_channels(inputs[3], not transB)

Review Comment:
   Could you use `b` instead of `inputs[3]` here?



##########
python/tvm/relay/frontend/onnx.py:
##########
@@ -4898,6 +4898,90 @@ def _impl_v10(cls, inputs, attr, params):
         return out
 
 
+class QGemm(OnnxOpConverter):
+    """Operator converter for QGemm."""
+
+    @classmethod
+    def _impl_v1(cls, inputs, attr, params):
+        # 
http://www.xavierdupre.fr/app/mlprodict/helpsphinx/onnxops/onnx_commicrosoft_QGemm.html
+
+        a = inputs[0]
+        a_scale = get_scalar(inputs[1], params)
+        a_zp = get_scalar(inputs[2], params, "int32")
+
+        b = inputs[3]
+        #  a scalar or 1D tensor of size 1 or N
+        b_scale = get_scalar_or_1d_tensor(inputs[4], params)
+        #  a scalar or 1D tensor of size 1 or N
+        b_zp = get_scalar_or_1d_tensor(inputs[5], params, "int32")
+
+        # note that if optional and not provided then value will be None.
+        C = inputs[6] if len(inputs) > 6 else None
+        # must be null or a scalar or 1D tensor of size 1
+        y_scale = inputs[7] if len(inputs) > 7 else None

Review Comment:
   If an optional input is not passed, then its default value is `None`. So you 
can simplify this block like this:
   ```Python
   C = inputs[6]
   y_scale = inputs[7]
   ```



##########
python/tvm/relay/frontend/onnx.py:
##########
@@ -4898,6 +4898,90 @@ def _impl_v10(cls, inputs, attr, params):
         return out
 
 
+class QGemm(OnnxOpConverter):
+    """Operator converter for QGemm."""
+
+    @classmethod
+    def _impl_v1(cls, inputs, attr, params):
+        # 
http://www.xavierdupre.fr/app/mlprodict/helpsphinx/onnxops/onnx_commicrosoft_QGemm.html
+
+        a = inputs[0]
+        a_scale = get_scalar(inputs[1], params)
+        a_zp = get_scalar(inputs[2], params, "int32")
+
+        b = inputs[3]
+        #  a scalar or 1D tensor of size 1 or N
+        b_scale = get_scalar_or_1d_tensor(inputs[4], params)
+        #  a scalar or 1D tensor of size 1 or N

Review Comment:
   Could you please add comments above that describe the shapes for tensors `A` 
and `B` to understand what `N` is.



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