code: def on_validation_epoch_end(self):
      if self.cfg.get("pipeline_model_parallel_size", 1) > 1:
          if parallel_state.is_pipeline_last_stage():
              # only the last pipeline parallel stages return loss
              averaged_loss = torch.stack(
                  [i["loss"] for i in self.validation_step_outputs]
              ).mean()
          else:
              averaged_loss = torch.tensor(0.0).cuda()
  
          # we can only log on one rank if it is rank zero so we broadcast from last rank
          torch.distributed.broadcast(averaged_loss, get_last_rank())
  
          self.log(
              "val_loss",
              averaged_loss,
              prog_bar=True,
              rank_zero_only=True,
              batch_size=1,
          )
          logging.info(f"Validation loss: {averaged_loss}")
  
      else:
          averaged_loss = torch.stack(
              [item["loss"] for item in self.validation_step_outputs]
          ).mean()
          logging.info(f"Validation loss: {averaged_loss}")
          self.log(
              "val_loss",
              averaged_loss,
              prog_bar=True,
              rank_zero_only=True,
              batch_size=1,
          )
  
      if self.cfg.get("report_validation_accuracy", False):
          gather_results = [
              None
              for _ in range(
                  parallel_state.get_data_parallel_world_size()
              )
          ]
          all_preds = list(
              itertools.chain(
                  *[
                      item["predicted_token_ids"]
                      for item in self.validation_step_outputs
                  ]
              )
          )
          all_labels = list(
              itertools.chain(
                  *[
                      item["labels"]
                      for item in self.validation_step_outputs
                  ]
              )
          )
          all_inputs = list(
              itertools.chain(
                  *[
                      item["enc_inputs"]
                      for item in self.validation_step_outputs
                  ]
              )
          )
  
          assert len(all_preds) == len(all_labels)
          assert len(all_preds) == len(all_inputs)
  
          # Gather inputs, preds, labels from all workers
          torch.distributed.all_gather_object(
              gather_results,
              [
                  (input, pred, label)
                  for (input, pred, label) in zip(
                      all_inputs, all_preds, all_labels
                  )
              ],
              group=parallel_state.get_data_parallel_group(),
          )
  
          # Deduplicate sentences that may have been distributed across multiple data parallel ranks.
          if parallel_state.get_data_parallel_rank() == 0:
              gather_results_dedup = list(
                  set(itertools.chain(*gather_results))
              )
  
              correct = 0
              for input, pred, label in gather_results_dedup:
                  if pred == label:
                      correct += 1
  
              val_acc = correct / len(gather_results_dedup)
              val_acc = torch.tensor(val_acc).cuda()
  
              logging.info(f"Validation accuracy: {val_acc}")
          else:
              val_acc = torch.tensor(0.0).cuda()
  
          self.log(
              "val_acc",
              val_acc,
              prog_bar=True,
              rank_zero_only=True,
              batch_size=1,
          )
  
      gbs = self.cfg.global_batch_size
      mbs = self.cfg.micro_batch_size
      self._reconfigure_batch_sizes(gbs, mbs)
      self.validation_step_outputs.clear()
  
imports: import itertools
  from typing import Any
  import torch
  from omegaconf.dictconfig import DictConfig
  from omegaconf.omegaconf import open_dict
  from pytorch_lightning.trainer.trainer import Trainer
  from nemo.collections.common.parts.adapter_modules import LinearAdapterConfig
  from nemo.collections.nlp.models.language_modeling.megatron_t5_model import MegatronT5Model
  from nemo.collections.nlp.models.language_modeling.megatron_t5_prompt_learning_model import MegatronT5PromptLearningModel
  from nemo.collections.nlp.models.language_modeling.megatron_t5_sft_model import MegatronT5SFTModel
  from nemo.collections.nlp.modules.common import VirtualPromptStyle
  from nemo.collections.nlp.modules.common.megatron.adapters.parallel_adapters import AdapterName, InfusedAdapterConfig, LoraKQVAdapterConfig, LoraKVAdapterConfig, LoraQAdapterConfig, MLPInfusedAdapterConfig, ParallelLinearAdapterConfig
  from nemo.collections.nlp.parts.utils_funcs import get_last_rank
  from nemo.core.classes.mixins import adapter_mixins
  from nemo.utils import logging, model_utils
label_desc: Use image node_id 12 for calling the MegatronT5BaseAdapterModel obj's underlying member method code with example usage: obj.on_validation_epoch_end() without return types