-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Replace matmul(v2) with fused_matmul during oneDNN fuse passes #49515
Replace matmul(v2) with fused_matmul during oneDNN fuse passes #49515
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
…/Paddle into remove_extra_matmul_attrs
paddle/fluid/framework/ir/mkldnn/reshape_transpose_matmul_mkldnn_fuse_pass.cc
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODOs
Co-authored-by: Tomasz Socha <[email protected]>
Co-authored-by: Tomasz Socha <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@raindrops2sea @XiaoguangHu01 please help to review~ |
@@ -84,6 +84,12 @@ void MatmulTransposeReshapeMKLDNNPass::Fuse( | |||
} | |||
|
|||
OpDesc *matmul_desc = matmul_op->Op(); | |||
matmul_desc->SetType("fused_matmul"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There have some broadcast
computational logic difference between matmul_v1
and matmul_v2
, the code as follows
import paddle
data1 = paddle.rand((3, 1, 10, 10))
data2 = paddle.rand((1, 2, 10, 10))
# The paddle.matmul (matmul_v2)
paddle.matmul(data1, data2).shape # [3, 2, 10, 10]
# The fluid.layers.matmul (matmul_v1)
paddle.fluid.layers.matmul(data1, data2).shape # 直接报错
# ValueError: (InvalidArgument) The batch size of the two matrices should be equal, or at least one is zero.
# But received X's shape: [3, 10, 10], Y's shape: [2, 10, 10]
Is there some problems when replacing directly ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I don't think that it could be problem. For some time oneDNN version of both matmul
and matmul_v2
are already using same code #44640, #48162. Declared attributes of these two are mostly the same. Only difference is alpha
not supported in matmul_v2
, and transpose
is renamed to trans
).
Goal of this PR is just to extract fusion logic from base op and base kernel. Fused op is superset, which has all extra attributes declared in OPMaker and fused kernel has implemented support for handling fusion logic.
I've adjusted all fuse pass unit test to work with fused_matmul
. Also this PR has been checked in our internal validation and it didn't report any accuracy drop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for data type Registeration
PR types
Others
PR changes
OPs
Describe
fused_matmul
to handle fusion logic from oneDNNmatmul
andmatmul_v2
fuse passes ,matmul_v2
op and kernel,