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] adaptive pool support #27747

Merged
merged 15 commits into from
Oct 12, 2020
Merged

Conversation

jczaja
Copy link
Contributor

@jczaja jczaja commented Sep 30, 2020

PR types

New features

PR changes

OPs

Describe

Added support for adaptive pooling (It was missing in oneDNN kernel) e.g. handling attribute "adaptive" and act accordingly. This is first of two fixes needed to fix #27398

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@jczaja jczaja added the Intel label Sep 30, 2020
@jczaja
Copy link
Contributor Author

jczaja commented Oct 1, 2020

@wozna, @wojtuss , @arlesniak , @arogowie-intel Please review

Comment on lines 859 to 862
ksize[0] = static_cast<int>(
ceil(static_cast<double>(src_tz[src_tz.size() - 2] / ksize[0])));
ksize[1] = static_cast<int>(
ceil(static_cast<double>(src_tz[src_tz.size() - 1] / ksize[1])));
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess you want to round up the kernel size, thus you need to cast to floating point at least one arg of division operator, otherwise both sides are integers and we have integer division. If integer division is that what you want, then cast to double is not necessary.

Suggested change
ksize[0] = static_cast<int>(
ceil(static_cast<double>(src_tz[src_tz.size() - 2] / ksize[0])));
ksize[1] = static_cast<int>(
ceil(static_cast<double>(src_tz[src_tz.size() - 1] / ksize[1])));
ksize[0] = static_cast<int>(
ceil(static_cast<double>(src_tz[src_tz.size() - 2]) / ksize[0]));
ksize[1] = static_cast<int>(
ceil(static_cast<double>(src_tz[src_tz.size() - 1]) / ksize[1]));

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest to have UT which distinguish those two slightly different rounding cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@arogowie-intel After some analysis of reference solution I restricted supported cases only to those when src_tz dims are divisible by corressponding ksize dims. This is because when we have some rounding applied then we may end up that during one pooling operation (multiple poolings over same input) pooling window size may vary , which is not supported by oneDNN.


def init_test_case(self):
self.ksize = [1, 1]
self.strides = [1, 1]
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if you could put test case triggering another calculation in additon to happy path in the mkldnn_reuse when adaptive is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@arlesniak I have added another test. Thanks for pointing out missing scenario coverage

Copy link
Contributor

@arlesniak arlesniak left a comment

Choose a reason for hiding this comment

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

LGTM

@jczaja
Copy link
Contributor Author

jczaja commented Oct 6, 2020

@luotao1 Could you please start your review?

@@ -853,6 +853,9 @@ class PoolingMKLDNNHandler : public MKLDNNHandlerT<T, mkldnn::pooling_forward,
CorrectOutputSize(src_tz, dst_tz, ksize, paddings, strides,
mkldnn_paddings[1]);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. why ctx.Attr<bool>("adaptive") is not here but inside the function ComputeAdaptivePoolParameters?

  2. In the function ComputeAdaptivePoolParameters declaration, it is not clear what will be changed, what will not. Maybe we could refer to tester_helper.cc

void TestOneThreadPrediction(const PaddlePredictor::Config *config, const std::vector<std::vector<PaddleTensor>> &inputs, 
 std::vector<std::vector<PaddleTensor>> *outputs, int num_threads, bool use_analysis = FLAGS_use_analysis)

in this way from the ComputeAdaptivePoolParameters(ctx, src_tz, &ksize, &strides);, we know what will be changed what will not.
But maybe point 2 is not important

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ComputeAdaptivePoolParameters is used in two places e.g. once inside PoolMKLDNNHandler and once directly in PoolGrad. So it was easiest for me to just read it inside rather than read it in two places and then pass as argument which would introduced tiny overhead as more data is passed to call.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, it is clear. Thanks

@@ -126,6 +126,9 @@ class PoolMKLDNNGradOpKernel : public paddle::framework::OpKernel<T> {
UpdatePadding(&paddings, global_pooling, 0, padding_algorithm, data_dims,
strides, ksize);

platform::PoolingMKLDNNHandler<T>::ComputeAdaptivePoolParameters(
Copy link
Contributor

Choose a reason for hiding this comment

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

Should UpdatePadding(&paddings, global_pooling, 0, padding_algorithm, data_dims,strides, ksize); be changed to
UpdatePadding(&paddings, global_pooling, ctx.Attr<bool>("adaptive"), padding_algorithm, data_dims,strides, ksize);, or it does not matter ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lidanqing-intel I think they should stay seprate as UpdatePadding is a common function used for CPU and oneDNN kernels (perhaps GPU as well) and computeAdaptivePoolParameters is just aplicable to oneDNN kernel.

@jczaja jczaja closed this Oct 7, 2020
@jczaja jczaja reopened this Oct 7, 2020
@jczaja jczaja closed this Oct 8, 2020
@jczaja jczaja reopened this Oct 8, 2020
@jczaja
Copy link
Contributor Author

jczaja commented Oct 9, 2020

@luotao1 Could you please start your review?

@@ -160,4 +191,6 @@ def init_shape(self):


if __name__ == '__main__':
from paddle import enable_static
enable_static()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why use enable_static only in this mkldnn unit-test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@luotao1 It should be in every test , it just I was working on that one so I added only in this one.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it.

Copy link
Contributor

@luotao1 luotao1 left a comment

Choose a reason for hiding this comment

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

LGTM

@luotao1 luotao1 merged commit 55e6376 into PaddlePaddle:develop Oct 12, 2020
chen-zhiyu pushed a commit to chen-zhiyu/Paddle that referenced this pull request Oct 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rec_r34_vd_tps_bilstm_attn(from PaddleOCR repo) MKLDNN prediction failed
5 participants