docstr: Setup metrics for this model for all available dataloaders.
  
  When using multiple DataLoaders, it is recommended to initialize separate modular
  metric instances for each DataLoader and use them separately.
  
  Reference:
      - https://torchmetrics.readthedocs.io/en/stable/pages/lightning.html#common-pitfalls
docstr_tok: ["Setup","metrics","for","this","model","for","all","available","dataloaders",".","When","using","multiple","DataLoaders",",","it","is","recommended","to","initialize","separate","modular","metric","instances","for","each","DataLoader","and","use","them","separately",".","Reference",":","-","https",":","\/\/torchmetrics.readthedocs.io\/en\/stable\/pages\/lightning.html","#","common-pitfalls"]
code: def _setup_metrics(self, tag: str = "val"):
      """Setup metrics for this model for all available dataloaders.
  
      When using multiple DataLoaders, it is recommended to initialize separate modular
      metric instances for each DataLoader and use them separately.
  
      Reference:
          - https://torchmetrics.readthedocs.io/en/stable/pages/lightning.html#common-pitfalls
      """
      # Number of currently configured dataloaders
      num_dataloaders = self._get_num_dataloaders(tag)
      logging.debug("Found %d dataloaders for %s", num_dataloaders, tag)
  
      if hasattr(self, "metrics"):
          if (
              tag in self.metrics
              and len(self.metrics[tag]) == num_dataloaders
          ):
              # Exact number of metrics have already been configured, nothing else to do
              logging.debug(
                  "Found %d metrics for tag %s, not necesary to initialize again",
                  num_dataloaders,
                  tag,
              )
              return
  
      if self.cfg.get("metrics") is None:
          # Metrics are not available in the configuration, nothing to do
          logging.debug("No metrics configured in model.metrics")
          return
  
      if (metrics_cfg := self.cfg["metrics"].get(tag)) is None:
          # Metrics configuration is not available in the configuration, nothing to do
          logging.debug(
              "No metrics configured for %s in model.metrics", tag
          )
          return
  
      if "loss" in metrics_cfg:
          raise ValueError(
              f"Loss is automatically included in the metrics, it should not be specified in model.metrics.{tag}."
          )
  
      # Initialize metrics
      if not hasattr(self, "metrics"):
          self.metrics = torch.nn.ModuleDict()
  
      # Setup metrics for each dataloader
      self.metrics[tag] = torch.nn.ModuleList()
      for dataloader_idx in range(num_dataloaders):
          metrics_dataloader_idx = {}
          for name, cfg in metrics_cfg.items():
              logging.debug(
                  "Initialize %s for dataloader_idx %s",
                  name,
                  dataloader_idx,
              )
              cfg_dict = OmegaConf.to_container(cfg)
              cfg_channel = cfg_dict.pop("channel", None)
              cfg_batch_averaging = cfg_dict.pop(
                  "metric_using_batch_averaging", None
              )
              metrics_dataloader_idx[name] = AudioMetricWrapper(
                  metric=hydra.utils.instantiate(cfg_dict),
                  channel=cfg_channel,
                  metric_using_batch_averaging=cfg_batch_averaging,
              )
  
          metrics_dataloader_idx = torch.nn.ModuleDict(
              metrics_dataloader_idx
          )
          self.metrics[tag].append(
              metrics_dataloader_idx.to(self.device)
          )
  
          logging.info(
              "Setup metrics for %s, dataloader %d: %s",
              tag,
              dataloader_idx,
              ", ".join(metrics_dataloader_idx),
          )
  
imports: from abc import ABC, abstractmethod
  from typing import List, Union
  import hydra
  import torch
  from omegaconf import DictConfig, OmegaConf
  from pytorch_lightning import Trainer
  from nemo.collections.asr.metrics.audio import AudioMetricWrapper
  from nemo.core.classes import ModelPT
  from nemo.utils import logging, model_utils
label_desc: Use image node_id 4 for calling the AudioToAudioModel obj's underlying member method code with example usage: obj._setup_metrics(tag) without return types