I try to calculate gradient penalty. But It seems that the gradients cannot back propagate to the parameters of netD.
        output = netD(fuse)
        gradients = grad(output, fuse, only_inputs=True, create_graph=False, retain_graph=False, grad_outputs=torch.ones(output.size(), device=device))[0]
        gradients.requires_grad = True
        D_penalty = penalty_scale * (gradients.view(batch_size, -1).norm(2, dim=-1) - 1).pow(2).mean()
        D_penalty.backward()