class_docstr: Similar to TrainingSampler, but only sample a random subset of indices.
  This is useful when you want to estimate the accuracy vs data-number curves by
    training the model with different subset_ratio.
class_docstr_tok: ["Similar","to","TrainingSampler",",","but","only","sample","a","random","subset","of","indices",".","This","is","useful","when","you","want","to","estimate","the","accuracy","vs","data-number","curves","by","training","the","model","with","different","subset_ratio","."]
docstr: Args:
      size (int): the total number of data of the underlying dataset to sample from
      subset_ratio (float): the ratio of subset data to sample from the underlying dataset
      shuffle (bool): whether to shuffle the indices or not
      seed_shuffle (int): the initial seed of the shuffle. Must be the same
          across all workers. If None, will use a random seed shared
          among workers (require synchronization among all workers).
      seed_subset (int): the seed to randomize the subset to be sampled.
          Must be the same across all workers. If None, will use a random seed shared
          among workers (require synchronization among all workers).
docstr_tok: ["Args",":","size","(","int",")",":","the","total","number","of","data","of","the","underlying","dataset","to","sample","from","subset_ratio","(","float",")",":","the","ratio","of","subset","data","to","sample","from","the","underlying","dataset","shuffle","(","bool",")",":","whether","to","shuffle","the","indices","or","not","seed_shuffle","(","int",")",":","the","initial","seed","of","the","shuffle",".","Must","be","the","same","across","all","workers",".","If","None",",","will","use","a","random","seed","shared","among","workers","(","require","synchronization","among","all","workers",")",".","seed_subset","(","int",")",":","the","seed","to","randomize","the","subset","to","be","sampled",".","Must","be","the","same","across","all","workers",".","If","None",",","will","use","a","random","seed","shared","among","workers","(","require","synchronization","among","all","workers",")","."]
code: def __init__(
      self,
      size: int,
      subset_ratio: float,
      shuffle: bool = True,
      seed_shuffle: Optional[int] = None,
      seed_subset: Optional[int] = None,
  ):
      """
      Args:
          size (int): the total number of data of the underlying dataset to sample from
          subset_ratio (float): the ratio of subset data to sample from the underlying dataset
          shuffle (bool): whether to shuffle the indices or not
          seed_shuffle (int): the initial seed of the shuffle. Must be the same
              across all workers. If None, will use a random seed shared
              among workers (require synchronization among all workers).
          seed_subset (int): the seed to randomize the subset to be sampled.
              Must be the same across all workers. If None, will use a random seed shared
              among workers (require synchronization among all workers).
      """
      super().__init__(size=size, shuffle=shuffle, seed=seed_shuffle)
  
      assert 0.0 < subset_ratio <= 1.0
      self._size_subset = int(size * subset_ratio)
      assert self._size_subset > 0
      if seed_subset is None:
          seed_subset = comm.shared_random_seed()
      self._seed_subset = int(seed_subset)
  
      # randomly generate the subset indexes to be sampled from
      g = torch.Generator()
      g.manual_seed(self._seed_subset)
      indexes_randperm = torch.randperm(self._size, generator=g)
      self._indexes_subset = indexes_randperm[: self._size_subset]
  
      logger.info("Using RandomSubsetTrainingSampler......")
      logger.info(
          f"Randomly sample {self._size_subset} data from the original {self._size} data"
      )
  
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 1 to create a new RandomSubsetTrainingSampler object from inherited base classes: TrainingSampler with example: obj = RandomSubsetTrainingSampler(size, subset_ratio, shuffle, seed_shuffle, seed_subset)