add mkldnn softmax_output#13699
add mkldnn softmax_output#13699TaoLv merged 17 commits intoapache:masterfrom rongzha1:mkldnn_softmax_output
Conversation
|
@rongzha1 please help fix the lint issue
|
| } | ||
|
|
||
| auto input_mem = idata.GetMKLDNNData(); | ||
| auto output_mem = odata.GetMKLDNNData(); |
There was a problem hiding this comment.
This function will create memory with default layout.
There was a problem hiding this comment.
Is it possible for softmax_output to have input with internal layout? Then how does the output look like?
|
@rongzha1 could you post some performance changes by this PR? |
for 1024*256 input, performance speedup 2.75 env: skx-8180, 1socket 28 core,
|
There was a problem hiding this comment.
Thank you for your contributions.
@azai91 - You may be interested in this PR.
|
@rongzha1 please rebase the code and make the CI pass :) |
|
please help to review and merge to the master branch. @eric-haibin-lin @zheng-da @azai91 |
| #include "./mkldnn_ops-inl.h" | ||
| #include "./mkldnn_base-inl.h" | ||
|
|
||
| #if MXNET_USE_MKLDNN == 1 |
There was a problem hiding this comment.
Move to the before of include
| // softmax_output has no axis parameter, so use it as it original implement. | ||
| int axis = data.shape().ndim() - 1; | ||
| mkldnn::softmax_forward::desc desc = is_train | ||
| ? mkldnn::softmax_forward::desc(mkldnn::prop_kind::forward_training, |
There was a problem hiding this comment.
does the training mode support now?
There was a problem hiding this comment.
following mkldnn_softmax did
| ? mkldnn::softmax_forward::desc(mkldnn::prop_kind::forward_training, | ||
| data_md, axis) | ||
| : mkldnn::softmax_forward::desc(mkldnn::prop_kind::forward_scoring, | ||
| data_md, axis); |
There was a problem hiding this comment.
auto prop = is_train ? mkldnn::prop_kind::forward_training : mkldnn::prop_kind::forward_scoring;
auto desc = mkldnn::softmax_forward::desc(prop, data_md, axis);
|
|
||
| static mkldnn::softmax_forward::primitive_desc GetSoftmaxOutputFwdDescImpl( | ||
| const SoftmaxOutputParam& param, bool is_train, | ||
| const NDArray &data, const mkldnn::memory &input_mem) { |
There was a problem hiding this comment.
why we need have data and input_mem at the same time?
| } | ||
|
|
||
| auto input_mem = idata.GetMKLDNNData(); | ||
| auto output_mem = odata.GetMKLDNNData(); |
There was a problem hiding this comment.
Is it possible for softmax_output to have input with internal layout? Then how does the output look like?
| return op; | ||
|
|
||
| DMLC_REGISTER_PARAMETER(SoftmaxOutputParam); | ||
| struct SoftmaxOutputGrad { |
There was a problem hiding this comment.
@eric-haibin-lin Please help to review this. Do we have any existing gradient structure to do this?
| auto input_mem = idata.GetMKLDNNData(); | ||
| auto output_mem = odata.GetMKLDNNData(); | ||
|
|
||
| MKLDNNSoftmaxOutputFwd &fwd = GetSoftmaxOutputForward(param, ctx, idata, *input_mem); |
There was a problem hiding this comment.
label is used for backward
src/operator/softmax_output.cc
Outdated
| gnode->attrs.op = nnvm::Op::Get("_backward_SoftmaxOutput"); | ||
| gnode->attrs.name = n->attrs.name + "_backward"; | ||
| std::vector<nnvm::NodeEntry> in_grad(2); | ||
| for (uint32_t i = 0; i < 2; ++i) { |
There was a problem hiding this comment.
if there are only two elements, no need to have for-loop.
src/operator/softmax_output.cc
Outdated
| const std::vector<NDArray> &outputs) { | ||
| CHECK_EQ(inputs.size(), 2U); | ||
| const SoftmaxOutputParam ¶m = nnvm::get<SoftmaxOutputParam>(attrs.parsed); | ||
| // MKLDNN softmaxOutput only works well on the special MKLDNN layout. |
There was a problem hiding this comment.
What does "special MKLDNN layout" mean here?
There was a problem hiding this comment.
means support ndim 1,2,4; remove this ambiguous comments,
pengzhao-intel
left a comment
There was a problem hiding this comment.
Thanks for the contribution.
LGTM
| // Softmax symbol is renamed to SoftmaxOutput and deprecated since Dec, 2015 | ||
| NNVM_REGISTER_OP(SoftmaxOutput).add_alias("Softmax"); | ||
|
|
||
| MXNET_REGISTER_OP_PROPERTY(Softmax, DeprecatedSoftmaxProp) |
There was a problem hiding this comment.
@szha could you help to take a look at this change? SoftmaxOutput is re-writed with NNVM flavor in this PR and the deprecated Softmax is moved to be an alias of SoftmaxOutput. Need your confirm that it doesn't break any API.
There was a problem hiding this comment.
Seems that they differ by only the label field, which means the note isn't accurate and if it should be considered breakage then it already happened in the past. Looks like the Softmax op as it stands isn't really usable so I think making it an alias of SoftmaxOutput is actually improvement.
|
Ping @szha @eric-haibin-lin for review. Thank you. |
|
@szha could you help take a look for the API change? |
|
Hi, @szha @eric-haibin-lin Can you help to review this PR and merge it to master branch? Thanks |
|
@rongzha1 Please re-base code and re-trigger CI. I will merge this PR tomorrow if there is no other comment. |
|
|
||
| auto input_mem = idata.GetMKLDNNData(); | ||
| auto out_mem = CreateMKLDNNMem(out_data[softmaxout_enum::kOut], | ||
| input_mem->get_primitive_desc(), req[softmaxout_enum::kOut]); |
src/operator/softmax_output.cc
Outdated
| } | ||
| FallBackCompute(SoftmaxOutputCompute<cpu>, attrs, ctx, inputs, req, outputs); | ||
| } | ||
|
|
src/operator/softmax_output.cc
Outdated
| return {"data", "label"}; | ||
| } | ||
|
|
||
|
|
|
Merging now. |
* add mkldnn softmax_output * fix gpu OP unittest error * fix ci/jenkins/mxnet-validation/unix-gpu compiler error * fix coding style * fix Tao comments * remove blank line, fix indentx * modify according to sandeep's comments * change get CPU engine method, and pravate variable * move macro MXNET_USE_MKLDNN to the head * modify according to Tao's comments * make output layout as input * change API of GetSoftmaxOutputForward * add CommitOutput for mkldnn_softmax_output * trigger Jenkins re-test * add alias Softmax symbol for SoftmaxOutput OP * indent and remove blank line
* add mkldnn softmax_output * fix gpu OP unittest error * fix ci/jenkins/mxnet-validation/unix-gpu compiler error * fix coding style * fix Tao comments * remove blank line, fix indentx * modify according to sandeep's comments * change get CPU engine method, and pravate variable * move macro MXNET_USE_MKLDNN to the head * modify according to Tao's comments * make output layout as input * change API of GetSoftmaxOutputForward * add CommitOutput for mkldnn_softmax_output * trigger Jenkins re-test * add alias Softmax symbol for SoftmaxOutput OP * indent and remove blank line
* add mkldnn softmax_output * fix gpu OP unittest error * fix ci/jenkins/mxnet-validation/unix-gpu compiler error * fix coding style * fix Tao comments * remove blank line, fix indentx * modify according to sandeep's comments * change get CPU engine method, and pravate variable * move macro MXNET_USE_MKLDNN to the head * modify according to Tao's comments * make output layout as input * change API of GetSoftmaxOutputForward * add CommitOutput for mkldnn_softmax_output * trigger Jenkins re-test * add alias Softmax symbol for SoftmaxOutput OP * indent and remove blank line
* add mkldnn softmax_output * fix gpu OP unittest error * fix ci/jenkins/mxnet-validation/unix-gpu compiler error * fix coding style * fix Tao comments * remove blank line, fix indentx * modify according to sandeep's comments * change get CPU engine method, and pravate variable * move macro MXNET_USE_MKLDNN to the head * modify according to Tao's comments * make output layout as input * change API of GetSoftmaxOutputForward * add CommitOutput for mkldnn_softmax_output * trigger Jenkins re-test * add alias Softmax symbol for SoftmaxOutput OP * indent and remove blank line
Description
Add mkldnn implement for softmax_output OP
Checklist
Essentials
Please feel free to remove inapplicable items for your PR.
Changes
test_softmax has passed
@pengzhao-intel