For example, I have models net0 and net1 working like this
out0 = net0(inp0)
out1 = net0(net1(net0(inp1)))
loss = criterion(out0, out1, target)

I want to reverse the gradient sign from the output of model net1 but calculate net0(inp0) as usual.
In simple case, I would do
out0 = net0(inp0)
out1 = net0(net1(inp1))
loss = criterion(out0, out1, target)
loss.backward()
[p.grad.data.neg_() for p in net1.parameters()]
opt.step()

Can I do some hook to reverse gradients from output of net1?