class_docstr: Control the loops for training, evaluation, and prediction. This module is independent of
  the model definition. This class inherits from the Pytorch Lightning's LightningModule:
  https://lightning.ai/docs/pytorch/stable/common/lightning_module.html
code: def _compute_template_loss(
      self,
      per_output: Dict,
      label: torch.Tensor,
  ):
      logits = per_output[TEMPLATE_LOGITS]
      choices_scores = per_output[LOGITS]
      lm_target = per_output[LM_TARGET]
  
      bs = lm_target.size(0)
      num_choices = lm_target.size(1)
  
      lm_loss = F.cross_entropy(
          logits[range(bs), label].flatten(0, 1),
          lm_target[range(bs), label].flatten(0, 1),
      )
      if self.model.mc_loss > 0:
          mc_loss = F.cross_entropy(choices_scores, label)
      else:
          mc_loss = 0.0
  
      if self.model.unlikely_loss > 0:
          cand_loglikely = -F.cross_entropy(
              logits.flatten(0, 2),
              lm_target.flatten(0, 2),
              reduction="none",
          ).view(bs, num_choices, -1)
          cand_loglikely += (lm_target < 0) * -100
          cand_loglikely[range(bs), label] = -100
          unlikely_loss = (
              -torch.log(1 - torch.exp(cand_loglikely) + 1e-2).sum()
              / (cand_loglikely != -100).sum()
          )
      else:
          unlikely_loss = 0.0
  
      return (
          lm_loss
          + mc_loss * self.model.mc_loss
          + unlikely_loss * self.model.unlikely_loss
      )
  
imports: import logging
  from typing import Callable, Dict, List, Optional, Union
  import lightning.pytorch
  import torch
  import torch.nn.functional
  import torchmetrics
  from lightning.pytorch.strategies import DeepSpeedStrategy
  from lightning.pytorch.utilities import grad_norm
  from torch import nn
  from torch.nn.modules.loss import _Loss
  from torchmetrics.aggregation import BaseAggregator
  from ..constants import LM_TARGET, LOGITS, T_FEW, TEMPLATE_LOGITS, WEIGHT
  from ..data.mixup import MixupModule, multimodel_mixup
  from ..models.utils import run_model
  from .semantic_seg_metrics import COD, Balanced_Error_Rate
  from .utils import apply_layerwise_lr_decay, apply_single_lr, apply_two_stages_lr, get_lr_scheduler, get_optimizer
label_desc: Use image node_id 2 for calling the LitModule obj's underlying member method code with example usage: obj._compute_template_loss(per_output, label) and returns: unknown