Hi all,
I’m working on a project where I need to manipulate gradients as they flow backward through each computational path in a model’s computation graph. Currently, I know that PyTorch’s .register_hook
method allows you to manipulate gradients for a tensor during backpropagation, but this hook is only called after gradients from all incoming paths have been summed together.
I’d like to “hook in” before this summation step, so that I can observe or modify gradient contributions coming from each computational path (branch) individually, before they are combined at a given node in the graph.
I don’t think it’s possible to do this with PyTorch’s API, if anyone has suggestions that don’t involve modifying the C++ internals please let me know. I’m also wondering if anyone has any thoughts on if there would be demand for this kind of feature as an addition to the hook system - would it make sense as a feature request?