code: def get_generator_loss(
      self,
      batch: tensor_dict_type,
      forward_results: tensor_dict_type,
      *,
      step: Optional[int],
      last_layer: nn.Parameter,
      cond: Optional[Tensor] = None,
  ) -> CustomTrainStepLoss:
      inputs = batch[INPUT_KEY].contiguous()
      reconstructions = forward_results[PREDICTIONS_KEY].contiguous()
      # vq & nll loss
      vq_losses = self.vq_loss(
          forward_results, batch, reduction="none", gather=False
      )
      """{"mse": mse, "commit": commit_loss, LOSS_KEY: loss}"""
      recon_loss = vq_losses[self.vq_loss.loss_type]
      codebook_loss = vq_losses["codebook"].mean()
      with torch.no_grad():
          loss_items = {
              "recon": recon_loss.mean().item(),
              "codebook": codebook_loss.item(),
          }
      if self.perceptual_weight > 0:
          p_loss = self.perceptual_loss(inputs, reconstructions)
          p_loss = self.perceptual_weight * p_loss
          recon_loss = recon_loss + p_loss
          with torch.no_grad():
              loss_items["perceptual"] = p_loss.mean().item()
      nll_loss = torch.mean(recon_loss)
      loss = nll_loss + codebook_loss
      # check discriminator start
      if step is not None and step < self.d_loss_start_step:
          return CustomTrainStepLoss(loss, loss_items)
      g_loss = self.g_loss(
          nll_loss, last_layer, loss_items, reconstructions, cond
      )
      loss = loss + g_loss
      return CustomTrainStepLoss(loss, loss_items)
  
imports: import torch
  import torch.nn
  from torch import Tensor
  from typing import Tuple
  from typing import Optional
  from cftool.types import tensor_dict_type
  from .common import IAutoEncoder
  from .common import AutoEncoderInit
  from .common import AutoEncoderLPIPSWithDiscriminator
  from ..general import VQCodebook
  from ...schemas import CustomTrainStepLoss
  from ....schema import IDLModel
  from ....constants import INPUT_KEY
  from ....constants import PREDICTIONS_KEY
  from ....losses.vae import VQVAELoss
label_desc: Use image node_id 2 for calling the AutoEncoderVQLoss obj's underlying member method code with example usage: obj.get_generator_loss(batch, forward_results) and returns: CustomTrainStepLoss, CustomTrainStepLoss