Hi!
I want to ask a maybe trivial question regarding the issue with two forward passes and one backward pass. Is doing:
loss1 = loss_fun1(model(x))
loss2 = loss_fun2(model(y))
(loss1+loss2).backward()
optimizer.step()

the same as doing:
loss1 = loss_fun1(model(x))
loss1.backward()
loss2 = loss_fun2(model(y))
loss2.backward()
optimizer.step()

?
I’ve tried both cases but neither seems to work and throws the popular error:  Trying to backward through the graph a second time etc.
Also, trying retain_graph=True doesn’t make it work either.
In my understanding shouldn’t the gradient of both the computational graphs created from loss1 and loss2 be accumulated? What is it that I’m missing?