Ok, i hope i understand what you try to do (sounds like RL btw)
if not, ill try again 
Doing the following will work, does this make sense to your scenario?
loss = torch.log(out1[0][0])*-10
optimizer.zero_grad()
loss.backward(retain_graph=True)
optimizer.step()
out2 = mymodel(inp2)    #<--- move to here, after weights were updated from inp1
loss = torch.log(out2[0][0])*-10
optimizer.zero_grad()
loss.backward()         #<--- do you need retain_graph here ?
optimizer.step()

Roy.