Hi,
This hook just gives you the gradient that was computed for W. And this gradient has the same size as W.
Note that the hook is not doing any computation, it just shows you something that was computed before.
I am not sure to understand why you expect to see a Batch dimension on the gradient of W here. the torch.mm() operation takes two inputs and compute the gradient for each of them. In particular for W, it will be X.t() * grad_out. As you can see the Batch dimension “naturally” disappears when you compute the gradient.