-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function will create memory with default layout.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
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.
WIP to review :)
#include "./mkldnn_ops-inl.h" | ||
#include "./mkldnn_base-inl.h" | ||
|
||
#if MXNET_USE_MKLDNN == 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.
Move to the before of include
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.
Done
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does the training mode support now?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto prop = is_train ? mkldnn::prop_kind::forward_training : mkldnn::prop_kind::forward_scoring;
auto desc = mkldnn::softmax_forward::desc(prop, data_md, axis);
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
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why we need have data
and input_mem
at the same time?
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, remove data
} | ||
|
||
auto input_mem = idata.GetMKLDNNData(); | ||
auto output_mem = odata.GetMKLDNNData(); |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
label is not 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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there are only two elements, no need to have for-loop.
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "special MKLDNN layout" mean here?
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.
means support ndim 1,2,4; remove this ambiguous comments,
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.
Thanks for the contribution.
LGTM
|
||
MXNET_REGISTER_OP_PROPERTY(Softmax, DeprecatedSoftmaxProp) |
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.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
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.
Nit comments.
|
||
auto input_mem = idata.GetMKLDNNData(); | ||
auto out_mem = CreateMKLDNNMem(out_data[softmaxout_enum::kOut], | ||
input_mem->get_primitive_desc(), req[softmaxout_enum::kOut]); |
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.
Indent.
src/operator/softmax_output.cc
Outdated
} | ||
FallBackCompute(SoftmaxOutputCompute<cpu>, attrs, ctx, inputs, req, outputs); | ||
} | ||
|
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.
remove blank line.
src/operator/softmax_output.cc
Outdated
return {"data", "label"}; | ||
} | ||
|
||
|
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.
reduce to 1 blank line.
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
* 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