-
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
[oneDNN] adaptive pool support #27747
Conversation
Thanks for your contribution! |
@wozna, @wojtuss , @arlesniak , @arogowie-intel Please review |
paddle/fluid/platform/mkldnn_reuse.h
Outdated
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]))); |
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.
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.
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])); |
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.
I'd suggest to have UT which distinguish those two slightly different rounding cases.
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.
@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] |
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.
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.
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.
@arlesniak I have added another test. Thanks for pointing out missing scenario coverage
test=develop
test=develop
test=develop
test=develop
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
@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]); | |||
} | |||
|
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.
-
why
ctx.Attr<bool>("adaptive")
is not here but inside the functionComputeAdaptivePoolParameters
? -
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
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.
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.
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.
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( |
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.
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 ?
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.
@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.
@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() |
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.
Why use enable_static
only in this mkldnn unit-test?
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.
@luotao1 It should be in every test , it just I was working on that one so I added only in this one.
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.
Got it.
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
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