class_docstr: DistributedSampler will iterate through an underlying sampler and return samples which
  belong to this shard.
  
  DistributedSampler is different from the PyTorch built-in torch.utils.data.DistributedSampler
  because theirs is meant to be a standalone sampler.  Theirs does shuffling and assumes a
  constant size dataset as an input.  Ours is meant to be used a building block in a chain of
  samplers, so it accepts a sampler as input that may or may not be constant-size.
class_docstr_tok: ["DistributedSampler","will","iterate","through","an","underlying","sampler","and","return","samples","which","belong","to","this","shard",".","DistributedSampler","is","different","from","the","PyTorch","built-in","torch.utils.data.DistributedSampler","because","theirs","is","meant","to","be","a","standalone","sampler",".","Theirs","does","shuffling","and","assumes","a","constant","size","dataset","as","an","input",".","Ours","is","meant","to","be","used","a","building","block","in","a","chain","of","samplers",",","so","it","accepts","a","sampler","as","input","that","may","or","may","not","be","constant-size","."]
code: def __iter__(self) -> Iterator:
      if self._num_workers == 1:
          yield from self._sampler
      else:
          for i, batch in enumerate(self._sampler):
              if i % self._num_workers == self._rank:
                  yield batch
  
imports: from typing import Iterator
  import numpy
  import torch
label_desc: Use image node_id 3 for calling the DistributedSampler obj's underlying member method code with example usage: obj.__iter__() without return types