class_docstr: Megatron NMT training
class_docstr_tok: ["Megatron","NMT","training"]
code: def _setup_megatron_dataloader_from_config(
      self, cfg, dataset, consumed_samples
  ):
      logging.info(
          f"Building dataloader with consumed samples: {consumed_samples}"
      )
      if isinstance(dataset, BlendableDataset):
          collate_fn = dataset.datasets[0].collate_fn
      else:
          collate_fn = dataset.collate_fn
  
      batch_sampler = MegatronPretrainingBatchSampler(
          total_samples=len(dataset),
          consumed_samples=consumed_samples,
          micro_batch_size=cfg.micro_batch_size,
          global_batch_size=cfg.global_batch_size,
          data_parallel_rank=parallel_state.get_data_parallel_rank(),
          data_parallel_size=parallel_state.get_data_parallel_world_size(),
          drop_last=True,
      )
      return torch.utils.data.DataLoader(
          dataset,
          batch_sampler=batch_sampler,
          collate_fn=collate_fn,
          num_workers=cfg.num_workers,
          pin_memory=cfg.pin_memory,
          persistent_workers=True if cfg.num_workers > 0 else False,
      )
  
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 19 for calling the MegatronNMTModel obj's underlying member method code with example usage: obj._setup_megatron_dataloader_from_config(cfg, dataset, consumed_samples) and returns: torch