If you just want to modify the gradients, you can either add a hook to the Tensor with register_hook() and whatever is returned by that hook will be used as gradient.
Or if it is more involved, you can do that with a custom Function as well.
But modifying the weights data directly is dangerous and might break for no reason in the future.