class_docstr: Megatron Vision Transformer Model.
class_docstr_tok: ["Megatron","Vision","Transformer","Model","."]
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, drop_last=True
  ):
      """Buld dataloader given an input dataset."""
  
      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=drop_last,
              )
          elif self.cfg.data.dataloader_type == "cyclic":
              batch_sampler = MegatronVisionPretrainingRandomSampler(
                  dataset=dataset,
                  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,
                  data_sharding=self.cfg.data.get(
                      "data_sharding", True
                  ),
              )
          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"'
          )
  
      return torch.utils.data.DataLoader(
          dataset,
          batch_sampler=batch_sampler,
          num_workers=self.cfg.data.num_workers,
          pin_memory=True,
          persistent_workers=True
          if self.cfg.data.num_workers > 0
          else False,
      )
  
imports: import itertools
  from functools import partial
  from typing import Any, Optional
  import torch
  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 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, MegatronModule
  from nemo.collections.nlp.modules.common.megatron.utils import average_losses_across_data_parallel_group, get_all_params_for_weight_decay_optimization, get_linear_layer, get_params_for_weight_decay_optimization, init_method_normal, scaled_init_method_normal
  from nemo.collections.nlp.parts.utils_funcs import get_last_rank, torch_dtype_from_precision
  from nemo.collections.vision.data.megatron.data_samplers import MegatronVisionPretrainingRandomSampler
  from nemo.collections.vision.data.megatron.vit_dataset import build_train_valid_datasets
  from nemo.collections.vision.modules.vit.vit_backbone import VitBackbone, VitMlpHead
  from nemo.core.classes.common import PretrainedModelInfo
  from nemo.utils import logging
label_desc: Use image node_id 21 for calling the MegatronVitClassificationModel obj's underlying member method code with example usage: obj.build_pretraining_data_loader(dataset, consumed_samples, drop_last) and returns: torch