I imagine the error that is thrown is from trying to backprop Variables that belong to different graph structures. errD_real belongs to the graph of netD(input) where errD_fake belongs to netD(netG(noise)) (though it has been detached to only affect netD) so you’re trying to get the derivative wrt different inputs into different functions.