@albanD, Hi, I am doing the similar thing under DDP, but it threw errors like has_marked_unused_parameters_ ASSERT FAILED and setting find_unused_parameters=True won’t work as well.
My understanding is the DDP won’t allow the  loss1.backward() to have some loose module parts in the model that don’t participant in the computation of loss. (as loss1 and loss2 are corresponding to different branches, and when do loss1.backward()…) Please correct me if I am wrong about this.
Currently I get away with this problem by
loss = loss1 + 0 * loss2
loss.backward(retain_graph=True)
optimizer1.step()
loss = 0 * loss1 + loss2
optimizer2.step()

a quick explanation about why to do it this way, there are a backbone and then two branches, main branch and aux branch. And now backbone and main branch work as a whole to produce loss1.
the aux branch only takes the output of backbone, produces loss2, but don’t want loss2 to affect the backbone. BTW, the optimizers are set by different param_lists also.
The code can run normally for now, but it is ugly, and slow. Wonder if there is a better way to do this under DDP?