class_docstr: Megatron Retrieval enhanced language model
class_docstr_tok: ["Megatron","Retrieval","enhanced","language","model"]
docstr: Buld dataloader given an input dataset.
code: def build_pretraining_data_loader(self, dataset, consumed_samples):
      """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,
                  data_parallel_rank=parallel_state.get_data_parallel_rank(),
                  data_parallel_size=parallel_state.get_data_parallel_world_size(),
              )
          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,
                  data_parallel_rank=parallel_state.get_data_parallel_rank(),
                  data_parallel_size=parallel_state.get_data_parallel_world_size(),
              )
          else:
              raise ValueError(
                  'cfg.data.dataloader_type must be "single" or "cyclic"'
              )
      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=self.cfg.data.num_workers,
          pin_memory=True,
      )
  
imports: import math
  from typing import Any, List, Optional, Union
  import torch
  from omegaconf import DictConfig
  from pytorch_lightning.trainer.trainer import Trainer
  from nemo.collections.nlp.data.language_modeling.megatron.data_samplers import MegatronPretrainingRandomSampler, MegatronPretrainingSampler
  from nemo.collections.nlp.data.language_modeling.megatron.retro_dataset import build_mock_train_valid_test_datasets, build_train_valid_test_datasets
  from nemo.collections.nlp.models.language_modeling.megatron_base_model import MegatronBaseModel
  from nemo.collections.nlp.modules.common.megatron.module import Float16Module
  from nemo.collections.nlp.modules.common.megatron.mup.init import normal_
  from nemo.collections.nlp.modules.common.megatron.mup.shape import set_base_shapes
  from nemo.collections.nlp.modules.common.megatron.retrieval_token_level_encoder_decoder import MegatronRetrievalTokenLevelEncoderDecoderModule
  from nemo.collections.nlp.modules.common.megatron.utils import average_losses_across_data_parallel_group, build_position_ids, get_params_for_weight_decay_optimization
  from nemo.collections.nlp.modules.common.text_generation_strategy import model_inference_strategy_dispatcher
  from nemo.collections.nlp.modules.common.text_generation_utils import generate, get_computeprob_response, get_default_length_params, get_default_sampling_params, megatron_gpt_generate
  from nemo.collections.nlp.modules.common.tokenizer_utils import get_nmt_tokenizer
  from nemo.collections.nlp.modules.common.transformer.text_generation import LengthParam, OutputType, SamplingParam, TextGeneration
  from nemo.collections.nlp.parts.nlp_overrides import GradScaler
  from nemo.utils import AppState, logging
label_desc: Use image node_id 11 for calling the MegatronRetrievalModel obj's underlying member method code with example usage: obj.build_pretraining_data_loader(dataset, consumed_samples) and returns: torch, None