Hi,
The gradient argument here is not the gradient of the op you just did. But the gradient flowing back from the later functions.
If you want to see it differently, it computes gradient^T J where J is the jacobian of your function that contains the derivatives.