No, sorry. I’m wrong and your code snippet should be the right way and also seems to work:
model = nn.Linear(1, 1)
model.weight.register_hook(lambda grad: torch.ones_like(grad) * 1000)
model(torch.randn(1, 1)).backward()
print(model.weight.grad)
> tensor([[1000.]])

I’ll edit my previous post.