rongzha1 commented on a change in pull request #17170: add mkldnn softmax
backward
URL: https://github.com/apache/incubator-mxnet/pull/17170#discussion_r361566556
##########
File path: src/operator/nn/softmax.cc
##########
@@ -54,13 +54,30 @@ static void SoftmaxComputeExCPU(const nnvm::NodeAttrs&
attrs,
inputs, req, outputs);
}
+static void SoftmaxGradComputeExCPU(const nnvm::NodeAttrs& attrs,
+ const OpContext& ctx,
+ const std::vector<NDArray>& inputs,
+ const std::vector<OpReqType>& req,
+ const std::vector<NDArray>& outputs) {
+ // It seems MKLDNN softmax doesn't support training.
+ const SoftmaxParam& param = nnvm::get<SoftmaxParam>(attrs.parsed);
+ if (SupportMKLDNNSoftmax(param, inputs[1], outputs[0])) {
+ MKLDNN_OPCHECK_INIT(false, outputs.size(), inputs, outputs);
+ MKLDNNRun(MKLDNNSoftmaxBackward, attrs, ctx, inputs, req, outputs);
+ auto fn = SoftmaxGradCompute<cpu, op::mshadow_op::mul,
mxnet_op::softmax_bwd>;
+ MKLDNN_OPCHECK_RUN(fn, attrs, ctx, inputs, req, outputs);
+ return;
+ }
+ FallBackCompute(SoftmaxGradCompute<cpu, op::mshadow_op::mul,
mxnet_op::softmax_bwd>, attrs, ctx,
+ inputs, req, outputs);
+}
+
inline static bool SoftmaxStorageType(const nnvm::NodeAttrs& attrs,
const int dev_mask,
DispatchMode* dispatch_mode,
std::vector<int> *in_attrs,
std::vector<int> *out_attrs) {
const SoftmaxParam& param = nnvm::get<SoftmaxParam>(attrs.parsed);
- CHECK_EQ(in_attrs->size(), (param.use_length.value()) ? 2U : 1U);
Review comment:
this check will result in backward check fail.
Will recover this check and add another function for backward.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services