kshitij12345 commented on a change in pull request #14992: [MXNET-978] Support
higher order gradient for `log`.
URL: https://github.com/apache/incubator-mxnet/pull/14992#discussion_r287109398
##########
File path: src/operator/tensor/elemwise_unary_op_basic.cc
##########
@@ -1069,13 +1069,72 @@ The storage type of ``log2`` output is always dense
.set_attr<nnvm::FGradient>("FGradient", ElemwiseGradUseIn{"_backward_log2"});
MXNET_OPERATOR_REGISTER_BINARY_WITH_SPARSE_CPU_DR(_backward_log,
-
unary_bwd<mshadow_op::log_grad>);
+
unary_bwd<mshadow_op::log_grad>)
+.set_attr<nnvm::FGradient>("FGradient",
+ [](const nnvm::NodePtr& n, const std::vector<nnvm::NodeEntry>& ograds) {
+ // For g(x) -> g = log
+ // g''(x) = -1 * (g'(x) * g'(x))
+ auto gx = nnvm::NodeEntry{n, 0, 0};
+ auto ggx_mid = MakeNode("elemwise_mul", n->attrs.name +
"_backward_mid_grad_grad",
+ {gx, gx}, nullptr, &n);
+ auto ggx = MakeNode("negative", n->attrs.name + "_backward_grad_grad",
+ {nnvm::NodeEntry{ggx_mid, 0, 0}}, nullptr, &n);
+
+ std::vector<nnvm::NodeEntry> ret;
+
+ ret.emplace_back(MakeNode("elemwise_mul", n->attrs.name +
"_backward_grad_grad",
+ {ograds[0], gx}, nullptr, &n));
+ ret.emplace_back(MakeNode("elemwise_mul", n->attrs.name +
"_backward_grad_grad_inp",
Review comment:
`log` is unary, but the `_backward_log` isn't.
https://github.com/apache/incubator-mxnet/blob/016556553ced0c9c9400efec2f08a3c39cbb00ba/src/operator/tensor/elemwise_unary_op_basic.cc#L1071
It takes as input the output gradient and input to log.
https://github.com/apache/incubator-mxnet/blob/016556553ced0c9c9400efec2f08a3c39cbb00ba/src/operator/tensor/elemwise_unary_op_basic.cc#L1045
----------------------------------------------------------------
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