class_docstr: 提供给 ``jittor`` 框架使用的 ``DataLoader`` 函数，``JittorDataLoader`` 提供了 ``Collator`` 来自动检测 dataset 的每个 field 是否可 pad，
  若是可 pad 的 field 则自动 pad 到相同长度，否则只会将相同 field 的数据收集组成一个 batch 返回。
  具体详见 :class:`~fastNLP.core.collators.Collator`；用户通过 callte_fn 来控制是否使用该功能， collate_fn 只能为 ``['auto', None, Callable]`` 三种取值。
  
      * callate_fn 为 ``'auto'`` 时，``JittorDataLoader`` 使用 :class:`~fastNLP.core.collators.Collator` 作为 collate_fn 的取值。
        此时可以配套使用 ``JittorDataLoader`` 的 ``set_pad`` 和 ``set_ignore`` 方法来设置 pad_val 或 忽略某个 field 的检测。
      * callate_fn 为 ``None`` 时， ``JittorDataLoader`` 默认使用 Jittor DataLoader 自带的 collate_fn
      * collate_fn 为 :class:`Callable` 时， 该 Callable 函数应当接受一个 batch 参数作为输入， batch 是一个 List 对象且 List 中的每一条数据都是
        dataset 的一条数据；该 Callable 函数还应当返回一个对象。
  
  :param dataset: 实现了 __getitem__() 和 __len__() 的对象。
  :param batch_size: 批次大小，默认为 ``16`` 且当 batch_sampler 为 None 有效。
  :param shuffle: 是否打乱数据集， 默认为 ``False``。
  :param drop_last: 当 ``drop_last=True`` 时，``JittorDataLoader`` 会扔掉最后一个长度小于 ``batch_size`` 的 batch 数据;
      若 ``drop_last=False`` , 则会返回该 batch 数据。 默认为 ``False`` 。
  :param num_workers: 当 ``num_workers > 0`` 时, ``JittorDataLoader`` 会开启 num_workers 个子进程来处理数据， 可以加快
      数据处理速度，但同时也消耗大量内存。 当 ``num_workers=0`` 时， 不开启子进程。 默认为 ``0``。
  :param buffer_size: 每个进程占用的内存空间，默认为 512M。主要是配合 ``num_workers`` 使用，用户可以自定义每个进程的内存大小。
  :param stop_grad: 是否不使用梯度， 默认 ``True`` 。
  :param keep_numpy_array: 返回的数据是 ``np.array`` 类型而不是 ``jittor.Var`` 类型，默认为 ``False``
  :param endless: 是否让 ``JittorDataLoader`` 无限返回数据，也就是将 dataset 循环使用使得返回数据是没有限制的。默认为 ``False``.
  :param collate_fn: 用于从 dataset 取到的一个 batch 数据进行打包处理的 Callable 函数，其值应该为以下三个: ``[None, "auto", Callable]``.
  
      * callate_fn 为 ``None`` 时，需要注意的是此时传进来的 datset 类型不能为 :class:`~fastNLP.core.dataset.DataSet` , 当 collate_fn 为 ``None`` 时，
        ``JittorDataLoader`` 调用默认的 Jittor 框架的 ``DataLoader`` 自带的 ``collate_batch`` 作为 callate_fn 的默认值， 其无法处理
        :class:`~fastNLP.core.dataset.DataSet` 的 dataset 对象。
      * callate_fn 为 ``'auto'`` 时，``JittorDataLoader`` 使用 :class:`~fastNLP.core.collators.Collator` 作为 collate_fn 的默认值。
        此时可以配套使用 ``JittorDataLoader`` 的 ``set_pad`` 和 ``set_ignore`` 方法来设置 pad_val 或 忽略某个 field 的检测。
      * collate_fn 为 :class:`Callable` 时， 该 Callable 函数应当接受一个 batch 参数作为输入， batch 是一个 List 对象且 List 中的每一条数据都是
        dataset 的一条数据；该 Callable 函数还应当返回一个对象。
