Solved by albanD in post #2 
              
              
                Hi, 
when you run in torch.no_grad, then nothing will traverse that block of code. 
In this case, if you just don’t want to compute gradient for that net, you remove the torch.no_grad and set its parameters not to require gradients with something like: 
for p in gen.parameters():
  p.requires_grad_(…