code: def get_hiddens_module(
      cfg=None, model_parallel_cfg: ModelParallelConfig = None
  ):
      """Build a MegatronHiddensModule from a configuration cfg"""
      # Build a hiddens module if config is provided.
      if cfg is None:
          return None
  
      logging.info(f"NOTE: Adding hiddens transforms and losses")
  
      # build all hidden transforms. We support a list or a dictionary of transforms (list enforces order)
      transform_cfg = cfg.get("transform", [])
      if isinstance(transform_cfg, (DictConfig, dict)):
          transform_cfg = [transform_cfg]
      hidden_transforms = []
      # here we expect transform_cfg to be a list of dictionaries
      for cur_list_cfg in transform_cfg:
          for name, cur_cfg in cur_list_cfg.items():
              cls_kwargs = OmegaConf.to_container(cur_cfg)
              cls_kwargs["model_parallel_cfg"] = model_parallel_cfg
              if not "cls_name" in cls_kwargs:
                  raise KeyError(
                      f"Missing 'cls_name' in hidden transform {name}"
                  )
  
              cls_name = cls_kwargs.pop("cls_name")
              # add name based on dictionary if not given in conf
              if "name" not in cls_kwargs:
                  cls_kwargs["name"] = name
              if cls_name not in _TRANSFORM_CLASS_REGISTRY:
                  raise KeyError(
                      f"Unknown hidden transform {cls_name}, available: {_TRANSFORM_CLASS_REGISTRY.keys()}"
                  )
              try:
                  cur_transform = import_class_by_path(
                      _TRANSFORM_CLASS_REGISTRY[cls_name]
                  )(**cls_kwargs)
              except Exception as e:
                  logging.error(
                      f"Failed to build hidden transform {name} with cfg={cur_cfg}"
                  )
                  raise e
  
              hidden_transforms.append(cur_transform)
              logging.info(f"Added transform {name} with cfg={cur_cfg}")
  
      # build all hidden losses
      loss_cfg = cfg.get("loss", [])
      if isinstance(loss_cfg, (DictConfig, dict)):
          loss_cfg = [loss_cfg]
      hidden_loss_transforms = []
      # here we expect loss_cfg to be a list of dictionaries
      for cur_list_cfg in loss_cfg:
          for name, cur_cfg in cur_list_cfg.items():
              cls_kwargs = OmegaConf.to_container(cur_cfg)
              if not "cls_name" in cls_kwargs:
                  raise KeyError(
                      f"Missing 'cls_name' in hidden loss {name}"
                  )
  
              cls_name = cls_kwargs.pop("cls_name")
              # add name based on dictionary if not given in conf
              if "name" not in cls_kwargs:
                  cls_kwargs["name"] = name
              if cls_name not in _LOSS_CLASS_REGISTRY:
                  raise KeyError(
                      f"Unknown hidden loss {cls_name}, available: {_LOSS_CLASS_REGISTRY.keys()}"
                  )
              try:
                  cur_loss = import_class_by_path(
                      _LOSS_CLASS_REGISTRY[cls_name]
                  )(**cls_kwargs)
              except Exception as e:
                  logging.error(
                      f"Failed to build hidden loss {name} with cfg={cur_cfg}"
                  )
                  raise e
              hidden_loss_transforms.append(cur_loss)
              logging.info(f"Added loss {name} with cfg={cur_cfg}")
  
      enc_output_name = cfg.get("enc_output_name", "hiddens")
  
      return MegatronHiddensModule(
          hidden_transforms=hidden_transforms,
          hidden_loss_transforms=hidden_loss_transforms,
          enc_output_name=enc_output_name,
      )
  
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 4 for calling a global function with example usage: get_hiddens_module(cfg, model_parallel_cfg) and returns: MegatronHiddensModule, None