class_docstr: Produce indices for inference across all workers.
  Inference needs to run on the __exact__ set of samples,
  therefore when the total number of samples is not divisible by the number of workers,
  this sampler produces different number of samples on different workers.
class_docstr_tok: ["Produce","indices","for","inference","across","all","workers",".","Inference","needs","to","run","on","the","__exact__","set","of","samples",",","therefore","when","the","total","number","of","samples","is","not","divisible","by","the","number","of","workers",",","this","sampler","produces","different","number","of","samples","on","different","workers","."]
code: def _get_local_indices(total_size, world_size, rank):
      shard_size = total_size // world_size
      left = total_size % world_size
      shard_sizes = [
          shard_size + int(r < left) for r in range(world_size)
      ]
  
      begin = sum(shard_sizes[:rank])
      end = min(sum(shard_sizes[: rank + 1]), total_size)
      return range(begin, end)
  
imports: import itertools
  import logging
  import math
  from collections import defaultdict
  from typing import Optional
  import torch
  from torch.utils.data.sampler import Sampler
  from detectron2.utils import comm
label_desc: Use image node_id 2 for calling the InferenceSampler obj's underlying member method code with example usage: obj._get_local_indices(total_size, world_size, rank) and returns: range