I have 2 classification being trained back to back. when I do loss back in the second model, I get a error asking me to put retain_graph=True on the previous call. Which does not make sense to me.
the training schematics is below
model1.train()
model2.train()
for i, data in enumerate(dataset):
     for _ in range(100):    
            x=model1(data[0])
            loss1=loss_fn1(x,data[1])
            loss1.backward()
            opt1.step()
            opt1.zero_gradient()

    y=model2(data[2],x)
    loss2=loss_fn2(y,data[3])
    loss2.backward()
    opt2.step()
    opt2.zero_gradient()

The loss2 backward is the problem. How can I overcome the problem?