AndrewZhaoLuo commented on a change in pull request #9911:
URL: https://github.com/apache/tvm/pull/9911#discussion_r785194825
##########
File path: python/tvm/relay/frontend/onnx.py
##########
@@ -268,6 +256,40 @@ def flatten_to_nd(x, x_shape, nd=3):
],
0,
)
+
+ b_type = infer_type(inputs[1])
+ # Convert to dense if the second matrix is 2d and non-dynamic
+ if b_rank == 2 and not _ty.is_dynamic(b_type.checked_type):
+ a = flatten_to_nd(inputs[0], a_shape, 2)
+ b = _op.transpose(inputs[1])
+ output = _op.nn.dense(a, b, out_dtype=out_dtype)
+ else:
+ # broadcast a and b
+ a_broadcasted_shape = _op.concatenate(
+ [
+ out_batch,
+ _op.strided_slice(
+ a_shape, [infer_shape(a_shape)[0] - 2],
[infer_shape(a_shape)[0]]
+ ),
+ ],
+ 0,
+ )
+ b_broadcasted_shape = _op.concatenate(
+ [
+ out_batch,
+ _op.strided_slice(
+ b_shape, [infer_shape(b_shape)[0] - 2],
[infer_shape(b_shape)[0]]
Review comment:
same here, use b_rank
--
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]