kshitij12345 commented on a change in pull request #15413: [MXNET-978] Higher
Order Gradient Support `reciprocal`, `abs`.
URL: https://github.com/apache/incubator-mxnet/pull/15413#discussion_r300451696
##########
File path: src/operator/tensor/elemwise_unary_op_basic.cc
##########
@@ -717,7 +717,38 @@ Example::
MXNET_OPERATOR_REGISTER_BINARY(_backward_reciprocal)
.set_attr<FCompute>("FCompute<cpu>",
- ElemwiseBinaryOp::Compute<cpu, unary_bwd<mshadow_op::reciprocal_grad> >);
+ ElemwiseBinaryOp::Compute<cpu, unary_bwd<mshadow_op::reciprocal_grad> >)
+.set_attr<nnvm::FGradient>("FGradient",
+ [](const nnvm::NodePtr& n, const std::vector<nnvm::NodeEntry>& ograds) {
+ // ograds[0]: dL/dxgrad
+ // inputs[0]: dL/dy
+ // inputs[1]: x
+ // f(x) = y = 1/x
+ // f'(x) = -1/x^2
+ // f''(x) = 2/x^3 = -2 * (f'(x) * f(x))
+
+ const std::unordered_map<std::string, std::string> args = {{"scalar",
"-2.0"}};
+
+ auto dydx_mul_dldy = nnvm::NodeEntry{n}; // f'(x) * head_grads
+ auto dydx = MakeNode("elemwise_div", n->attrs.name + "_dydx",
+ {dydx_mul_dldy, n->inputs[0]}, nullptr, &n);
+ auto fx = MakeNode("reciprocal", n->attrs.name + "_fx",
Review comment:
I don't think we can use it as that would work as our `_backward_reciprocal`
which is binary will have to support 3 inputs.
https://github.com/apache/incubator-mxnet/blob/8ebaa5c0384ecbef244150859b3e24ea2f02095d/src/operator/elemwise_op_common.h#L213-L227
----------------------------------------------------------------
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