class_docstr: 用来管理训练过程中的所有的 callback 实例；
class_docstr_tok: ["\u7528\u6765\u7ba1\u7406\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u7684\u6240\u6709\u7684","callback","\u5b9e\u4f8b\uff1b"]
docstr: 用于断点重训的 callback 的保存函数；
  该函数主要涉及两个方面：
  
  1. callback 的状态的保存；我们会调用每一个 callback 的 :func:`on_save_checkpoint` 方法，该方法应当返回一个字典，其中包含着
     断点重训应当保存的状态；
  2. 每一个具体的 callback 函数的 filter 的状态；
  
  :param trainer: :class:`~fastNLP.core.controllers.Trainer` 实例；
  :return: 一个包含上述内容的字典，格式如下:
  .. code-block::
  
      {
          "callback_name_1": {
              "states": {...},
              "filter_states": {"on_train_begin": filter1.state_dict(), ...}
          }
      }
docstr_tok: ["\u7528\u4e8e\u65ad\u70b9\u91cd\u8bad\u7684","callback","\u7684\u4fdd\u5b58\u51fd\u6570\uff1b","\u8be5\u51fd\u6570\u4e3b\u8981\u6d89\u53ca\u4e24\u4e2a\u65b9\u9762\uff1a","1.","callback","\u7684\u72b6\u6001\u7684\u4fdd\u5b58\uff1b\u6211\u4eec\u4f1a\u8c03\u7528\u6bcf\u4e00\u4e2a","callback","\u7684",":","func",":","`","on_save_checkpoint","`","\u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u5e94\u5f53\u8fd4\u56de\u4e00\u4e2a\u5b57\u5178\uff0c\u5176\u4e2d\u5305\u542b\u7740","\u65ad\u70b9\u91cd\u8bad\u5e94\u5f53\u4fdd\u5b58\u7684\u72b6\u6001\uff1b","2",".","\u6bcf\u4e00\u4e2a\u5177\u4f53\u7684","callback","\u51fd\u6570\u7684","filter","\u7684\u72b6\u6001\uff1b",":","param","trainer",":",":","class",":","`","~fastNLP.core.controllers.Trainer","`","\u5b9e\u4f8b\uff1b",":","return",":","\u4e00\u4e2a\u5305\u542b\u4e0a\u8ff0\u5185\u5bb9\u7684\u5b57\u5178\uff0c\u683c\u5f0f\u5982\u4e0b",":","..","code-block",":",":","{","``","callback_name_1","''",":","{","``","states","''",":","{","...","}",",","``","filter_states","''",":","{","``","on_train_begin","''",":","filter1.state_dict","(",")",",","...","}","}","}"]
code: def on_save_checkpoint(self, trainer) -> Dict:
      r"""
      用于断点重训的 callback 的保存函数；
      该函数主要涉及两个方面：
  
      1. callback 的状态的保存；我们会调用每一个 callback 的 :func:`on_save_checkpoint` 方法，该方法应当返回一个字典，其中包含着
         断点重训应当保存的状态；
      2. 每一个具体的 callback 函数的 filter 的状态；
  
      :param trainer: :class:`~fastNLP.core.controllers.Trainer` 实例；
      :return: 一个包含上述内容的字典，格式如下:
      .. code-block::
  
          {
              "callback_name_1": {
                  "states": {...},
                  "filter_states": {"on_train_begin": filter1.state_dict(), ...}
              }
          }
      """
  
      states = {}
      # 1. 每一个 callback 的状态；
      # 如果有两个 callback 的 name 相同，那么我们只会保存第一个；
      _duplicated_callbacks = []
      for each_callback in self.all_callbacks:
          if each_callback.callback_name in states:
              _duplicated_callbacks.append(each_callback.callback_name)
              # 对于 callback_name 有重复的 callback，我们仍旧会调用其 `on_save_checkpoint` 函数，就如同调用其它 callback 函数
              #  一样，但是其结果并不会存储在 states 中返回；
              each_callback.on_save_checkpoint(trainer)
          else:
              states[each_callback.callback_name] = {}
              states[each_callback.callback_name][
                  "states"
              ] = each_callback.on_save_checkpoint(trainer)
  
      if len(_duplicated_callbacks) > 0:
          logger.warning(
              f"Notice these callback_name: {_duplicated_callbacks} are duplicated, "
              f"fastNLP will only save the first callback's state."
          )
  
      # 2. 每一个具体的 callback 函数的 filter 的状态；
      _record_duplicated_callback_names = set()
      for each_callback_filters in self._callback_filters:
          if (
              each_callback_filters[0]
              not in _record_duplicated_callback_names
          ):
              _record_duplicated_callback_names.add(
                  each_callback_filters[0]
              )
              if (
                  "filter_states"
                  not in states[each_callback_filters[0]]
              ):
                  states[each_callback_filters[0]]["filter_states"] = {}
              states[each_callback_filters[0]]["filter_states"][
                  each_callback_filters[1]
              ] = each_callback_filters[2].state_dict()
  
      # 3. 保存 callback_counter；
      # callback_counter 不应当被保存，因为其在断点重训时会由新的 callback_manager 重新初始化；
      # 对于断点重训，我们不会保存 Trainer 的所有参数，例如 batch_step_fn；如果在断点重训时重新初始化 Trainer 发现 batch_step_fn
      # 不为 None，那么 Trainer 就会调用实际的 check_batch_step_fn 函数，从而需要 callback_counter 为全新的状态；
  
      return states
  
imports: import inspect
  from typing import List, Optional, Dict, Sequence
  from collections import defaultdict
  from .callback_event import Event
  from .callback import Callback
  from fastNLP.core.log import logger
  from .progress_callback import ProgressCallback, choose_progress_callback
  from ..utils.exceptions import EarlyStopException
  from ..utils.utils import _get_fun_msg
label_desc: Use image node_id 5 for calling the CallbackManager obj's underlying member method code with example usage: obj.on_save_checkpoint(trainer) and returns: states