code: def __init__(self, dataset, weights, batch_size, num_workers):
      super().__init__()
  
      if weights is not None:
          sampler = torch.utils.data.WeightedRandomSampler(
              weights, replacement=True, num_samples=batch_size
          )
      else:
          sampler = torch.utils.data.RandomSampler(
              dataset, replacement=True
          )
  
      if weights == None:
          weights = torch.ones(len(dataset))
  
      batch_sampler = torch.utils.data.BatchSampler(
          sampler, batch_size=batch_size, drop_last=True
      )
  
      self._infinite_iterator = iter(
          torch.utils.data.DataLoader(
              dataset,
              num_workers=num_workers,
              batch_sampler=_InfiniteSampler(batch_sampler),
          )
      )
  
file_path: generalized-moe/domainbed/lib/fast_data_loader.py
imports: import torch
label_desc: Use image node_id 1 to create a new InfiniteDataLoader object  with example: obj = InfiniteDataLoader(dataset, weights, batch_size, num_workers)