class_docstr: Megatron Bert pretraining.
  Model returns [batch, seq, hidden] shape
class_docstr_tok: ["Megatron","Bert","pretraining",".","Model","returns","[","batch",",","seq",",","hidden","]","shape"]
code: def validation_step(self, dataloader_iter, batch_idx):
      # Check if iterator is exhausted
      dataloader_iter, done = self._val_iterator_done(dataloader_iter)
      if done:
          return
      prefix = "test" if self.trainer.testing else "val"
      if self.cfg.data.dataloader_type == "LDDL":
          seq_length = dataloader_iter.iterator.get_seqlen()
      else:
          seq_length = self.cfg.encoder_seq_length
  
      fwd_bwd_function = get_forward_backward_func()
  
      losses_reduced_per_micro_batch = fwd_bwd_function(
          forward_step_func=self.get_forward_output_and_loss_func(),
          data_iterator=dataloader_iter,
          model=[self.model],
          num_microbatches=get_num_microbatches(),
          forward_only=True,
          seq_length=seq_length,
          micro_batch_size=self.cfg.micro_batch_size,
      )
  
      if losses_reduced_per_micro_batch:
          loss_tensors_list = [
              loss_reduced["loss"]
              for loss_reduced in losses_reduced_per_micro_batch
          ]
          loss_tensor = torch.vstack(loss_tensors_list)
          loss_mean = loss_tensor.mean(axis=0)
      else:
          loss_mean = torch.tensor([0.0]).cuda()
  
      loss = loss_mean[0]
      self.validation_step_outputs.append(
          loss
      ) if prefix == "val" else self.test_step_outputs.append(loss)
      return loss
  
imports: import itertools
  from typing import Any, Dict, List, Optional
  import torch
  import torch.nn.functional
  from omegaconf.dictconfig import DictConfig
  from pytorch_lightning.trainer.trainer import Trainer
  from nemo.collections.nlp.data.language_modeling.megatron import dataset_utils
  from nemo.collections.nlp.data.language_modeling.megatron.data_samplers import MegatronPretrainingRandomSampler, MegatronPretrainingSampler
  from nemo.collections.nlp.models.language_modeling.megatron.bert_model import BertModel
  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.utils import ApexGuardDefaults, average_losses_across_data_parallel_group, get_params_for_weight_decay_optimization
  from nemo.collections.nlp.parts.nlp_overrides import GradScaler
  from nemo.collections.nlp.parts.utils_funcs import get_last_rank
  from nemo.core.classes.common import PretrainedModelInfo
  from nemo.core.neural_types import ChannelType, MaskType, NeuralType
  from nemo.utils import AppState, logging
label_desc: Use image node_id 8 for calling the MegatronBertModel obj's underlying member method code with example usage: obj.validation_step(dataloader_iter, batch_idx) and returns: loss