class_docstr_tok: ["\u63d0\u4f9b\u7ed9","``","jittor","``","\u6846\u67b6\u4f7f\u7528\u7684","``","DataLoader","``","\u51fd\u6570\uff0c","``","JittorDataLoader","``","\u63d0\u4f9b\u4e86","``","Collator","``","\u6765\u81ea\u52a8\u68c0\u6d4b","dataset","\u7684\u6bcf\u4e2a","field","\u662f\u5426\u53ef","pad\uff0c","\u82e5\u662f\u53ef","pad","\u7684","field","\u5219\u81ea\u52a8","pad","\u5230\u76f8\u540c\u957f\u5ea6\uff0c\u5426\u5219\u53ea\u4f1a\u5c06\u76f8\u540c","field","\u7684\u6570\u636e\u6536\u96c6\u7ec4\u6210\u4e00\u4e2a","batch","\u8fd4\u56de\u3002","\u5177\u4f53\u8be6\u89c1",":","class",":","`","~fastNLP.core.collators.Collator","`","\uff1b\u7528\u6237\u901a\u8fc7","callte_fn","\u6765\u63a7\u5236\u662f\u5426\u4f7f\u7528\u8be5\u529f\u80fd\uff0c","collate_fn","\u53ea\u80fd\u4e3a","``","[","'auto","'",",","None",",","Callable","]","``","\u4e09\u79cd\u53d6\u503c\u3002","*","callate_fn","\u4e3a","``","'auto","'","``","\u65f6\uff0c","``","JittorDataLoader","``","\u4f7f\u7528",":","class",":","`","~fastNLP.core.collators.Collator","`","\u4f5c\u4e3a","collate_fn","\u7684\u53d6\u503c\u3002","\u6b64\u65f6\u53ef\u4ee5\u914d\u5957\u4f7f\u7528","``","JittorDataLoader","``","\u7684","``","set_pad","``","\u548c","``","set_ignore","``","\u65b9\u6cd5\u6765\u8bbe\u7f6e","pad_val","\u6216","\u5ffd\u7565\u67d0\u4e2a","field","\u7684\u68c0\u6d4b\u3002","*","callate_fn","\u4e3a","``","None","``","\u65f6\uff0c","``","JittorDataLoader","``","\u9ed8\u8ba4\u4f7f\u7528","Jittor","DataLoader","\u81ea\u5e26\u7684","collate_fn","*","collate_fn","\u4e3a",":","class",":","`","Callable","`","\u65f6\uff0c","\u8be5","Callable","\u51fd\u6570\u5e94\u5f53\u63a5\u53d7\u4e00\u4e2a","batch","\u53c2\u6570\u4f5c\u4e3a\u8f93\u5165\uff0c","batch","\u662f\u4e00\u4e2a","List","\u5bf9\u8c61\u4e14","List","\u4e2d\u7684\u6bcf\u4e00\u6761\u6570\u636e\u90fd\u662f","dataset","\u7684\u4e00\u6761\u6570\u636e\uff1b\u8be5","Callable","\u51fd\u6570\u8fd8\u5e94\u5f53\u8fd4\u56de\u4e00\u4e2a\u5bf9\u8c61\u3002",":","param","dataset",":","\u5b9e\u73b0\u4e86","__getitem__","(",")","\u548c","__len__","(",")","\u7684\u5bf9\u8c61\u3002",":","param","batch_size",":","\u6279\u6b21\u5927\u5c0f\uff0c\u9ed8\u8ba4\u4e3a","``","16","``","\u4e14\u5f53","batch_sampler","\u4e3a","None","\u6709\u6548\u3002",":","param","shuffle",":","\u662f\u5426\u6253\u4e71\u6570\u636e\u96c6\uff0c","\u9ed8\u8ba4\u4e3a","``","False","``","\u3002",":","param","drop_last",":","\u5f53","``","drop_last=True","``","\u65f6\uff0c","``","JittorDataLoader","``","\u4f1a\u6254\u6389\u6700\u540e\u4e00\u4e2a\u957f\u5ea6\u5c0f\u4e8e","``","batch_size","``","\u7684","batch","\u6570\u636e",";","\u82e5","``","drop_last=False","``",",","\u5219\u4f1a\u8fd4\u56de\u8be5","batch","\u6570\u636e\u3002","\u9ed8\u8ba4\u4e3a","``","False","``","\u3002",":","param","num_workers",":","\u5f53","``","num_workers",">","0","``","\u65f6",",","``","JittorDataLoader","``","\u4f1a\u5f00\u542f","num_workers","\u4e2a\u5b50\u8fdb\u7a0b\u6765\u5904\u7406\u6570\u636e\uff0c","\u53ef\u4ee5\u52a0\u5feb","\u6570\u636e\u5904\u7406\u901f\u5ea6\uff0c\u4f46\u540c\u65f6\u4e5f\u6d88\u8017\u5927\u91cf\u5185\u5b58\u3002","\u5f53","``","num_workers=0","``","\u65f6\uff0c","\u4e0d\u5f00\u542f\u5b50\u8fdb\u7a0b\u3002","\u9ed8\u8ba4\u4e3a","``","0","``","\u3002",":","param","buffer_size",":","\u6bcf\u4e2a\u8fdb\u7a0b\u5360\u7528\u7684\u5185\u5b58\u7a7a\u95f4\uff0c\u9ed8\u8ba4\u4e3a","512M\u3002\u4e3b\u8981\u662f\u914d\u5408","``","num_workers","``","\u4f7f\u7528\uff0c\u7528\u6237\u53ef\u4ee5\u81ea\u5b9a\u4e49\u6bcf\u4e2a\u8fdb\u7a0b\u7684\u5185\u5b58\u5927\u5c0f\u3002",":","param","stop_grad",":","\u662f\u5426\u4e0d\u4f7f\u7528\u68af\u5ea6\uff0c","\u9ed8\u8ba4","``","True","``","\u3002",":","param","keep_numpy_array",":","\u8fd4\u56de\u7684\u6570\u636e\u662f","``","np.array","``","\u7c7b\u578b\u800c\u4e0d\u662f","``","jittor.Var","``","\u7c7b\u578b\uff0c\u9ed8\u8ba4\u4e3a","``","False","``",":","param","endless",":","\u662f\u5426\u8ba9","``","JittorDataLoader","``","\u65e0\u9650\u8fd4\u56de\u6570\u636e\uff0c\u4e5f\u5c31\u662f\u5c06","dataset","\u5faa\u73af\u4f7f\u7528\u4f7f\u5f97\u8fd4\u56de\u6570\u636e\u662f\u6ca1\u6709\u9650\u5236\u7684\u3002\u9ed8\u8ba4\u4e3a","``","False","``",".",":","param","collate_fn",":","\u7528\u4e8e\u4ece","dataset","\u53d6\u5230\u7684\u4e00\u4e2a","batch","\u6570\u636e\u8fdb\u884c\u6253\u5305\u5904\u7406\u7684","Callable","\u51fd\u6570\uff0c\u5176\u503c\u5e94\u8be5\u4e3a\u4ee5\u4e0b\u4e09\u4e2a",":","``","[","None",",","``","auto","''",",","Callable","]","``",".","*","callate_fn","\u4e3a","``","None","``","\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u7684\u662f\u6b64\u65f6\u4f20\u8fdb\u6765\u7684","datset","\u7c7b\u578b\u4e0d\u80fd\u4e3a",":","class",":","`","~fastNLP.core.dataset.DataSet","`",",","\u5f53","collate_fn","\u4e3a","``","None","``","\u65f6\uff0c","``","JittorDataLoader","``","\u8c03\u7528\u9ed8\u8ba4\u7684","Jittor","\u6846\u67b6\u7684","``","DataLoader","``","\u81ea\u5e26\u7684","``","collate_batch","``","\u4f5c\u4e3a","callate_fn","\u7684\u9ed8\u8ba4\u503c\uff0c","\u5176\u65e0\u6cd5\u5904\u7406",":","class",":","`","~fastNLP.core.dataset.DataSet","`","\u7684","dataset","\u5bf9\u8c61\u3002","*","callate_fn","\u4e3a","``","'auto","'","``","\u65f6\uff0c","``","JittorDataLoader","``","\u4f7f\u7528",":","class",":","`","~fastNLP.core.collators.Collator","`","\u4f5c\u4e3a","collate_fn","\u7684\u9ed8\u8ba4\u503c\u3002","\u6b64\u65f6\u53ef\u4ee5\u914d\u5957\u4f7f\u7528","``","JittorDataLoader","``","\u7684","``","set_pad","``","\u548c","``","set_ignore","``","\u65b9\u6cd5\u6765\u8bbe\u7f6e","pad_val","\u6216","\u5ffd\u7565\u67d0\u4e2a","field","\u7684\u68c0\u6d4b\u3002","*","collate_fn","\u4e3a",":","class",":","`","Callable","`","\u65f6\uff0c","\u8be5","Callable","\u51fd\u6570\u5e94\u5f53\u63a5\u53d7\u4e00\u4e2a","batch","\u53c2\u6570\u4f5c\u4e3a\u8f93\u5165\uff0c","batch","\u662f\u4e00\u4e2a","List","\u5bf9\u8c61\u4e14","List","\u4e2d\u7684\u6bcf\u4e00\u6761\u6570\u636e\u90fd\u662f","dataset","\u7684\u4e00\u6761\u6570\u636e\uff1b\u8be5","Callable","\u51fd\u6570\u8fd8\u5e94\u5f53\u8fd4\u56de\u4e00\u4e2a\u5bf9\u8c61\u3002"]
docstr: 如果 collate_fn 是 Collator 对象，得到该对象。如果没有的话，返回 None
  
  :return:
