ThanatosShinji / onnx-tool

A parser, editor and profiler tool for ONNX models.
https://pypi.org/project/onnx-tool/
MIT License
399 stars 52 forks source link

High-dimension Matmul MACs calculation error #30

Closed haojin2 closed 1 year ago

haojin2 commented 1 year ago

Describe the bug Gives wrong answer on higher-dimensional matmul operations: https://github.com/ThanatosShinji/onnx-tool/blob/main/onnx_tool/node.py#L642-L656

To Reproduce e.g. a matmul with operands with shape (2, 3)and (4, 3, 5) is a batch matmul, should give a result with shape (4, 2, 5) The current code will just give the result for MACs as 2 3 5 which is not correct, where we also need to take into account the batch dim 4.

ThanatosShinji commented 1 year ago

Thanks for your report! I've confirmed it's a broadcast bug.

ThanatosShinji commented 1 year ago

Can provide the shape_infer result of the current code on your model? I suspect the resulting shape is also wrong too.

haojin2 commented 1 year ago

yeah the shape_infer would just give (2, 5) for the above case, ignoring the batch dim 4

ThanatosShinji commented 1 year ago

The bug is fixed in the main branch. The code will be released after all model tests.

haojin2 commented 1 year ago

Do you have ETA for the release?

ThanatosShinji commented 1 year ago

One new feature is about to release. So there won't be a release only for this bug. You can checkout the main branch code and install it with your pip.

ThanatosShinji commented 1 year ago

you can install v0.7.1 to test the fix of this bug now.

haojin2 commented 1 year ago

Thanks, closing the issue.