@albanD  Thanks for the reply. I’m a bit confused by the autograd process. The document says it computes the vector-Jacobian result, which usually returns a vector.
However, the tanh function is element-wise, that is, Y_{ij} = nn.tanh(X_{ij}), where X and Y are both matrices.
In this case, we have a matrix-valued function and the gradient of Y wrt X would be a 4-D Jacobian matrix.
The C-souce code is like this:
*gradInput_data = *gradOutput_data * (1. - z*z);
It seems so perform an elementwise multiplication: Y_ij * (1-X_ij^2)
Could you please explain how the auto-grad actually handle this?
P.S.: Sorry if it’s inappropriate to reply such an old post.