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

INTEL MKL: Enhance MkL BatchNorm ops with primitive reuse #19402

Merged

Conversation

gzmkl
Copy link
Contributor

@gzmkl gzmkl commented May 18, 2018

Enable MKL BatchNorm ops with primitive reuse, to improve
(1) model training and
(2) inference of small batch size
by minimizing primitive creation time.

************ Notes *******************
Please review and merge this PR first
#19399

@gzmkl
Copy link
Contributor Author

gzmkl commented May 21, 2018

Close temporarily - pending conv_bwd PR

@gzmkl gzmkl closed this May 21, 2018
@gzmkl
Copy link
Contributor Author

gzmkl commented May 21, 2018

mkl_conv_ops.cc has been reverted to avoid any review confusion.
The new version of mkl_conv_ops.cc is contained in PR #19399.

Thanks

@gzmkl gzmkl reopened this May 21, 2018
@drpngx drpngx requested a review from rmlarsen June 4, 2018 15:59
@drpngx drpngx added the awaiting review Pull request awaiting review label Jun 4, 2018
@gzmkl
Copy link
Contributor Author

gzmkl commented Jun 4, 2018

Pending on #19754

@gzmkl gzmkl closed this Jun 4, 2018
@gzmkl
Copy link
Contributor Author

gzmkl commented Jul 4, 2018

Reopen since PR #19399 has been merged

@gzmkl gzmkl reopened this Jul 4, 2018
@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@yiqianglee
Copy link
Contributor

Yes, i have already singed CLA, and should be ok to contribute.

@gzmkl
Copy link
Contributor Author

gzmkl commented Jul 18, 2018

Hi,
I am the PR submitter and confirm that I am OK with all the changes made by yiqianglee.
Thanks,
GZ

@rmlarsen
Copy link
Member

@gzmkl I think many of my comments for PR 19403 would apply to this as well, please modify accordingly.

@rmlarsen rmlarsen added cla: yes and removed cla: no labels Jul 19, 2018
@googlebot
Copy link

A Googler has manually verified that the CLAs look good.

(Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.)

@gzmkl
Copy link
Contributor Author

gzmkl commented Jul 19, 2018

Plan to apply PR 19403 comments on this PR too.

@tensorflowbutler tensorflowbutler removed the awaiting review Pull request awaiting review label Jul 20, 2018
@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@gzmkl
Copy link
Contributor Author

gzmkl commented Jul 24, 2018

Latest code change based on PR 19403 code review suggestions.
Summary:
(1) Change signature of Execute (...) so that input parameters are declared as "const" while output parameter as "non-const".
(2) In many places, remove unnecessary static_cast and const_cast to simplify the code.
(3) Back-out code in SetOp() method (mkl_util.h) - using "emplace" causes unit test failures of ops/nn_grad_test.py.
(4) Minor changes in some comment statements to make descriptions more accurate.
BTW, related code review suggestions from PR 19399 & 19400 have also been reflected in this PR.

@rmlarsen
Copy link
Member

@gzmkl Thanks for the update. Let's try to get PR 19403 merged first before we push the remaining PRs. Running tests for it again now.

(*diff_src_tensor)->flat<T>().data()[i] = 0;
int num_elements = (*diff_src_tensor)->shape().num_elements();
auto diff_src_data = (*diff_src_tensor)->flat<T>().data();
for (size_t i = 0; i < num_elements; i++)
Copy link
Member

Choose a reason for hiding this comment

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

I would use std::fill instead of a loop. Same everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I will do.
There are places in files which are not changed in this PR. Should I do the same change?

Copy link
Member

Choose a reason for hiding this comment

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

Please do. :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have done code refactoring for multiple places in mkl_fused_batch_norm_op.cc.

To avoid potential merge conflicts, I did not apply this code change recommendation to
source files not related to this PR.

We will include this suggestion, along with others (such as changing signature of Execute()
with proper const or non-const argument declarations), to create a separate "code clean up"
PR.

Thanks!

@rmlarsen
Copy link
Member

@gzmkl resolved conflict

@googlebot
Copy link

A Googler has manually verified that the CLAs look good.

(Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.)

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@rmlarsen rmlarsen added cla: yes ready to pull PR ready for merge process and removed cla: no labels Aug 1, 2018
@googlebot
Copy link

A Googler has manually verified that the CLAs look good.

(Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.)

@gzmkl
Copy link
Contributor Author

gzmkl commented Aug 7, 2018

Hi Rasmus,

Please choose "master" version to address the following conflict in mkl_util.h

<<<<<<< primreuse_batch_norm
#include

master

Line of "#include " seems to be duplicated.

@gzmkl
Copy link
Contributor Author

gzmkl commented Aug 7, 2018

Please take the branch code with the following conflict
<<<<<<< primreuse_batch_norm
#include "tensorflow/core/platform/cpu_info.h" // Keep this line

master

Thanks!

@tensorflow-copybara tensorflow-copybara merged commit 8e2f587 into tensorflow:master Aug 7, 2018
tensorflow-copybara pushed a commit that referenced this pull request Aug 7, 2018
@@ -262,6 +262,7 @@ class MklFusedBatchNormOp : public OpKernel {
}

void MklCreateInputLayout(OpKernelContext* context) {
const Tensor& input = MklGetInput(context, 0);
Copy link
Member

Choose a reason for hiding this comment

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

Just curious, why do we have this line? This local variable isn't used anywhere in the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should not be there. See more comment below.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you!

@@ -544,6 +545,7 @@ class MklFusedBatchNormGradOp : public OpKernel {
}

void MklCreateInputLayout(OpKernelContext* context) {
const Tensor& input = MklGetInput(context, 0);
Copy link
Member

Choose a reason for hiding this comment

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

This local variable also isn't used anywhere in this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch!

Yes, this line of code should be there. And it was in a function with MKL-ML integration which will be removed in the long run since we have MKL-DNN integration.

I will clean up this code, after all primitive reuse PRs have been done (only Relu one remains). I have a TODO list based on Rasmus's suggestions, which were applied only to individual PRs (thus
only on related changed files), and will have a "clean-up" PR.

Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for your clarification!

@claynerobison claynerobison deleted the primreuse_batch_norm branch March 22, 2019 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes ready to pull PR ready for merge process
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants