Hello, I have one multi-task multi-loss problem when I implement one multi-task classification problem.

self.optimizer_task1 = torch.optim.Adam([{'params':self.modules['shared_model'].parameters()},{'params': self.modules['net1'].parameters()}])
self.optimizer_task2 = torch.optim.Adam([{'params':self.modules['shared_model'].parameters()},{'params': self.modules['net2'].parameters()}])
......
self.module.train()
loss1.backward()
self.optimizer_task1.step()
self.optimizer_task1.zero_grad()

loss2.backward()
self.optimizer_task2.step()
self.optimizer_task2.zero_grad()


When the codes run to the line <loss2.backward()>, there will be an error “RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [128]] is at version 2; expected version 1 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).”. I wonder if the two optimizer could have the same part ‘shared_net’