You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2021/09/22 20:16:33 UTC

[GitHub] [tvm] AndrewZhaoLuo commented on a change in pull request #9063: [ONNX] [#8838] QLinearLeakyRelu contrib op

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



##########
File path: python/tvm/relay/frontend/onnx.py
##########
@@ -3430,6 +3430,25 @@ def _impl_v10(cls, inputs, attr, params):
         return _qnn.op.quantize(out, y_scale, y_zero_point, out_dtype=dtype)
 
 
+class QLinearLeakyRelu(OnnxOpConverter):
+    """Operator converter for QLinearLeakyRelu from Microsoft onnxruntime contrib opset."""
+
+    @classmethod
+    def _impl_v10(cls, inputs, attr, params):
+
+        a_scale = get_scalar(inputs[1], params)
+        a_zero_point = get_scalar(inputs[2], params, "int32")
+        y_scale = fold_constant(get_scalar(inputs[3], params))
+        y_zero_point = get_scalar(inputs[4], params, "int32")
+        alpha = float(attr.get("alpha", 1.0))
+
+        dtype = infer_type(inputs[0]).checked_type.dtype
+
+        a = _qnn.op.dequantize(inputs[0], a_scale, a_zero_point)
+        out = _op.nn.leaky_relu(a, alpha)
+        return _qnn.op.quantize(out, y_scale, y_zero_point, out_dtype=dtype)

Review comment:
       If alpha is a power of two e.g. 1 / 16 or 1 / 8, then we can implement this via bit shift operations assuming zero can be represented in the quantization scheme. Not making a suggestion or anything, just thought it was an interesting point.




-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org