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: 断点重训的保存函数，该函数会负责保存优化器、fp16 状态和 sampler 的状态，以及模型的保存（若 ``should_save_model`` 为 ``True``）
  
  :param folder: 保存断点重训的状态的文件夹；:meth:`save_checkpoint` 函数应该在该路径下面下面新增名为 ``FASTNLP_CHECKPOINT_FILENAME`` 与
      ``FASTNLP_MODEL_FILENAME`` （如果 ``should_save_model`` 为 ``True`` ）的文件。把 model 相关的内容放入到 ``FASTNLP_MODEL_FILENAME`` 文件
      中，将传入的 ``states`` 以及自身产生的其它状态一并保存在 ``FASTNLP_CHECKPOINT_FILENAME`` 里面。
  :param states: 由 :class:`~fastNLP.core.controllers.Trainer` 传入的一个字典，其中已经包含了为了实现断点重训所需要保存的其它对象的状态。Driver 应该
      只需要保存该对象而不需要理解该对象，同时在 :meth:`load_checkpoint` 的时候需要将 ``states`` 返回回去，返回的值与这里传入的值保持一致。
  :param dataloader: 正在使用的 dataloader，需要保存里面的状态使得之后可以从当前迭代的位置恢复。
  :param only_state_dict: 是否只保存模型的参数，当 ``should_save_model`` 为 ``False`` ，该参数无效。
  :param should_save_model: 是否应该保存模型，如果为 ``False`` ，Driver 将不负责 model 的保存。
docstr_tok: ["\u65ad\u70b9\u91cd\u8bad\u7684\u4fdd\u5b58\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u4f1a\u8d1f\u8d23\u4fdd\u5b58\u4f18\u5316\u5668\u3001fp16","\u72b6\u6001\u548c","sampler","\u7684\u72b6\u6001\uff0c\u4ee5\u53ca\u6a21\u578b\u7684\u4fdd\u5b58\uff08\u82e5","``","should_save_model","``","\u4e3a","``","True","``","\uff09",":","param","folder",":","\u4fdd\u5b58\u65ad\u70b9\u91cd\u8bad\u7684\u72b6\u6001\u7684\u6587\u4ef6\u5939\uff1b",":","meth",":","`","save_checkpoint","`","\u51fd\u6570\u5e94\u8be5\u5728\u8be5\u8def\u5f84\u4e0b\u9762\u4e0b\u9762\u65b0\u589e\u540d\u4e3a","``","FASTNLP_CHECKPOINT_FILENAME","``","\u4e0e","``","FASTNLP_MODEL_FILENAME","``","\uff08\u5982\u679c","``","should_save_model","``","\u4e3a","``","True","``","\uff09\u7684\u6587\u4ef6\u3002\u628a","model","\u76f8\u5173\u7684\u5185\u5bb9\u653e\u5165\u5230","``","FASTNLP_MODEL_FILENAME","``","\u6587\u4ef6","\u4e2d\uff0c\u5c06\u4f20\u5165\u7684","``","states","``","\u4ee5\u53ca\u81ea\u8eab\u4ea7\u751f\u7684\u5176\u5b83\u72b6\u6001\u4e00\u5e76\u4fdd\u5b58\u5728","``","FASTNLP_CHECKPOINT_FILENAME","``","\u91cc\u9762\u3002",":","param","states",":","\u7531",":","class",":","`","~fastNLP.core.controllers.Trainer","`","\u4f20\u5165\u7684\u4e00\u4e2a\u5b57\u5178\uff0c\u5176\u4e2d\u5df2\u7ecf\u5305\u542b\u4e86\u4e3a\u4e86\u5b9e\u73b0\u65ad\u70b9\u91cd\u8bad\u6240\u9700\u8981\u4fdd\u5b58\u7684\u5176\u5b83\u5bf9\u8c61\u7684\u72b6\u6001\u3002Driver","\u5e94\u8be5","\u53ea\u9700\u8981\u4fdd\u5b58\u8be5\u5bf9\u8c61\u800c\u4e0d\u9700\u8981\u7406\u89e3\u8be5\u5bf9\u8c61\uff0c\u540c\u65f6\u5728",":","meth",":","`","load_checkpoint","`","\u7684\u65f6\u5019\u9700\u8981\u5c06","``","states","``","\u8fd4\u56de\u56de\u53bb\uff0c\u8fd4\u56de\u7684\u503c\u4e0e\u8fd9\u91cc\u4f20\u5165\u7684\u503c\u4fdd\u6301\u4e00\u81f4\u3002",":","param","dataloader",":","\u6b63\u5728\u4f7f\u7528\u7684","dataloader\uff0c\u9700\u8981\u4fdd\u5b58\u91cc\u9762\u7684\u72b6\u6001\u4f7f\u5f97\u4e4b\u540e\u53ef\u4ee5\u4ece\u5f53\u524d\u8fed\u4ee3\u7684\u4f4d\u7f6e\u6062\u590d\u3002",":","param","only_state_dict",":","\u662f\u5426\u53ea\u4fdd\u5b58\u6a21\u578b\u7684\u53c2\u6570\uff0c\u5f53","``","should_save_model","``","\u4e3a","``","False","``","\uff0c\u8be5\u53c2\u6570\u65e0\u6548\u3002",":","param","should_save_model",":","\u662f\u5426\u5e94\u8be5\u4fdd\u5b58\u6a21\u578b\uff0c\u5982\u679c\u4e3a","``","False","``","\uff0cDriver","\u5c06\u4e0d\u8d1f\u8d23","model","\u7684\u4fdd\u5b58\u3002"]
code: def save_checkpoint(
      self,
      folder,
      states: Dict,
      dataloader,
      only_state_dict: bool = True,
      should_save_model: bool = True,
      **kwargs,
  ):
      r"""
      断点重训的保存函数，该函数会负责保存优化器、fp16 状态和 sampler 的状态，以及模型的保存（若 ``should_save_model`` 为 ``True``）
  
      :param folder: 保存断点重训的状态的文件夹；:meth:`save_checkpoint` 函数应该在该路径下面下面新增名为 ``FASTNLP_CHECKPOINT_FILENAME`` 与
          ``FASTNLP_MODEL_FILENAME`` （如果 ``should_save_model`` 为 ``True`` ）的文件。把 model 相关的内容放入到 ``FASTNLP_MODEL_FILENAME`` 文件
          中，将传入的 ``states`` 以及自身产生的其它状态一并保存在 ``FASTNLP_CHECKPOINT_FILENAME`` 里面。
      :param states: 由 :class:`~fastNLP.core.controllers.Trainer` 传入的一个字典，其中已经包含了为了实现断点重训所需要保存的其它对象的状态。Driver 应该
          只需要保存该对象而不需要理解该对象，同时在 :meth:`load_checkpoint` 的时候需要将 ``states`` 返回回去，返回的值与这里传入的值保持一致。
      :param dataloader: 正在使用的 dataloader，需要保存里面的状态使得之后可以从当前迭代的位置恢复。
      :param only_state_dict: 是否只保存模型的参数，当 ``should_save_model`` 为 ``False`` ，该参数无效。
      :param should_save_model: 是否应该保存模型，如果为 ``False`` ，Driver 将不负责 model 的保存。
      """
      raise NotImplementedError(
          "Each specific driver should implemented its own `save_checkpoint` 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 27 for calling the Driver obj's underlying member method code with example usage: obj.save_checkpoint(folder, states, dataloader, only_state_dict, should_save_model) without return types