This is the small (hopefully easy to follow function):

  
      github.com
  
  
    pytorch/pytorch/blob/master/torch/utils/data/dataloader.py#L129 57

        if re.search('[SaUO]', elem.dtype.str) is not None:
            raise TypeError(error_msg.format(elem.dtype))


        return torch.stack([torch.from_numpy(b) for b in batch], 0)
    if elem.shape == ():  # scalars
        py_type = float if elem.dtype.name.startswith('float') else int
        return numpy_type_map[elem.dtype.name](list(map(py_type, batch)))
elif isinstance(batch[0], int_classes):
    return torch.LongTensor(batch)
elif isinstance(batch[0], float):
    return torch.DoubleTensor(batch)
elif isinstance(batch[0], string_classes):
    return batch
elif isinstance(batch[0], collections.Mapping):
    return {key: default_collate([d[key] for d in batch]) for key in batch[0]}
elif isinstance(batch[0], collections.Sequence):
    transposed = zip(*batch)
    return [default_collate(samples) for samples in transposed]


raise TypeError((error_msg.format(type(batch[0]))))





  
  
    
    
  
  


On each __iter__ the DataLoader returns a new one of these iterators: https://github.com/pytorch/pytorch/blob/master/torch/utils/data/dataloader.py#L302 48
The iterator creates a new self.workers everytime it’s created: https://github.com/pytorch/pytorch/blob/master/torch/utils/data/dataloader.py#L151-L155 35