class_docstr: Megatron encoder-decoder base class
class_docstr_tok: ["Megatron","encoder-decoder","base","class"]
docstr: Shared logging for validation and test
docstr_tok: ["Shared","logging","for","validation","and","test"]
code: def _test_validation_epoch_end(self, step_outputs, prefix):
      """
      Shared logging for validation and test
      """
      # NOTE: we need to make sure outputs is not empty (this is a workaround for a bug in pytorch lightning (?))
      if not step_outputs:
          logging.warning(f"{prefix} epoch end: outputs is empty")
          return None
  
      # only the last pipeline parallel stages return loss
      if parallel_state.is_pipeline_last_stage() and len(step_outputs):
          averaged_loss = {
              k: torch.stack([x[k] for x in step_outputs]).mean()
              for k in step_outputs[0].keys()
          }
      else:
          # if we are here we assume that only loss is available and hidden transforms are disabled (since not supported in pipleline parallel)
          averaged_loss = {"loss": torch.tensor(0.0).cuda()}
  
      # we can only log on one rank if it is rank zero so we broadcast from last rank
      for k, v in averaged_loss.items():
          torch.distributed.broadcast(v, get_last_rank())
          averaged_loss[k] = v
          n = f"{prefix}_{k}"
          # log only '*_loss' values in progress bar
          self.log(
              n,
              v,
              prog_bar=(n.endswith("_loss")),
              rank_zero_only=True,
              batch_size=1,
          )
  
      # free memory
      step_outputs.clear()
  
      return averaged_loss
  
imports: import copy
  import functools
  import inspect
  from typing import Any, Dict, List, Optional
  import torch
  from omegaconf import OmegaConf, open_dict
  from omegaconf.dictconfig import DictConfig
  from pytorch_lightning.accelerators import CPUAccelerator
  from pytorch_lightning.trainer.trainer import Trainer
  from nemo.collections.nlp.data.language_modeling.megatron.data_samplers import MegatronPretrainingRandomSampler, MegatronPretrainingSampler
  from nemo.collections.nlp.models.language_modeling.megatron_base_model import MegatronBaseModel
  from nemo.collections.nlp.modules.common.megatron.build_model import build_model
  from nemo.collections.nlp.modules.common.megatron.module import Float16Module
  from nemo.collections.nlp.modules.common.megatron.token_level_encoder_decoder import MegatronTokenLevelEncoderDecoderModule
  from nemo.collections.nlp.modules.common.megatron.utils import ApexGuardDefaults, average_losses_across_data_parallel_group, get_params_for_weight_decay_optimization
  from nemo.collections.nlp.modules.common.text_generation_utils import compute_beam_search_len_penalty, get_sampling_token_fn
  from nemo.collections.nlp.parts.utils_funcs import get_last_rank
  from nemo.utils import AppState, logging
label_desc: Use image node_id 25 for calling the MegatronLMEncoderDecoderModel obj's underlying member method code with example usage: obj._test_validation_epoch_end(step_outputs, prefix) and returns: averaged_loss, None