Hi,
The gradient from the output of the module match the output size and so have a batch dimension. But the weight don’t have a batch dimension so you don’t have one for the gradients either.
You can do two things here:

Do as many backward as there are sample in the batch. Saving the gradient each time and stack them at the end to get your (batch, in, nhid) gradients.
Expand the weights to `(batch, in, nhid) to have as many weights as you have samples. And in the forward, make sure each element in the weight is used to compute the output for each sample in your batch. Now when you will backprop, you will again get a gradient of the size of the weights that contain all the values you want.