AndrewZhaoLuo commented on a change in pull request #8907:
URL: https://github.com/apache/tvm/pull/8907#discussion_r701310382
##########
File path: python/tvm/relay/frontend/onnx.py
##########
@@ -195,6 +195,17 @@ def _dim_check(attrs):
return _dim_check, "Only 1d, 2d and 3d kernel supported."
+def get_scalar(x, params, dtype="float32"):
+ """Helper to get a scalar value for Quantized operators."""
+ if isinstance(x, _expr.Var) and x.name_hint in params:
Review comment:
Should we throw an error if it's a var we can't look up in params
##########
File path: tests/python/frontend/onnx/test_forward.py
##########
@@ -5266,6 +5266,39 @@ def repeat(N, D):
)
[email protected]_targets
+def test_qlinearconcat(target, dev):
+ def verify_qlinearconcat(shapes, out_shape, axis=None):
+ input_names = []
+ input_values = []
+ input_nodes = []
+ for i in range(len(shapes)):
+ tensor_name = str(chr(ord("a") + i))
Review comment:
nit: I believe `chr` returns a string so no need to wrap it with `str`
##########
File path: python/tvm/relay/frontend/onnx.py
##########
@@ -3306,6 +3290,32 @@ def get_scalar(x, dtype="float32"):
return _qnn.op.quantize(out, y_scale, y_zero_point, out_dtype=dtype)
+class QLinearConcat(OnnxOpConverter):
+ """Operator converter for QLinearConcat from Microsoft onnxruntime contrib
opset."""
+
+ @classmethod
+ def _impl_v1(cls, inputs, attr, params):
+ # which axis to concat on
+ axis = attr["axis"]
+
+ y_scale = fold_constant(get_scalar(inputs[0], params))
+ y_zero_point = get_scalar(inputs[1], params, "int32")
+
+ # input tensors, scales, zero_points
+ assert (
+ len(inputs) % 3 == 2
+ ), "Additional input count must be a multiple of 3 --
tensor/scale/zero_point tuples"
+ tensors = []
+ scales = []
+ zero_points = []
+ for i in range(2, len(inputs), 3):
Review comment:
Though it looks like your tests pass so idk.
##########
File path: python/tvm/relay/frontend/onnx.py
##########
@@ -3306,6 +3290,32 @@ def get_scalar(x, dtype="float32"):
return _qnn.op.quantize(out, y_scale, y_zero_point, out_dtype=dtype)
+class QLinearConcat(OnnxOpConverter):
+ """Operator converter for QLinearConcat from Microsoft onnxruntime contrib
opset."""
+
+ @classmethod
+ def _impl_v1(cls, inputs, attr, params):
+ # which axis to concat on
+ axis = attr["axis"]
+
+ y_scale = fold_constant(get_scalar(inputs[0], params))
+ y_zero_point = get_scalar(inputs[1], params, "int32")
+
+ # input tensors, scales, zero_points
+ assert (
+ len(inputs) % 3 == 2
+ ), "Additional input count must be a multiple of 3 --
tensor/scale/zero_point tuples"
+ tensors = []
+ scales = []
+ zero_points = []
+ for i in range(2, len(inputs), 3):
Review comment:
Based on the spec it seems like these things should be packaged as
tuples
https://github.com/microsoft/onnxruntime/blob/master/docs/ContribOperators.md#com.microsoft.QLinearConcat
--
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]