class_docstr: Megatron GPT Supervised Fine-Tuning
class_docstr_tok: ["Megatron","GPT","Supervised","Fine-Tuning"]
docstr: Buld dataloader given an input dataset.
docstr_tok: ["Buld","dataloader","given","an","input","dataset","."]
code: def build_data_loader(self, dataset, data_cfg, consumed_samples=0):
      """Buld dataloader given an input dataset."""
  
      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=data_cfg.micro_batch_size,
          global_batch_size=data_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=data_cfg.drop_last,
          pad_samples_to_global_batch_size=not data_cfg.drop_last,
      )
      return torch.utils.data.DataLoader(
          dataset,
          batch_sampler=batch_sampler,
          collate_fn=collate_fn,
          num_workers=data_cfg.num_workers,
          pin_memory=data_cfg.pin_memory,
      )
  
imports: import itertools
  import json
  from functools import partial
  from typing import Any, Optional
  import torch
  from omegaconf import DictConfig, ListConfig
  from pytorch_lightning.trainer.trainer import Trainer
  from nemo.collections.common.metrics import MetricStringToTorchMetric
  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.gpt_sft_chat_dataset import GPTSFTChatDataset
  from nemo.collections.nlp.data.language_modeling.megatron.gpt_sft_dataset import GPTSFTDataset, GPTSFTPackedDataset
  from nemo.collections.nlp.data.language_modeling.megatron.megatron_batch_samplers import MegatronPretrainingBatchSampler
  from nemo.collections.nlp.models.language_modeling.megatron_gpt_model import MegatronGPTModel
  from nemo.collections.nlp.modules.common.megatron.utils import get_iterator_k_split
  from nemo.collections.nlp.modules.common.text_generation_utils import generate, get_computeprob_response
  from nemo.collections.nlp.parts.mixins.nlp_adapter_mixins import NLPAdapterModelMixin
  from nemo.collections.nlp.parts.utils_funcs import get_last_rank
  from nemo.utils import AppState, logging
label_desc: Use image node_id 17 for calling the MegatronGPTSFTModel obj's underlying member method code with example usage: obj.build_data_loader(dataset, data_cfg, consumed_samples) and returns: torch