Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fusing of Conv and Mul in TransposeOptimizer (#2088) #2152

Merged
merged 1 commit into from
May 4, 2023

Conversation

cosineFish
Copy link
Contributor

Should not fuse Conv and Mul if the constant input of Mul is not with shape [N] or [1,..,1,N].

@fatcat-z
Copy link
Collaborator

Thanks for your contributions!

Could you please add some details about what kind of issues will be caused without this change?

@cosineFish
Copy link
Contributor Author

Thanks for your contributions!

Could you please add some details about what kind of issues will be caused without this change?

Sure.
The reason why this change is needed is from the implementation of conv, weights of conv is only linearly related with output channels(bias is required to be not set for _mul_handler):
image

If perm of the transpose node before mul node is NCHW_TO_NHWC(the most possible case), then the multipler can be merged into weights of conv only if its shape is in (1...1, Cout).

Without this change, incorrect fusing will be made and issues like #2088 will be caused. The reason why the test in #2088 fails is that after fusing conv+transpose+mul, weights of conv is incorrectly changed from shape [512,1,3,3] to [512,2,3,3].

Should not fuse Conv and Mul if the constant input of Mul is not with
shape [N] or [1,..,1,N].

Signed-off-by: cosine <cosine_chen@163.com>
Copy link
Collaborator

@fatcat-z fatcat-z left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@fatcat-z fatcat-z merged commit 14f4a5f into onnx:main May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants