class_docstr: 用来初始化 `Driver` 的基类，所有定制的 `driver` 都需要继承此类；
  **fastNLP** 提供的 driver 实例都会同时被 :class:`~fastNLP.core.controllers.Trainer` 和 :class:`~fastNLP.core.controllers.Evaluator` 调用。
  
  :param model: 训练或者评测的模型，需要注意该模型可能为用户已经使用类似 :class:`torch.nn.DataParallel` 或者
      :class:`torch.nn.parallel.DistributedDataParallel` 包裹过的模型。
class_docstr_tok: ["\u7528\u6765\u521d\u59cb\u5316","`","Driver","`","\u7684\u57fa\u7c7b\uff0c\u6240\u6709\u5b9a\u5236\u7684","`","driver","`","\u90fd\u9700\u8981\u7ee7\u627f\u6b64\u7c7b\uff1b","*","*","fastNLP","*","*","\u63d0\u4f9b\u7684","driver","\u5b9e\u4f8b\u90fd\u4f1a\u540c\u65f6\u88ab",":","class",":","`","~fastNLP.core.controllers.Trainer","`","\u548c",":","class",":","`","~fastNLP.core.controllers.Evaluator","`","\u8c03\u7528\u3002",":","param","model",":","\u8bad\u7ec3\u6216\u8005\u8bc4\u6d4b\u7684\u6a21\u578b\uff0c\u9700\u8981\u6ce8\u610f\u8be5\u6a21\u578b\u53ef\u80fd\u4e3a\u7528\u6237\u5df2\u7ecf\u4f7f\u7528\u7c7b\u4f3c",":","class",":","`","torch.nn.DataParallel","`","\u6216\u8005",":","class",":","`","torch.nn.parallel.DistributedDataParallel","`","\u5305\u88f9\u8fc7\u7684\u6a21\u578b\u3002"]
docstr: 通过调用 ``fn`` 来实现训练时的前向传播过程；
  注意 :class:`~fastNLP.core.controllers.Trainer` 和 :class:`~fastNLP.core.controllers.Evaluator` 会调用该函数来
  实现网络的前向传播过程，其中传入该函数的参数 ``fn`` 是函数 :meth:`get_model_call_fn` 所返回的函数。
  
  :param batch: 当前的一个 batch 的数据；可以为字典或者其它类型。
  :param fn: 调用该函数进行一次计算。
  :param signature_fn: 由 :class:`~fastNLP.core.controllers.Trainer` 传入的用于网络前向传播一次的签名函数，因为当
      batch 是一个 :class:`Dict` 的时候，我们会自动调用 :func:`fastNLP.core.utils.auto_param_call` 函数，而一些被
      包裹的模型需要暴露其真正的函数签名，例如 :class:`DistributedDataParallel` 的调用函数是 ``forward``，但是需要其
      函数签名为 ``model.module.forward``。
  :return: 由 ``fn`` 返回的结果（应当为一个 :class:`dict` 或者 :class:`dataclass` ，但是不需要我们去检查）。
