class_docstr: Megatron NMT training
class_docstr_tok: ["Megatron","NMT","training"]
code: def eval_step(self, dataloader_iter, batch_idx, dataloader_idx=0):
      # Check if iterator is exhausted
      dataloader_iter, done = self._val_iterator_done(dataloader_iter)
      if done:
          return
      # Need to squeze dim 0 for old NMT datasets since things are pre-batched and we ask the dataloader for batch size 1.
      batch = next(dataloader_iter)
      batch = [x.squeeze(dim=0) if x.ndim == 3 else x for x in batch]
      batch = self.process_global_batch_for_text_translation_datasets(
          batch
      )
  
      # Eval step requires text datasets so we need to reconfigure MBS on each batch.
      app_state = AppState()
      _reconfigure_microbatch_calculator(
          rank=app_state.global_rank,
          rampup_batch_size=None,
          global_batch_size=batch["text_enc"].size(0)
          * parallel_state.get_data_parallel_world_size(),
          micro_batch_size=batch["text_enc"].size(0),
          data_parallel_size=parallel_state.get_data_parallel_world_size(),
      )
      # This returns the averaged loss across data-parallel groups.
      reduced_loss = self.fwd_bwd_step(
          itertools.chain([batch]), batch_idx, True
      )
  
      tokens_enc, labels, enc_mask = (
          batch["text_enc"],
          batch["labels"],
          batch["enc_mask"],
      )
  
      predicted_tokens_ids, _ = self.decode(
          tokens_enc,
          enc_mask,
          tokens_enc.size(1)
          + self._cfg.max_generation_delta,  # Generate up to src-length + max generation delta. TODO: Implement better stopping when everything hits <EOS>.
          tokenizer=self.decoder_tokenizer,
      )
  
      if self.multilingual:
          source_processor = self.source_processor_list[dataloader_idx]
          target_processor = self.target_processor_list[dataloader_idx]
      else:
          source_processor = self.source_processor
          target_processor = self.target_processor
  
      # Post-process the translations and inputs to log.
      preds = self.postprocess_outputs(
          outputs=predicted_tokens_ids,
          tokenizer=self.decoder_tokenizer,
          processor=target_processor,
      )
      labels = self.postprocess_outputs(
          outputs=labels,
          tokenizer=self.decoder_tokenizer,
          processor=target_processor,
      )
      encoder_inputs = self.postprocess_outputs(
          outputs=tokens_enc,
          tokenizer=self.encoder_tokenizer,
          processor=source_processor,
      )
  
      loss_dict = {
          "inputs": encoder_inputs,
          "translations": preds,
          "ground_truths": labels,
      }
      if isinstance(reduced_loss, dict):
          loss_dict.update(reduced_loss)
      else:
          loss_dict["loss"] = reduced_loss
  
      if (
          type(self.trainer.val_dataloaders) == list
          and len(self.trainer.val_dataloaders) > 1
      ):
          self.validation_step_outputs[dataloader_idx].append(loss_dict)
      else:
          self.validation_step_outputs.append(loss_dict)
  
      return loss_dict
  
imports: import enum
  import itertools
  import random
  from typing import List, Optional
  import numpy
  import torch
  from omegaconf.dictconfig import DictConfig
  from omegaconf.listconfig import ListConfig
  from pytorch_lightning.trainer.trainer import Trainer
  from sacrebleu import corpus_bleu
  from nemo.collections.nlp.data.common.sequence_to_sequence_dataset import BinarizedMemmapSequenceToSequenceDataset, TextMemmapSequenceToSequenceDataset
  from nemo.collections.nlp.data.language_modeling.megatron.base_dataset_utils import get_datasets_weights_and_num_samples
  from nemo.collections.nlp.data.language_modeling.megatron.blendable_dataset import BlendableDataset
  from nemo.collections.nlp.data.language_modeling.megatron.megatron_batch_samplers import MegatronPretrainingBatchSampler
  from nemo.collections.nlp.data.language_modeling.megatron.xlm_dataset import BinarizedMemmapCrossLingualMLMAndTranslationDataset, TextMemmapCrossLingualMLMAndTranslationDataset
  from nemo.collections.nlp.models.language_modeling.megatron_lm_encoder_decoder_model import MegatronLMEncoderDecoderModel
  from nemo.collections.nlp.models.language_modeling.megatron_t5_model import MegatronT5Model
  from nemo.collections.nlp.models.machine_translation.mt_enc_dec_model import MTEncDecModel
  from nemo.collections.nlp.modules.common.megatron.megatron_export import DecEmb, EncEmb, TokensHeadEmb
  from nemo.collections.nlp.modules.common.megatron.utils import get_iterator_k_split
  from nemo.collections.nlp.parts.nlp_overrides import GlobalBatchDataFetcher
  from nemo.collections.nlp.parts.utils_funcs import get_last_rank
  from nemo.core.classes import Exportable
  from nemo.utils import AppState, logging, timers
label_desc: Use image node_id 8 for calling the MegatronNMTModel obj's underlying member method code with example usage: obj.eval_step(dataloader_iter, batch_idx, dataloader_idx) and returns: loss_dict