Hi, I am new to pytorch and this is what I want to do:
I have two models that are related to one another: modelA and modelB. I want to get three separate gradients. I am able to get the first two without any issues, but I am not sure how I can get the third one.
-
differentiating the loss of modelA wrt modelA.parameters
[v.grad.data for v in modelA.parameters()] -
differentiating the loss of modelB wrt modelB.parameters
[v.grad.data for v in modelB.parameters()] -
differentiating the loss of modelB wrt modelA.parameters
This is what I tried: torch.autograd.grad(lossB, modelA.parameters())
However, I get the following error: grad can be implicitly created only for scalar outputs
Any help would be great!