The reference for the first way: https://github.com/pytorch/examples/blob/master/dcgan/main.py#L217
The reference for the second way: https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix/blob/master/models/pix2pix_model.py#L79 1
Thanks