class_docstr: Megatron encoder-decoder base class
class_docstr_tok: ["Megatron","encoder-decoder","base","class"]
docstr: Buld dataloader given an input dataset.
docstr_tok: ["Buld","dataloader","given","an","input","dataset","."]
code: def build_pretraining_data_loader(
      self, dataset, consumed_samples, num_workers
  ):
      """Buld dataloader given an input dataset."""
  
      if dataset is None:
          return None
  
      logging.info(
          f"Building dataloader with consumed samples: {consumed_samples}"
      )
      # Megatron sampler
      if (
          hasattr(self._cfg.data, "dataloader_type")
          and self._cfg.data.dataloader_type is not None
      ):
          if self._cfg.data.dataloader_type == "single":
              batch_sampler = MegatronPretrainingSampler(
                  total_samples=len(dataset),
                  consumed_samples=consumed_samples,
                  micro_batch_size=self._cfg.micro_batch_size,
                  global_batch_size=self._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=self._cfg.get("drop_last", True),
              )
          elif self._cfg.data.dataloader_type == "cyclic":
              batch_sampler = MegatronPretrainingRandomSampler(
                  total_samples=len(dataset),
                  consumed_samples=consumed_samples,
                  micro_batch_size=self._cfg.micro_batch_size,
                  global_batch_size=self._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=self._cfg.get("drop_last", True),
              )
          else:
              raise Exception(
                  f"{self._cfg.dataloader_type} dataloader type is not supported."
              )
      else:
          raise ValueError(
              'cfg.data.dataloader_type not found. Must be "single" or "cyclic"'
          )
  
      # Torch dataloader.
      return torch.utils.data.DataLoader(
          dataset,
          batch_sampler=batch_sampler,
          num_workers=num_workers,
          pin_memory=True,
          persistent_workers=True if num_workers > 0 else False,
      )
  
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 32 for calling the MegatronLMEncoderDecoderModel obj's underlying member method code with example usage: obj.build_pretraining_data_loader(dataset, consumed_samples, num_workers) and returns: torch, None