docstr_tok: ["\u901a\u8fc7\u8c03\u7528","``","fn","``","\u6765\u5b9e\u73b0\u8bad\u7ec3\u65f6\u7684\u524d\u5411\u4f20\u64ad\u8fc7\u7a0b\uff1b","\u6ce8\u610f",":","class",":","`","~fastNLP.core.controllers.Trainer","`","\u548c",":","class",":","`","~fastNLP.core.controllers.Evaluator","`","\u4f1a\u8c03\u7528\u8be5\u51fd\u6570\u6765","\u5b9e\u73b0\u7f51\u7edc\u7684\u524d\u5411\u4f20\u64ad\u8fc7\u7a0b\uff0c\u5176\u4e2d\u4f20\u5165\u8be5\u51fd\u6570\u7684\u53c2\u6570","``","fn","``","\u662f\u51fd\u6570",":","meth",":","`","get_model_call_fn","`","\u6240\u8fd4\u56de\u7684\u51fd\u6570\u3002",":","param","batch",":","\u5f53\u524d\u7684\u4e00\u4e2a","batch","\u7684\u6570\u636e\uff1b\u53ef\u4ee5\u4e3a\u5b57\u5178\u6216\u8005\u5176\u5b83\u7c7b\u578b\u3002",":","param","fn",":","\u8c03\u7528\u8be5\u51fd\u6570\u8fdb\u884c\u4e00\u6b21\u8ba1\u7b97\u3002",":","param","signature_fn",":","\u7531",":","class",":","`","~fastNLP.core.controllers.Trainer","`","\u4f20\u5165\u7684\u7528\u4e8e\u7f51\u7edc\u524d\u5411\u4f20\u64ad\u4e00\u6b21\u7684\u7b7e\u540d\u51fd\u6570\uff0c\u56e0\u4e3a\u5f53","batch","\u662f\u4e00\u4e2a",":","class",":","`","Dict","`","\u7684\u65f6\u5019\uff0c\u6211\u4eec\u4f1a\u81ea\u52a8\u8c03\u7528",":","func",":","`","fastNLP.core.utils.auto_param_call","`","\u51fd\u6570\uff0c\u800c\u4e00\u4e9b\u88ab","\u5305\u88f9\u7684\u6a21\u578b\u9700\u8981\u66b4\u9732\u5176\u771f\u6b63\u7684\u51fd\u6570\u7b7e\u540d\uff0c\u4f8b\u5982",":","class",":","`","DistributedDataParallel","`","\u7684\u8c03\u7528\u51fd\u6570\u662f","``","forward","``","\uff0c\u4f46\u662f\u9700\u8981\u5176","\u51fd\u6570\u7b7e\u540d\u4e3a","``","model.module.forward","``","\u3002",":","return",":","\u7531","``","fn","``","\u8fd4\u56de\u7684\u7ed3\u679c\uff08\u5e94\u5f53\u4e3a\u4e00\u4e2a",":","class",":","`","dict","`","\u6216\u8005",":","class",":","`","dataclass","`","\uff0c\u4f46\u662f\u4e0d\u9700\u8981\u6211\u4eec\u53bb\u68c0\u67e5\uff09\u3002"]
code: def model_call(
      self, batch, fn: Callable, signature_fn: Optional[Callable]
  ) -> Dict:
      r"""
      通过调用 ``fn`` 来实现训练时的前向传播过程；
      注意 :class:`~fastNLP.core.controllers.Trainer` 和 :class:`~fastNLP.core.controllers.Evaluator` 会调用该函数来
      实现网络的前向传播过程，其中传入该函数的参数 ``fn`` 是函数 :meth:`get_model_call_fn` 所返回的函数。
  
      :param batch: 当前的一个 batch 的数据；可以为字典或者其它类型。
      :param fn: 调用该函数进行一次计算。
      :param signature_fn: 由 :class:`~fastNLP.core.controllers.Trainer` 传入的用于网络前向传播一次的签名函数，因为当
          batch 是一个 :class:`Dict` 的时候，我们会自动调用 :func:`fastNLP.core.utils.auto_param_call` 函数，而一些被
          包裹的模型需要暴露其真正的函数签名，例如 :class:`DistributedDataParallel` 的调用函数是 ``forward``，但是需要其
          函数签名为 ``model.module.forward``。
      :return: 由 ``fn`` 返回的结果（应当为一个 :class:`dict` 或者 :class:`dataclass` ，但是不需要我们去检查）。
      """
      raise NotImplementedError(
          "Each specific driver should implemented its own `model_call` function."
      )
  
imports: import os
  import signal
  import sys
  from typing import Sequence, List, Optional, Callable, Dict, Union, Tuple
  from abc import ABC, abstractmethod
  from datetime import datetime
  from pathlib import Path
  from io import BytesIO
  import json
  from fastNLP.core.utils import nullcontext
label_desc: Use image node_id 6 for calling the Driver obj's underlying member method code with example usage: obj.model_call(batch, fn, signature_fn) without return types