Solved by albanD in post #4 
              
              
                Because you want the discriminator loss to only compute gradients for the discriminator and not the generator. 
The .detach() here allows you to make sure this happens. 
If you do it for the generator loss, then the generator loss won’t contribute to the generator gradient which is not what you want…