class_docstr: 随机分 batch 的 batch_sampler 。
  
  :param dataset: 实现了 __len__ 方法的数据容器
  :param batch_size: 每个 batch 的大小
  :param shuffle: 如果为 ``True``，将不进行打乱操作，实际上数据会以从长到短的方式输出
  :param drop_last: 如果最后一个 batch 无法构成 batch_size 个 sample ，是否丢掉
  :param seed: 设置的随机数种子
  :param kwargs: fastNLP 内部使用的参数
class_docstr_tok: ["\u968f\u673a\u5206","batch","\u7684","batch_sampler","\u3002",":","param","dataset",":","\u5b9e\u73b0\u4e86","__len__","\u65b9\u6cd5\u7684\u6570\u636e\u5bb9\u5668",":","param","batch_size",":","\u6bcf\u4e2a","batch","\u7684\u5927\u5c0f",":","param","shuffle",":","\u5982\u679c\u4e3a","``","True","``","\uff0c\u5c06\u4e0d\u8fdb\u884c\u6253\u4e71\u64cd\u4f5c\uff0c\u5b9e\u9645\u4e0a\u6570\u636e\u4f1a\u4ee5\u4ece\u957f\u5230\u77ed\u7684\u65b9\u5f0f\u8f93\u51fa",":","param","drop_last",":","\u5982\u679c\u6700\u540e\u4e00\u4e2a","batch","\u65e0\u6cd5\u6784\u6210","batch_size","\u4e2a","sample","\uff0c\u662f\u5426\u4e22\u6389",":","param","seed",":","\u8bbe\u7f6e\u7684\u968f\u673a\u6570\u79cd\u5b50",":","param","kwargs",":","fastNLP","\u5185\u90e8\u4f7f\u7528\u7684\u53c2\u6570"]
docstr: 进行分布式的相关设置，应当在初始化该 BatchSampler 本身后立即被调用。
  
  :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","BatchSampler","\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","``",":","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, rank, pad=True):
      """
      进行分布式的相关设置，应当在初始化该 BatchSampler 本身后立即被调用。
  
      :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: import os
  import math
  from copy import deepcopy
  from typing import Dict, Union, List
  from itertools import chain
  import numpy
  from fastNLP.core.dataset import DataSet
  from fastNLP.core.log import logger
  from .utils import create_array
  from abc import abstractmethod
label_desc: Use image node_id 2 for calling the RandomBatchSampler obj's underlying member method code with example usage: obj.set_distributed(num_replicas, rank, pad) and returns: self