larroy commented on a change in pull request #14613: [MXNET-978] Higher order
gradient support for some unary operators
URL: https://github.com/apache/incubator-mxnet/pull/14613#discussion_r288353926
##########
File path: src/operator/tensor/elemwise_unary_op_basic.cc
##########
@@ -83,7 +83,18 @@ The storage type of ``relu`` output depends upon the input
storage type:
- relu(csr) = csr
)code" ADD_FILELINE)
-.set_attr<nnvm::FGradient>("FGradient", ElemwiseGradUseOut{"_backward_relu"});
+.set_attr<nnvm::FGradient>("FGradient",
+ [](const nnvm::NodePtr& n, const std::vector<nnvm::NodeEntry>& ograds) {
+ auto zero_node = MakeNode("zeros_like", n->attrs.name + "_backward",
+ {n->inputs[0]}, nullptr, &n);
+ auto x_grad = MakeNode("_greater", n->attrs.name + "_mid_x_grad",
+ {n->inputs[0], nnvm::NodeEntry{zero_node, 0, 0}}, nullptr, &n);
+ auto in_grad = MakeNode("elemwise_mul", n->attrs.name + "_backward",
+ {ograds[0], nnvm::NodeEntry{x_grad, 0 , 0}}, nullptr, &n);
+ std::vector<nnvm::NodeEntry> ret;
+ ret.emplace_back(nnvm::NodeEntry{in_grad, 0, 0});
+ return ret;
+ });
Review comment:
We should measure if this causes regressions as we discussed, otherwise we
should add FGradient to _backward_relu.
I think same applies for other functions.
----------------------------------------------------------------
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