I am using 0.4.0 version of pytorch.
To get the output gradient w.r.t the input, I used the following code.
m = nn.Linear(20, 30)
input = torch.randn(128, 20)
input.requires_grad = True
output = m(input).sum()
output.backward()
print(input.grad.data)

Am I correct ?
Thanks!