docstr_tok: ["\u5982\u679c","collate_fn","\u662f","Collator","\u5bf9\u8c61\uff0c\u5f97\u5230\u8be5\u5bf9\u8c61\u3002\u5982\u679c\u6ca1\u6709\u7684\u8bdd\uff0c\u8fd4\u56de","None",":","return",":"]
code: def _get_collator(self):
      """
      如果 collate_fn 是 Collator 对象，得到该对象。如果没有的话，返回 None
  
      :return:
      """
      collator = None
      if hasattr(self.collate_fn, "__wrapped__") and isinstance(
          self.collate_fn.__wrapped__, Collator
      ):
          collator = self.collate_fn.__wrapped__
      elif isinstance(self.collate_fn, Collator):
          collator = self.collate_fn
      return collator
  
imports: from typing import Callable, Optional, List, Union, Dict, Sequence
  from copy import deepcopy
  import numpy
  from fastNLP.envs.imports import _NEED_IMPORT_JITTOR
  from fastNLP.core.collators import Collator
  from fastNLP.core.dataloaders.utils import indice_collate_wrapper
  from fastNLP.core.dataset import DataSet
  from ..utils import HasLenGetitemType
label_desc: Use image node_id 6 for calling the JittorDataLoader obj's underlying member method code with example usage: obj._get_collator() and returns: collator