-
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
Add Conv Transpose BF16 #30877
Add Conv Transpose BF16 #30877
Conversation
Thanks for your contribution! |
: platform::MKLDNNHandlerT<T, mkldnn::deconvolution_forward>( | ||
dev_ctx, mkldnn_engine, cpu_place, | ||
platform::CreateKey(dev_ctx, framework::vectorize(input->dims()), | ||
unique_name)) { | ||
const bool is_test = ctx.Attr<bool>("is_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.
In general I like very much this PR . The only thing that is missing is that inside a ConvTransposeMKLDNNHandler you should call isCached() method not to create MD again. Please look to other ops implemented with MKLDNNHandlerT like pool, softmax etc.
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.
In general there is huge overlap with oneDNN conv kernel (not surprisingly) so it would be good to have this common part in one place. But such refactoring is rather better for another PR.
paddle/fluid/platform/mkldnn_reuse.h
Outdated
@@ -253,6 +255,11 @@ class MKLDNNHandlerT { | |||
std::static_pointer_cast<dnnl::memory>(dev_ctx_.GetBlob(target_key)); | |||
|
|||
if (target_memory_p == nullptr) { | |||
if (custom_func) { |
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.
If I understand still after this custom reorder the condition user_md != target_md
may be true and this would result in second reorder. Is it intentionally?
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.
Yes, it is intentionally. Custom reorder function is used to set an appropriate reorder for data_format
. However, user_md! = target_md
may differ in data type. In the case of bf16, the original weights (user_md) are float, while for calculations (target_md) we need them in bf16 and it is converted in this reorder.
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, then if the additional thing you want to do is data type conversion I'd suggest to create a helper function for this task explicitly named anything close to ConvertMemDataType
. With it there would be clear intention of control-flow logic: 1st reorder data, 2nd convert memory data type. This AcquireMemoryWithReorder
function is already very complicated, very hard to understand it's control-flow and I suppose hard to debug. Not mentioning it's maintenance and testing. IMHO this function is doing to much things.
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 custom function was introduced because there was no NCWH format enum in oneDNN so we needed to do reorder ourselves. This is outdated as after we impleented custom reorder relevant enum was added. So actual task is to remove custom reorder and there is a issue for that in our tracker.
auto fwd_prop_kind = is_test ? mkldnn::prop_kind::forward_inference | ||
: mkldnn::prop_kind::forward_training; |
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 is already check forcing is_test
attribute to be true at the beginning . So is this ternary operator needed?
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.
We will be changing operators anyway to support training, so I think it's worth leaving it.
weights_tz, platform::MKLDNNGetDataType<K>(), | ||
(g == 1) ? filter->format() : MKLDNNMemoryFormat::goihw); | ||
|
||
// Custom Reorder from IOHW to OIHW |
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.
Doesn't oneDNN support such reorder?
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.
This is also related to group convolution, so we have to specify that format explicitly.
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 This code is reflecting the diffrence among oneDNN and PaddlePaddle in implementing groups. in oneDNN groups are another dimension e.g. shape without groups OIWH (weights) when there are more than one groups then It becomes GOIHW (5 dimensional). In PaddlePaddle OIHW and GOIHW are expressed in 4D data. It just weights of second group are glued (concatenated) to the end of weights of first group. That is why when groups are present we cannot rely on format inside tensor and we need to change from OIHW to GOIHW
python/paddle/fluid/tests/unittests/mkldnn/test_conv2d_transpose_bf16_mkldnn_op.py
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
Looks good. Just a general note on |
PR types
Others
PR changes
OPs
Describe
This PR: