class_docstr: A runner class to train and evaluate a model given a task and datasets.
  
  The runner uses pytorch distributed data parallel by default. Future release
  will support other distributed frameworks.
class_docstr_tok: ["A","runner","class","to","train","and","evaluate","a","model","given","a","task","and","datasets",".","The","runner","uses","pytorch","distributed","data","parallel","by","default",".","Future","release","will","support","other","distributed","frameworks","."]
docstr: Create dataloaders for training and validation.
code: def create_loaders(
      self,
      datasets,
      num_workers,
      batch_sizes,
      is_trains,
      collate_fns,
      dataset_ratios=None,
  ):
      """
      Create dataloaders for training and validation.
      """
  
      def _create_loader(
          dataset, num_workers, bsz, is_train, collate_fn
      ):
          # create a single dataloader for each split
          if isinstance(dataset, ChainDataset) or isinstance(
              dataset, wds.DataPipeline
          ):
              # wds.WebdDataset instance are chained together
              # webdataset.DataPipeline has its own sampler and collate_fn
              loader = iter(
                  DataLoader(
                      dataset,
                      batch_size=bsz,
                      num_workers=num_workers,
                      pin_memory=True,
                  )
              )
          else:
              # map-style dataset are concatenated together
              # setup distributed sampler
              if self.use_distributed:
                  sampler = DistributedSampler(
                      dataset,
                      shuffle=is_train,
                      num_replicas=get_world_size(),
                      rank=get_rank(),
                  )
                  if not self.use_dist_eval_sampler:
                      # e.g. retrieval evaluation
                      sampler = sampler if is_train else None
              else:
                  sampler = None
  
              loader = DataLoader(
                  dataset,
                  batch_size=bsz,
                  num_workers=num_workers,
                  pin_memory=True,
                  sampler=sampler,
                  shuffle=sampler is None and is_train,
                  collate_fn=collate_fn,
                  drop_last=True if is_train else False,
              )
              loader = PrefetchLoader(loader)
  
              if is_train:
                  loader = IterLoader(
                      loader, use_distributed=self.use_distributed
                  )
  
          return loader
  
      loaders = []
  
      for dataset, bsz, is_train, collate_fn in zip(
          datasets, batch_sizes, is_trains, collate_fns
      ):
          if isinstance(dataset, list) or isinstance(dataset, tuple):
              loader = MultiIterLoader(
                  loaders=[
                      _create_loader(
                          d, num_workers, bsz, is_train, collate_fn[i]
                      )
                      for i, d in enumerate(dataset)
                  ],
                  ratios=dataset_ratios,
              )
          else:
              loader = _create_loader(
                  dataset, num_workers, bsz, is_train, collate_fn
              )
  
          loaders.append(loader)
  
      return loaders
  
imports: import datetime
  import json
  import logging
  import os
  import time
  from pathlib import Path
  import torch
  import torch.distributed
  import webdataset
  from lavis.common.dist_utils import download_cached_file, get_rank, get_world_size, is_main_process, main_process
  from lavis.common.registry import registry
  from lavis.common.utils import is_url
  from lavis.datasets.data_utils import concat_datasets, reorg_datasets_by_split
  from lavis.datasets.datasets.dataloader_utils import IterLoader, MultiIterLoader, PrefetchLoader
  from torch.nn.parallel import DistributedDataParallel
  from torch.utils.data import DataLoader, DistributedSampler
  from torch.utils.data.dataset import ChainDataset
label_desc: Use image node_id 31 for calling the RunnerBase obj's underlying member method code with example usage: obj.create_loaders(datasets, num_workers, batch_sizes, is_trains, collate_fns, dataset_ratios) and returns: loaders, loader