You could use use register_full_backward_hook and return the grad_ouput:
def hook(module, grad_input, grad_output):
    return grad_output

x = torch.randn(1, 3, requires_grad=True)
lin = nn.Linear(3, 3, bias=False)
lin.register_full_backward_hook(hook)

out = lin(x)
out.mean().backward()
print(x.grad)