Both approaches should compute the same gradients.
In the second approach you would need to call lossGen.backward(retain_graph=True), otherwise the intermediate values will be cleared and you’ll get an error calling lossSeg.backward().
However, currently you are using lossSeg to calculate gradients in both models, GenA and SegA.
Is this what you would like to do?
If you would only want to calculate the gradients of lossSeg w.r.t. the parameters in SegA, you should .detach() the output of GenA before passing it so SegA.