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

[OneDNN] Fc elementwise add fusion #58276

Open
wants to merge 50 commits into
base: develop
Choose a base branch
from

Conversation

zhanglirong1999
Copy link
Contributor

PR types

New features

PR changes

Others

Description

Paddle does not support in-place computation now, implement fc_elementise_add using fc + binary_add. It is also a re-implementation of the previous PR #55504 directly delete the pass to solve the accuracy problem.

@paddle-bot
Copy link

paddle-bot bot commented Oct 20, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added the contributor External developers label Oct 20, 2023
@zhanglirong1999 zhanglirong1999 changed the title Fc elementwise add fusion [OneDNN] Fc elementwise add fusion Oct 20, 2023
@xinyu-intel xinyu-intel self-requested a review October 20, 2023 08:16
@zhanglirong1999 zhanglirong1999 force-pushed the fc_elementwise_add_fusion branch 5 times, most recently from 1a16786 to a6016d5 Compare October 23, 2023 02:19
Copy link

paddle-ci-bot bot commented Nov 2, 2023

Sorry to inform you that 436e6df's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

paddle/fluid/inference/api/paddle_pass_builder.cc Outdated Show resolved Hide resolved
paddle/fluid/inference/api/paddle_pass_builder.cc Outdated Show resolved Hide resolved
Comment on lines 176 to 177
auto residual_data_md = dnnl::memory::desc(
{MB, OC}, dnnl::memory::data_type::f32, dnnl::memory::format_tag::ab);
Copy link
Contributor

Choose a reason for hiding this comment

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

recommend to get_mdesc from the residual input tensor instead of assumption here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For inner product primitive, the dst is always NC(mentioned in doc). That's why we can not use residual mdesc directly, have to make sure residual md shape is NC.

Copy link
Contributor

Choose a reason for hiding this comment

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

when the residual won't be NC? BTW, the data type can also be bf16, right?

paddle/fluid/operators/mkldnn/fc_mkldnn_op.cc Outdated Show resolved Hide resolved
paddle/fluid/operators/mkldnn/fc_mkldnn_op.cc Outdated Show resolved Hide resolved
paddle/fluid/operators/mkldnn/fc_mkldnn_op.cc Outdated Show resolved Hide resolved
@@ -506,6 +623,10 @@ class FCMKLDNNKernel : public framework::OpKernel<T_in> {
ip_cache->src_mem = *src_memory_p;
ip_cache->weights_mem = *weights_memory_p;
ip_cache->dst_mem = *dst_memory_p;
if (residual_data && residual_data_memory_p) {
ip_cache->residual_data = *residual_data;
Copy link
Contributor

Choose a reason for hiding this comment

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

why need cache residual_data?

Comment on lines +44 to +45
# 'Scale_in_eltwise': self.residual_scale,
# 'fuse_residual_connection': True
Copy link
Contributor

Choose a reason for hiding this comment

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

is it expected?

@xinyu-intel
Copy link
Contributor

@LLee233 Please help on a review, thanks:)

out->dims(),
residual_param->dims(),
phi::errors::InvalidArgument(
"Output and elementwise parameter need to have the "
Copy link
Contributor

Choose a reason for hiding this comment

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

after using post_binary_add, do we still need to force residual data and dst to have same dims? I just think binary-add should support broadcast.

paddle/fluid/operators/mkldnn/fc_mkldnn_op.cc Outdated Show resolved Hide resolved
@zhanglirong1999 zhanglirong1999 force-pushed the fc_elementwise_add_fusion branch 2 times, most recently from 8950d76 to 300015a Compare November 3, 2023 08:31
Copy link
Contributor

@LLee233 LLee233 left a comment

Choose a reason for hiding this comment

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

By the way, just want to ask if we should still keep "fc_eltwise_add" since now it becomes "binary_add" (have extra input).

// For Inner Product primitives, the destination always N * C
auto residual_data = ctx.Input<phi::DenseTensor>("ResidualData");
auto residual_data_md =
dnnl::memory::desc({MB, OC},
Copy link
Contributor

Choose a reason for hiding this comment

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

Does residual_data_md should have determined shape? Since binary_add has enabled broadcast, maybe {1, 1} or {MB, 1} is also good?

@zhanglirong1999 zhanglirong1999 force-pushed the fc_elementwise_add_fusion branch 3 times, most recently from c1da50a to f70bfbc Compare November 7, 2023 06:31
@zhanglirong1999
Copy link
Contributor Author

@XieYunshen , hi, could you please help me approve the setting TIMEOUT properties?

@zhanglirong1999
Copy link
Contributor Author

@XiaoguangHu01 , hi, could you help me approve CI 'the usage of const_cast'? thanks

Copy link

paddle-ci-bot bot commented Nov 15, 2023

Sorry to inform you that f70bfbc's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers Intel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants