You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/07/11 04:50:54 UTC
[GitHub] [incubator-mxnet] kshitij12345 commented on a change in pull
request #15253: [MXNET-978] Add higher order gradient support `tan`, `tanh`
kshitij12345 commented on a change in pull request #15253: [MXNET-978] Add higher order gradient support `tan`, `tanh`
URL: https://github.com/apache/incubator-mxnet/pull/15253#discussion_r302362521
##########
File path: src/operator/tensor/elemwise_unary_op_trig.cc
##########
@@ -139,7 +139,31 @@ The storage type of ``tan`` output depends upon the input storage type:
)code" ADD_FILELINE)
.set_attr<nnvm::FGradient>("FGradient", ElemwiseGradUseOut{ "_backward_tan" });
-MXNET_OPERATOR_REGISTER_BINARY_WITH_SPARSE_CPU_DR(_backward_tan, unary_bwd<mshadow_op::tan_grad>);
+MXNET_OPERATOR_REGISTER_BINARY_WITH_SPARSE_CPU_DR(_backward_tan, unary_bwd<mshadow_op::tan_grad>)
+.set_attr<nnvm::FGradient>("FGradient",
+ [](const nnvm::NodePtr& n, const std::vector<nnvm::NodeEntry>& ograds) {
+ // NodeEntry{n} : y_grad * f'(x)
+ // n->inputs[0] : y_grad
+ // n->inputs[1] : f(x) = tan(x)
+ // ograds[0] : head_grads
+ // f'(x) = sec^2(x)
+ // f''(x) = 2 * f'(x) * f(x)
+ const std::unordered_map<std::string, std::string> args = {{"scalar", "2.0"}};
+ auto two_y = MakeNode("_mul_scalar", n->attrs.name + "_mul_two", {n->inputs[1]}, &args, &n);
+ auto grad_grad_mid = MakeNode("elemwise_mul", n->attrs.name + "_grad_mul",
Review comment:
Makes sense. Thanks. Will get to it.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services