class_docstr: 随机顺序的 Sampler 。
  
  :param dataset: 实现了 __len__ 方法的数据容器
  :param shuffle: 是否在每次 iterate 的时候打乱顺序
  :param seed: 随机数种子
  :param kwargs: fastNLP 内部使用的参数
class_docstr_tok: ["\u968f\u673a\u987a\u5e8f\u7684","Sampler","\u3002",":","param","dataset",":","\u5b9e\u73b0\u4e86","__len__","\u65b9\u6cd5\u7684\u6570\u636e\u5bb9\u5668",":","param","shuffle",":","\u662f\u5426\u5728\u6bcf\u6b21","iterate","\u7684\u65f6\u5019\u6253\u4e71\u987a\u5e8f",":","param","seed",":","\u968f\u673a\u6570\u79cd\u5b50",":","param","kwargs",":","fastNLP","\u5185\u90e8\u4f7f\u7528\u7684\u53c2\u6570"]
docstr: 进行分布式的相关设置，应当在初始化该 Sampler 本身后立即被调用。
  
  :param num_replicas: 分布式训练中的进程总数
  :param rank: 当前进程的 ``global_rank``。
  :param pad: 如果 sample 数量不整除 ``num_replicas`` 的时候，要不要 pad 一下，使得最终使得每个进程上
      的 sample 数量是完全一致的
  :return: 自身
docstr_tok: ["\u8fdb\u884c\u5206\u5e03\u5f0f\u7684\u76f8\u5173\u8bbe\u7f6e\uff0c\u5e94\u5f53\u5728\u521d\u59cb\u5316\u8be5","Sampler","\u672c\u8eab\u540e\u7acb\u5373\u88ab\u8c03\u7528\u3002",":","param","num_replicas",":","\u5206\u5e03\u5f0f\u8bad\u7ec3\u4e2d\u7684\u8fdb\u7a0b\u603b\u6570",":","param","rank",":","\u5f53\u524d\u8fdb\u7a0b\u7684","``","global_rank","``","\u3002",":","param","pad",":","\u5982\u679c","sample","\u6570\u91cf\u4e0d\u6574\u9664","``","num_replicas","``","\u7684\u65f6\u5019\uff0c\u8981\u4e0d\u8981","pad","\u4e00\u4e0b\uff0c\u4f7f\u5f97\u6700\u7ec8\u4f7f\u5f97\u6bcf\u4e2a\u8fdb\u7a0b\u4e0a","\u7684","sample","\u6570\u91cf\u662f\u5b8c\u5168\u4e00\u81f4\u7684",":","return",":","\u81ea\u8eab"]
code: def set_distributed(
      self, num_replicas: int, rank: int, pad: bool = True
  ):
      """
      进行分布式的相关设置，应当在初始化该 Sampler 本身后立即被调用。
  
      :param num_replicas: 分布式训练中的进程总数
      :param rank: 当前进程的 ``global_rank``。
      :param pad: 如果 sample 数量不整除 ``num_replicas`` 的时候，要不要 pad 一下，使得最终使得每个进程上
          的 sample 数量是完全一致的
      :return: 自身
      """
  
      assert self.during_iter is False, (
          "Cannot set the sampler to be distributed when it is "
          "during an unfinished iteration."
      )
      assert num_replicas > 0 and isinstance(num_replicas, int)
      assert isinstance(rank, int) and 0 <= rank < num_replicas
      # 注意初始化该函数时，所有的状态都应当默认是一个 epoch 刚开始训练的状态；
      self.num_replicas = num_replicas
      self.rank = rank
      self.pad = pad
  
      return self
  
imports: from typing import Dict, List, Union, Sequence
  import math
  import numpy
  from fastNLP.core.log import logger
  from fastNLP.core.dataset import DataSet
label_desc: Use image node_id 8 for calling the RandomSampler obj's underlying member method code with example usage: obj.set_distributed(num_replicas, rank, pad) and returns: self