code: def _shard_iterator_dataloader_worker(iterable, chunk_size=1):
      # Shard the iterable if we're currently inside pytorch dataloader worker.
      worker_info = data.get_worker_info()
      if worker_info is None or worker_info.num_workers == 1:
          # do nothing
          yield from iterable
      else:
          # worker0: 0, 1, ..., chunk_size-1, num_workers*chunk_size, num_workers*chunk_size+1, ...
          # worker1: chunk_size, chunk_size+1, ...
          # worker2: 2*chunk_size, 2*chunk_size+1, ...
          # ...
          yield from _roundrobin(
              *[
                  itertools.islice(
                      iterable,
                      worker_info.id * chunk_size + chunk_i,
                      None,
                      worker_info.num_workers * chunk_size,
                  )
                  for chunk_i in range(chunk_size)
              ]
          )
  
imports: import contextlib
  import copy
  import itertools
  import logging
  import numpy
  import pickle
  import random
  from typing import Callable, Union
  import torch
  import torch.utils.data
  from torch.utils.data.sampler import Sampler
  from detectron2.utils.serialize import PicklableWrapper
label_desc: Use image node_id 2 for calling a global function with example usage: _shard_iterator_dataloader_worker(iterable, chunk_size) without return types