What exactly would you like to show?
You can pass a gradient of the same shape as w, which would only set w.grad to this particular value:
w = torch.randn(2, 5, requires_grad=True)
w.backward(torch.ones_like(w))
print(w.grad)
> tensor([[1., 1., 1., 1., 1.],
          [1., 1., 1., 1., 1.]])