Hi,
Calling .backward() will free the computational graph for saving memory.
fake is used to compute the loss of netD and also used in updating netG, after performing .backward() on loss of netD, fake will be freed without .detach() (here detach is used to exclude fake from the computational graph so that calling .backward() on loss of netD will not free fake).
Thus, if you remove .detach() (it will free fake) and call .backward() on loss of netG, it will raise the error that needs retain_graph=True.