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"]
code: def __iter__(self):
      if self.during_iter:  # 如果发现_during_iter为True，说明之前的还没结束，只有强制重新初始化了
          self.num_consumed_samples = 0
      self.during_iter = True
  
      indices = list(range(self.num_samples))
  
      if self.shuffle:
          if self.num_consumed_samples > 0:  # 需要先按照原来的排序，删掉多余的
              _batches = []
              for _i in range(self.old_num_replicas):
                  _indices = indices[
                      _i : len(indices) : self.old_num_replicas
                  ]
                  __batches = self.batchify(
                      _indices,
                      self.old_batch_size,
                      seed=self.seed + self.epoch,
                  )
                  _batches.append(__batches)
              batches = list(chain(*[_ for _ in zip(*_batches)]))
              indices = list(chain(*batches))
              indices = indices[self.num_consumed_samples :]
          # 取出这个 rank ，
          indices = indices[
              self.rank : len(indices) : self.num_replicas
          ]
          batches = self.batchify(
              indices, self.batch_size, seed=self.seed + self.epoch
          )
          batches = list(map(list, batches))
      else:
          indices = indices[self.num_consumed_samples :]
          indices = indices[
              self.rank : len(indices) : self.num_replicas
          ]
          _num_batches = len(indices) // self.batch_size
          if _num_batches == 0:
              batches = [indices]
          else:
              batches = list(
                  map(
                      list,
                      np.array_split(
                          indices[: _num_batches * self.batch_size],
                          _num_batches,
                      ),
                  )
              )
              if len(indices) % self.batch_size != 0:
                  batches.append(
                      indices[_num_batches * self.batch_size :]
                  )
  
      need_pad_num = (
          self.num_samples - self.num_consumed_samples
      ) % self.num_replicas
      if self.pad and need_pad_num != 0 and need_pad_num <= self.rank:
          if len(batches) > 0:
              if len(batches[-1]) < self.batch_size:
                  batches[-1].append(
                      batches[-1][0]
                  )  # 这里可以保证这个bucket的长度没被破坏。
              else:
                  batches.append([batches[-1][0]])
      elif (
          self.pad is False
          and need_pad_num != 0
          and need_pad_num > self.rank
      ):
          if len(batches):
              batches[-1].pop(-1)
          if len(batches[-1]) == 0:
              batches.pop(-1)
  
      assert sum(map(len, batches)) == self.num_left_samples
  
      if (
          self.drop_last
          and len(batches) >= 1
          and len(batches[-1]) < self.batch_size
      ):
          batches = batches[:-1]
  
      for batch in batches:
          self.num_consumed_samples += self.num_replicas * len(batch)
          yield list(map(int, batch))
      self.during_iter = False
      self.num_consumed_samples = 0
      self.old_batch_size = self.batch_size
      self.old_num_replicas = self.num_replicas
      if self.epoch < 0:  # 防止用户没有修改epoch，导致每个epoch都一样了
          self.epoch -= 1
  
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 3 for calling the RandomBatchSampler obj's underlying member method code with example usage: obj.__iter__() without return types