code: def forward(
      self, output: DiscriminatorOutput, target: GANTarget
  ) -> Tensor:
      predictions, target_is_real = output.output, target.target_is_real
      if self.gan_mode in ["lsgan", "vanilla"]:
          target_tensor = self.expand_target(
              predictions, target_is_real
          )
          loss = self.loss(predictions, target_tensor)
      elif self.gan_mode == "wgangp":
          loss = (
              -predictions.mean()
              if target_is_real
              else predictions.mean()
          )
      else:
          raise NotImplementedError(
              f"gan_mode '{self.gan_mode}' is not implemented"
          )
      if output.cond_logits is not None and target.target_is_real:
          cond_loss = self.ce(output.cond_logits, target.labels)
          loss = loss + cond_loss
      return loss
  
file_path: carefree-learn/cflearn/losses/gan.py
imports: import torch
  from torch import nn
  from torch import Tensor
  from typing import Optional
  from typing import NamedTuple
  from ..misc.toolkit import get_gradient
label_desc: Use image node_id 3 for calling the GANLoss obj's underlying member method code with example usage: obj.forward(output, target) and returns: loss