class_docstr: More fine-grained state DataSampler that uses training iteration and epoch
  both for shuffling data. PyTorch DistributedSampler only uses epoch
  for the shuffling and starts sampling data from the start. In case of training
  on very large data, we train for one epoch only and when we resume training,
  we want to resume the data sampler from the training iteration.
class_docstr_tok: ["More","fine-grained","state","DataSampler","that","uses","training","iteration","and","epoch","both","for","shuffling","data",".","PyTorch","DistributedSampler","only","uses","epoch","for","the","shuffling","and","starts","sampling","data","from","the","start",".","In","case","of","training","on","very","large","data",",","we","train","for","one","epoch","only","and","when","we","resume","training",",","we","want","to","resume","the","data","sampler","from","the","training","iteration","."]
code: def __iter__(self):
      # partition data into num_replicas and optionally shuffle within a rank
      g = torch.Generator()
      g.manual_seed(self.epoch + self.seed)
      shuffling = torch.randperm(self.num_samples, generator=g).tolist()
      indices = np.array(
          list(
              range(
                  (self.rank * self.num_samples),
                  (self.rank + 1) * self.num_samples,
              )
          )
      )[shuffling].tolist()
  
      # make sure we have correct number of samples per replica
      assert len(indices) == self.num_samples
      assert self.batch_size > 0, "batch_size not set for the sampler"
  
      # resume the sampler
      start_index = self.start_iter * self.batch_size
      indices = indices[start_index:]
      return iter(indices)
  
imports: import contextlib
  import logging
  import queue
  from typing import Dict, List
  import numpy
  import torch
  from PIL import Image
  from torch.utils.data import Dataset
  from torch.utils.data.distributed import DistributedSampler
label_desc: Use image node_id 2 for calling the StatefulDistributedSampler obj's underlying member method code with example usage: obj.__iter__() and returns: iter