class_docstr: Left-to-right Transformer language model.
class_docstr_tok: ["Left-to-right","Transformer","language","model","."]
code: def _setup_dataloader_from_config(
      self, cfg: DictConfig, predict_last_k=0
  ):
      if cfg.get("use_tarred_dataset", False):
          if cfg.get("metadata_file") is None:
              raise FileNotFoundError(
                  "Trying to use tarred data set but could not find metadata path in config."
              )
          else:
              metadata_file = cfg.get("metadata_file")
              with open(metadata_file) as metadata_reader:
                  metadata = json.load(metadata_reader)
              if cfg.get("tar_files") is None:
                  tar_files = metadata.get("tar_files")
                  if tar_files is not None:
                      logging.info(
                          f"Loading from tarred dataset {tar_files}"
                      )
                  else:
                      raise FileNotFoundError(
                          "Could not find tarred dataset in config or metadata."
                      )
              else:
                  tar_files = cfg.get("tar_files")
                  if metadata.get("tar_files") is not None:
                      raise ValueError(
                          "Tar files specified in config and in metadata file. Tar files should only be specified once."
                      )
          dataset = TarredSentenceDataset(
              text_tar_filepaths=tar_files,
              metadata_path=metadata_file,
              tokenizer=self.tokenizer,
              shuffle_n=cfg.get("tar_shuffle_n", 100),
              shard_strategy=cfg.get("shard_strategy", "scatter"),
              global_rank=self.global_rank,
              world_size=self.world_size,
          )
          return torch.utils.data.DataLoader(
              dataset=dataset,
              batch_size=1,
              num_workers=cfg.get("num_workers", 2),
              pin_memory=cfg.get("pin_memory", False),
              drop_last=cfg.get("drop_last", False),
          )
      else:
          dataset = SentenceDataset(
              tokenizer=self.tokenizer,
              dataset=cfg.file_name,
              tokens_in_batch=cfg.tokens_in_batch,
              clean=cfg.get("clean", False),
              max_seq_length=cfg.get("max_seq_length", 512),
              min_seq_length=cfg.get("min_seq_length", 1),
              cache_ids=cfg.get("cache_ids", False),
          )
      if cfg.shuffle:
          sampler = pt_data.RandomSampler(dataset)
      else:
          sampler = pt_data.SequentialSampler(dataset)
      return torch.utils.data.DataLoader(
          dataset=dataset,
          batch_size=1,
          sampler=sampler,
          num_workers=cfg.get("num_workers", 2),
          pin_memory=cfg.get("pin_memory", False),
          drop_last=cfg.get("drop_last", False),
      )
  
imports: import json
  import math
  from typing import Dict, Optional
  import numpy
  import torch
  import torch.utils.data
  from omegaconf import DictConfig, OmegaConf
  from pytorch_lightning import Trainer
  from nemo.collections.common.losses import SmoothedCrossEntropyLoss
  from nemo.collections.common.metrics import GlobalAverageLossMetric
  from nemo.collections.common.parts import transformer_weights_init
  from nemo.collections.nlp.data import SentenceDataset, TarredSentenceDataset
  from nemo.collections.nlp.metrics import SequencePerplexity
  from nemo.collections.nlp.modules.common import TokenClassifier
  from nemo.collections.nlp.modules.common.lm_utils import get_transformer
  from nemo.collections.nlp.modules.common.tokenizer_utils import get_tokenizer
  from nemo.core.classes.common import typecheck
  from nemo.core.classes.modelPT import ModelPT
  from nemo.utils import logging, model_utils
label_desc: Use image node_id 14 for calling the TransformerLMModel obj's underlying member method code with example usage: obj._setup_dataloader_from_config(cfg, predict_last_k) and returns: torch, torch