It won’t work too. Actually, the code works well until meeting the loss.backward(). And the gradient can go through the loss function but not the network.
Additionally, https://pytorch.org/tutorials/beginner/dcgan_faces_tutorial.html 11 this tutorial also raise the same error.