This is a known issue: https://github.com/pytorch/pytorch/issues/12331 4
Try use  register_hook  on each input independently.
def hook(grad):
    print(grad)

test_model = nn.Linear(3,1)
test_inp = torch.randn(3, requires_grad=True)
test_inp.register_hook(hook)
out = test_model(test_inp)
out.sum().backward()