code: def save_model(
      model,
      optimizer,
      model_path,
      logger,
      config,
      is_best=False,
      prefix="ppocr",
      **kwargs,
  ):
      """
      save model to the target path
      """
      _mkdir_if_not_exist(model_path, logger)
      model_prefix = os.path.join(model_path, prefix)
  
      if prefix == "best_accuracy":
          best_model_path = os.path.join(model_path, "best_model")
          _mkdir_if_not_exist(best_model_path, logger)
  
      paddle.save(optimizer.state_dict(), model_prefix + ".pdopt")
      if prefix == "best_accuracy":
          paddle.save(
              optimizer.state_dict(),
              os.path.join(best_model_path, "model.pdopt"),
          )
  
      is_nlp_model = config["Architecture"][
          "model_type"
      ] == "kie" and config["Architecture"]["algorithm"] not in [
          "SDMGR"
      ]
      if is_nlp_model is not True:
          paddle.save(model.state_dict(), model_prefix + ".pdparams")
          metric_prefix = model_prefix
  
          if prefix == "best_accuracy":
              paddle.save(
                  model.state_dict(),
                  os.path.join(best_model_path, "model.pdparams"),
              )
  
      else:  # for kie system, we follow the save/load rules in NLP
          if config["Global"]["distributed"]:
              arch = model._layers
          else:
              arch = model
          if config["Architecture"]["algorithm"] in ["Distillation"]:
              arch = arch.Student
          arch.backbone.model.save_pretrained(model_prefix)
          metric_prefix = os.path.join(model_prefix, "metric")
  
          if prefix == "best_accuracy":
              arch.backbone.model.save_pretrained(best_model_path)
  
      # save metric and config
      with open(metric_prefix + ".states", "wb") as f:
          pickle.dump(kwargs, f, protocol=2)
      if is_best:
          logger.info("save best model is to {}".format(model_prefix))
      else:
          logger.info("save model in {}".format(model_prefix))
  
file_path: PaddleOCR/ppocr/utils/save_load.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import errno
  import os
  import pickle
  import six
  import paddle
  from ppocr.utils.logging import get_logger
  from ppocr.utils.network import maybe_download_params
label_desc: Use image node_id 4 for calling a global function with example usage: save_model(model, optimizer, model_path, logger, config, is_best, prefix) without return types