class_docstr: This class jointly handles the hidden transforms and hidden loss transforms.
  It helps in validating, and applying the transforms.
class_docstr_tok: ["This","class","jointly","handles","the","hidden","transforms","and","hidden","loss","transforms",".","It","helps","in","validating",",","and","applying","the","transforms","."]
docstr: Apply loss transforms
  Args:
      outputs: a dictionary of outputs (after hidden transforms)
      batch_data: a dictionary of batch data (e.g. "target_ids"), optional
  
  Returns:
      loss_dict: a dictionary of all losses, 
          {
              loss: joint loss (float),
              <name>_*: loss values from loss transforms, could be loss, or loss elements
          }
docstr_tok: ["Apply","loss","transforms","Args",":","outputs",":","a","dictionary","of","outputs","(","after","hidden","transforms",")","batch_data",":","a","dictionary","of","batch","data","(","e.g",".","``","target_ids","''",")",",","optional","Returns",":","loss_dict",":","a","dictionary","of","all","losses",",","{","loss",":","joint","loss","(","float",")",",","<","name",">","_","*",":","loss","values","from","loss","transforms",",","could","be","loss",",","or","loss","elements","}"]
code: def apply_loss_transforms(self, outputs, batch_data=None):
      """
      Apply loss transforms
      Args:
          outputs: a dictionary of outputs (after hidden transforms)
          batch_data: a dictionary of batch data (e.g. "target_ids"), optional
  
      Returns:
          loss_dict: a dictionary of all losses,
              {
                  loss: joint loss (float),
                  <name>_*: loss values from loss transforms, could be loss, or loss elements
              }
      """
      loss_dict = {}
      joint_loss = 0.0
      for i, loss_transform in enumerate(self.hidden_loss_transforms):
          cur_loss_dict = loss_transform.loss(
              outputs, batch_data=batch_data
          )
          joint_loss = joint_loss + cur_loss_dict["weighted_loss"]
          cur_loss_dict.pop("weighted_loss")
          # add name to loss values
          if loss_transform.name:
              cur_loss_dict = {
                  f"{loss_transform.name}_{k}": v
                  for k, v in cur_loss_dict.items()
              }
  
          # check if cur_loss keys are unique - we do not allow to override keys
          dup_keys = set(cur_loss_dict.keys()).intersection(
              set(loss_dict.keys())
          )
          if len(dup_keys):
              raise ValueError(
                  f"Loss transform ({i}) {loss_transform} is trying to override the following loss keys {list(dup_keys)}"
              )
          # update loss dict
          loss_dict.update(cur_loss_dict)
  
      # joint weighted loss (float)
      loss_dict["loss"] = joint_loss
  
      # add prefix to all loss keys (default to 'hiddens_')
      if self.loss_prefix:
          loss_dict = {
              f"{self.loss_prefix}{k}": v for k, v in loss_dict.items()
          }
  
      # add tokens loss weight (to be used by caller, or be ignored)
      loss_dict["tokens_loss_weight"] = torch.tensor(
          self.tokens_loss_weight
      ).to(joint_loss)
  
      return loss_dict
  
imports: import functools
  import itertools
  from typing import List
  import torch
  from omegaconf.dictconfig import DictConfig
  from omegaconf.omegaconf import OmegaConf
  from nemo.collections.nlp.modules.common.megatron.hiddens.megatron_hidden_loss import MegatronBaseHiddenLoss
  from nemo.collections.nlp.modules.common.megatron.hiddens.megatron_hidden_transform import MegatronBaseHiddenTransform
  from nemo.collections.nlp.modules.common.megatron.utils import ApexGuardDefaults
  from nemo.utils import logging
  from nemo.utils.model_utils import import_class_by_path
label_desc: Use image node_id 5 for calling the MegatronHiddensModule obj's underlying member method code with example usage: obj.apply_loss_transforms(outputs, batch_data) and returns: loss_dict