Question about hook

Hi

I just finished reading the docs for how to register a hook. I know it can return gradients, but I still don’t know how to use it to modify gradients. For example, I have a 10-dimensional vector. how can I keep the first 5 values unchanged by using the hook, i.e. set the gradient to the first value to 0.

Many Thanks

Copy the gradient tensor, set the last five entries to zeros, return it.