docstr: Build dataloader given an input dataset.
docstr_tok: ["Build","dataloader","given","an","input","dataset","."]
code: def build_pretraining_data_loader(
      self, dataset, consumed_samples, drop_last=True
  ):
      """Build 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
      ):
          # TODO (yuya): fix this
          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=drop_last,
              )
          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=drop_last,
              )
          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=self._cfg.data.num_workers,
          pin_memory=True,
      )
  
file_path: NeMo/nemo/collections/multimodal/models/text_to_image/instruct_pix2pix/ldm/ddpm_edit.py
imports: import torch
  from einops import rearrange
  from nemo.collections.multimodal.data.instruct_pix2pix.edit_dataset import EditDataset
  from nemo.collections.multimodal.models.text_to_image.stable_diffusion.ldm.ddpm import LatentDiffusion, MegatronLatentDiffusion
  from nemo.collections.nlp.data.language_modeling.megatron.data_samplers import MegatronPretrainingRandomSampler, MegatronPretrainingSampler
  from nemo.utils import logging
label_desc: Use image node_id 7 for calling the MegatronLatentDiffusionEdit obj's underlying member method code with example usage: obj.build_pretraining_data_loader(dataset, consumed_samples, drop_last) and returns: torch, None