class_docstr: 保存 checkpoint 的  callback ，其保存的文件目录以及文件名命名规则如下::
  
      - folder/
          - YYYY-mm-dd-HH_MM_SS_fffff/  # 自动根据当前脚本的启动时间创建的
              - {save_object}-epoch_{epoch_idx}/  # 满足 every_n_epochs 条件保存的模型
              - {save_object}-epoch_{epoch_idx}-batch_{global_batch_idx}/  # 满足 every_n_batches 保存的模型
              - {save_object}-last/  # 最后一个 epoch 的保存
              - {save_object}-epoch_{epoch_idx}-batch_{global_batch_idx}-exception_{exception_type}/  # exception时保存。
              - {save_object}-epoch_{epoch_idx}-batch_{global_batch_idx}-{monitor}_{monitor_value}/  # 满足topk条件存储文件名
  
  ``model_save_fn`` 为 ``None`` ，则以上每个 folder 中，将生成 fastnlp_model.pkl.tar 文件。若 ``model_save_fn`` 不为 ``None``，
  则 fastNLP 将 folder 绝对路径传递给该函数，fastNLP 在该 folder 下不进行模型保存。默认情况下，本 checkpoint 只保存了 model
  的状态；如还需保存 Trainer 的状态以断点重训的话，请使用 ``save_object='trainer'`` 。
  
  :param monitor: 监控的 metric 值。
  
      * 为 ``None``
        将尝试使用 :class:`~fastNLP.core.controllers.Trainer` 中设置 `monitor` 值（如果有设置）。
      * 为 ``str``
        尝试直接使用该名称从 ``evaluation`` 结果中寻找，如果在 ``evaluation`` 结果中没有找到完全一致的名称，将
        使用 最长公共字符串算法 从 ``evaluation`` 结果中找到最匹配的那个作为 ``monitor`` 。
      * 为 :class:`Callable`
        接受参数为 ``evaluation`` 的结果(字典类型)，返回一个 ``float`` 值作为 ``monitor`` 的结果，如果当前结果中没有相关
        的 ``monitor`` 值请返回 ``None`` 。
  
  :param folder: 保存的文件夹，fastNLP 将在该文件下以时间戳创建子文件夹，并在里面保存。因此不同次运行可以将被保存到不同的
      时间戳文件夹中。如果为 None ，默认使用当前文件夹。
  :param every_n_epochs: 多少个 epoch 保存一次。
  :param every_n_batches: 多少个 batch 保存一次。
  :param last: 如果为 ``True`` ，将在每次 epoch 运行结束都保存一次，会覆盖之前的保存。如果为 ``False`` 则不会保存 ``{save_object}-last`` 文件
  :param topk: 保存 monitor 结果中的 ``topk`` 个。
  :param on_exceptions: 在出异常信息时，是否保存。传入需要捕获的异常的类。默认将捕获 :class:`~fastNLP.core.callbacks.EarlyStopException` 。
  :param larger_better: monitor 的值是否时越大越好。
  :param only_state_dict: 保存模型时是否只保存 state_dict 。当 ``model_save_fn`` 不为 ``None`` 时，该参数无效。
  :param model_save_fn: 个性化的保存函数，当触发保存操作时，就调用这个函数，这个函数应当接受一个文件夹作为参数，不返回任何东西。
      如果传入了 ``model_save_fn`` 函数，fastNLP 将不再进行模型相关的保存。在多卡场景下，我们只在 rank 0 上会运行该函数。
  :param save_object: 可选 ``['trainer', 'model']`` ，表示在保存时的保存对象为 ``trainer+model`` 还是 只是 ``model`` 。如果
      保存 ``trainer`` 对象的话，将会保存 :class:`~fastNLP.core.controllers.Trainer` 的相关状态，可以通过 :meth:`Trainer.load_checkpoint` 加载该断
      点继续训练。如果保存的是 ``Model`` 对象，则可以通过 :meth:`Trainer.load_model` 加载该模型权重。
  :param save_evaluate_results: 是否保存 evaluate 的结果。如果为 ``True`` ，在保存 topk 模型的 folder 中还将额外保存一个
      ``fastnlp_evaluate_results.json`` 文件，记录当前的 results。仅在设置了 ``topk`` 的场景下有用，默认为 ``True`` 。
  :param kwargs:
