Thank you for the quick response, actually my example was simplifying my case too much. Let me provide a better example.
I’m not trying to compute the gradient of the loss w.r.t to my classifier parameters only.
x1, x2 = model(x)
out = heavy_module(x1, x2)
loss = Loss1(out)
loss.backward()

out_d = heavy_module(x1.detach(), x2)
loss_d = Loss2(out_d)
loss_d.backward()

Can we avoid the second heavy_module computation ? while having access to both out and out_d for different losses.
Thank you