tensor.register_hook() would have worked, but I would have to refactor everything. It would take days, and I might lose some functionality, because the system I already built is more flexible for my purposes. (Hooks get executed immediately, but I build a prioritized queue of calculations that still need to be performed)
I’m not sure I understand how torch.no_grad() would help. I am performing normal gradient calculations through backpropagation. Then I apply modifications to the generated gradients.