class_docstr_tok: ["\u4fdd\u5b58","checkpoint","\u7684","callback","\uff0c\u5176\u4fdd\u5b58\u7684\u6587\u4ef6\u76ee\u5f55\u4ee5\u53ca\u6587\u4ef6\u540d\u547d\u540d\u89c4\u5219\u5982\u4e0b",":",":","-","folder\/","-","YYYY-mm-dd-HH_MM_SS_fffff\/","#","\u81ea\u52a8\u6839\u636e\u5f53\u524d\u811a\u672c\u7684\u542f\u52a8\u65f6\u95f4\u521b\u5efa\u7684","-","{","save_object","}","-epoch_","{","epoch_idx","}","\/","#","\u6ee1\u8db3","every_n_epochs","\u6761\u4ef6\u4fdd\u5b58\u7684\u6a21\u578b","-","{","save_object","}","-epoch_","{","epoch_idx","}","-batch_","{","global_batch_idx","}","\/","#","\u6ee1\u8db3","every_n_batches","\u4fdd\u5b58\u7684\u6a21\u578b","-","{","save_object","}","-last\/","#","\u6700\u540e\u4e00\u4e2a","epoch","\u7684\u4fdd\u5b58","-","{","save_object","}","-epoch_","{","epoch_idx","}","-batch_","{","global_batch_idx","}","-exception_","{","exception_type","}","\/","#","exception\u65f6\u4fdd\u5b58\u3002","-","{","save_object","}","-epoch_","{","epoch_idx","}","-batch_","{","global_batch_idx","}","-","{","monitor","}","_","{","monitor_value","}","\/","#","\u6ee1\u8db3topk\u6761\u4ef6\u5b58\u50a8\u6587\u4ef6\u540d","``","model_save_fn","``","\u4e3a","``","None","``","\uff0c\u5219\u4ee5\u4e0a\u6bcf\u4e2a","folder","\u4e2d\uff0c\u5c06\u751f\u6210","fastnlp_model.pkl.tar","\u6587\u4ef6\u3002\u82e5","``","model_save_fn","``","\u4e0d\u4e3a","``","None","``","\uff0c","\u5219","fastNLP","\u5c06","folder","\u7edd\u5bf9\u8def\u5f84\u4f20\u9012\u7ed9\u8be5\u51fd\u6570\uff0cfastNLP","\u5728\u8be5","folder","\u4e0b\u4e0d\u8fdb\u884c\u6a21\u578b\u4fdd\u5b58\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u672c","checkpoint","\u53ea\u4fdd\u5b58\u4e86","model","\u7684\u72b6\u6001\uff1b\u5982\u8fd8\u9700\u4fdd\u5b58","Trainer","\u7684\u72b6\u6001\u4ee5\u65ad\u70b9\u91cd\u8bad\u7684\u8bdd\uff0c\u8bf7\u4f7f\u7528","``","save_object='trainer","'","``","\u3002",":","param","monitor",":","\u76d1\u63a7\u7684","metric","\u503c\u3002","*","\u4e3a","``","None","``","\u5c06\u5c1d\u8bd5\u4f7f\u7528",":","class",":","`","~fastNLP.core.controllers.Trainer","`","\u4e2d\u8bbe\u7f6e","`","monitor","`","\u503c\uff08\u5982\u679c\u6709\u8bbe\u7f6e\uff09\u3002","*","\u4e3a","``","str","``","\u5c1d\u8bd5\u76f4\u63a5\u4f7f\u7528\u8be5\u540d\u79f0\u4ece","``","evaluation","``","\u7ed3\u679c\u4e2d\u5bfb\u627e\uff0c\u5982\u679c\u5728","``","evaluation","``","\u7ed3\u679c\u4e2d\u6ca1\u6709\u627e\u5230\u5b8c\u5168\u4e00\u81f4\u7684\u540d\u79f0\uff0c\u5c06","\u4f7f\u7528","\u6700\u957f\u516c\u5171\u5b57\u7b26\u4e32\u7b97\u6cd5","\u4ece","``","evaluation","``","\u7ed3\u679c\u4e2d\u627e\u5230\u6700\u5339\u914d\u7684\u90a3\u4e2a\u4f5c\u4e3a","``","monitor","``","\u3002","*","\u4e3a",":","class",":","`","Callable","`","\u63a5\u53d7\u53c2\u6570\u4e3a","``","evaluation","``","\u7684\u7ed3\u679c","(","\u5b57\u5178\u7c7b\u578b",")","\uff0c\u8fd4\u56de\u4e00\u4e2a","``","float","``","\u503c\u4f5c\u4e3a","``","monitor","``","\u7684\u7ed3\u679c\uff0c\u5982\u679c\u5f53\u524d\u7ed3\u679c\u4e2d\u6ca1\u6709\u76f8\u5173","\u7684","``","monitor","``","\u503c\u8bf7\u8fd4\u56de","``","None","``","\u3002",":","param","folder",":","\u4fdd\u5b58\u7684\u6587\u4ef6\u5939\uff0cfastNLP","\u5c06\u5728\u8be5\u6587\u4ef6\u4e0b\u4ee5\u65f6\u95f4\u6233\u521b\u5efa\u5b50\u6587\u4ef6\u5939\uff0c\u5e76\u5728\u91cc\u9762\u4fdd\u5b58\u3002\u56e0\u6b64\u4e0d\u540c\u6b21\u8fd0\u884c\u53ef\u4ee5\u5c06\u88ab\u4fdd\u5b58\u5230\u4e0d\u540c\u7684","\u65f6\u95f4\u6233\u6587\u4ef6\u5939\u4e2d\u3002\u5982\u679c\u4e3a","None","\uff0c\u9ed8\u8ba4\u4f7f\u7528\u5f53\u524d\u6587\u4ef6\u5939\u3002",":","param","every_n_epochs",":","\u591a\u5c11\u4e2a","epoch","\u4fdd\u5b58\u4e00\u6b21\u3002",":","param","every_n_batches",":","\u591a\u5c11\u4e2a","batch","\u4fdd\u5b58\u4e00\u6b21\u3002",":","param","last",":","\u5982\u679c\u4e3a","``","True","``","\uff0c\u5c06\u5728\u6bcf\u6b21","epoch","\u8fd0\u884c\u7ed3\u675f\u90fd\u4fdd\u5b58\u4e00\u6b21\uff0c\u4f1a\u8986\u76d6\u4e4b\u524d\u7684\u4fdd\u5b58\u3002\u5982\u679c\u4e3a","``","False","``","\u5219\u4e0d\u4f1a\u4fdd\u5b58","``","{","save_object","}","-last","``","\u6587\u4ef6",":","param","topk",":","\u4fdd\u5b58","monitor","\u7ed3\u679c\u4e2d\u7684","``","topk","``","\u4e2a\u3002",":","param","on_exceptions",":","\u5728\u51fa\u5f02\u5e38\u4fe1\u606f\u65f6\uff0c\u662f\u5426\u4fdd\u5b58\u3002\u4f20\u5165\u9700\u8981\u6355\u83b7\u7684\u5f02\u5e38\u7684\u7c7b\u3002\u9ed8\u8ba4\u5c06\u6355\u83b7",":","class",":","`","~fastNLP.core.callbacks.EarlyStopException","`","\u3002",":","param","larger_better",":","monitor","\u7684\u503c\u662f\u5426\u65f6\u8d8a\u5927\u8d8a\u597d\u3002",":","param","only_state_dict",":","\u4fdd\u5b58\u6a21\u578b\u65f6\u662f\u5426\u53ea\u4fdd\u5b58","state_dict","\u3002\u5f53","``","model_save_fn","``","\u4e0d\u4e3a","``","None","``","\u65f6\uff0c\u8be5\u53c2\u6570\u65e0\u6548\u3002",":","param","model_save_fn",":","\u4e2a\u6027\u5316\u7684\u4fdd\u5b58\u51fd\u6570\uff0c\u5f53\u89e6\u53d1\u4fdd\u5b58\u64cd\u4f5c\u65f6\uff0c\u5c31\u8c03\u7528\u8fd9\u4e2a\u51fd\u6570\uff0c\u8fd9\u4e2a\u51fd\u6570\u5e94\u5f53\u63a5\u53d7\u4e00\u4e2a\u6587\u4ef6\u5939\u4f5c\u4e3a\u53c2\u6570\uff0c\u4e0d\u8fd4\u56de\u4efb\u4f55\u4e1c\u897f\u3002","\u5982\u679c\u4f20\u5165\u4e86","``","model_save_fn","``","\u51fd\u6570\uff0cfastNLP","\u5c06\u4e0d\u518d\u8fdb\u884c\u6a21\u578b\u76f8\u5173\u7684\u4fdd\u5b58\u3002\u5728\u591a\u5361\u573a\u666f\u4e0b\uff0c\u6211\u4eec\u53ea\u5728","rank","0","\u4e0a\u4f1a\u8fd0\u884c\u8be5\u51fd\u6570\u3002",":","param","save_object",":","\u53ef\u9009","``","[","'trainer","'",",","'model","'","]","``","\uff0c\u8868\u793a\u5728\u4fdd\u5b58\u65f6\u7684\u4fdd\u5b58\u5bf9\u8c61\u4e3a","``","trainer+model","``","\u8fd8\u662f","\u53ea\u662f","``","model","``","\u3002\u5982\u679c","\u4fdd\u5b58","``","trainer","``","\u5bf9\u8c61\u7684\u8bdd\uff0c\u5c06\u4f1a\u4fdd\u5b58",":","class",":","`","~fastNLP.core.controllers.Trainer","`","\u7684\u76f8\u5173\u72b6\u6001\uff0c\u53ef\u4ee5\u901a\u8fc7",":","meth",":","`","Trainer.load_checkpoint","`","\u52a0\u8f7d\u8be5\u65ad","\u70b9\u7ee7\u7eed\u8bad\u7ec3\u3002\u5982\u679c\u4fdd\u5b58\u7684\u662f","``","Model","``","\u5bf9\u8c61\uff0c\u5219\u53ef\u4ee5\u901a\u8fc7",":","meth",":","`","Trainer.load_model","`","\u52a0\u8f7d\u8be5\u6a21\u578b\u6743\u91cd\u3002",":","param","save_evaluate_results",":","\u662f\u5426\u4fdd\u5b58","evaluate","\u7684\u7ed3\u679c\u3002\u5982\u679c\u4e3a","``","True","``","\uff0c\u5728\u4fdd\u5b58","topk","\u6a21\u578b\u7684","folder","\u4e2d\u8fd8\u5c06\u989d\u5916\u4fdd\u5b58\u4e00\u4e2a","``","fastnlp_evaluate_results.json","``","\u6587\u4ef6\uff0c\u8bb0\u5f55\u5f53\u524d\u7684","results\u3002\u4ec5\u5728\u8bbe\u7f6e\u4e86","``","topk","``","\u7684\u573a\u666f\u4e0b\u6709\u7528\uff0c\u9ed8\u8ba4\u4e3a","``","True","``","\u3002",":","param","kwargs",":"]
code: def on_after_trainer_initialized(self, trainer, driver):
      if self.topk_saver.topk_queue:  # 需要设置 monitor
          if self.topk_saver.monitor is None:
              self.topk_saver.set_monitor(
                  monitor=trainer.monitor,
                  larger_better=trainer.larger_better,
              )
      if self.topk_saver.topk_queue and trainer.evaluator is None:
          logger.warning(
              f"You set `topk={self.topk}`, but `evaluate_dataloaders` is not set in Trainer."
          )
  
file_path: fastNLP/fastNLP/core/callbacks/checkpoint_callback.py
imports: from typing import Union, Optional, Callable, Dict, Sequence
  from pathlib import Path
  import sys
  from fastNLP.core.log import logger
  from .topk_saver import TopkSaver
  from .callback import Callback
  from ..utils.exceptions import EarlyStopException
label_desc: Use image node_id 3 for calling the CheckpointCallback obj's underlying member method code with example usage: obj.on_after_trainer_initialized(trainer, driver) without return types