code: def serialized_save(
      model: torch.nn.Module,
      optimizer,
      source: Union[dict, list],
      serial: Optional[int],
      serial_of_soft_link: Optional[int],
      path_without_extension: str,
      tag: Optional[str] = None,
      extension_name: Optional[str] = None,
      serial_intervals: int = 1,
      max_save: int = -1,
  ):
      r"""
      Save a sequence of files with given serial numbers and create a soft link
      to the file with specified serial number.
  
      Args:
          source: The source of current file.
          serial: The serial number of current file.
          serial_of_soft_link: The serial number that the soft link will point to.
          path_without_extension: The path to base file without extension name.
              This should remain the same within the sequence.
          tag: The extended tag of filename like 'epoch' or 'valid'.
              This should remain the same within the sequence.
          extension_name: (default = None) The extension name of file. This can also
              be specific automatically if leave blank.
          serial_interval: (default = 1) The interval of serial indices.
          max_save: (default = -1) The maximal amount of files. If -1, every file
              will be saved. 1: only the file with serial number same as `serial_
              of_soft_link` will be saved. 2: both the last one and linked files.
      """
  
      # deal with naming
      path_to_save = os.path.abspath(
          path_without_extension + get_tag(tag, serial)
      )  # saving fold
      safe_remove(
          path_to_save
      )  # behavior of torch.save is not clearly defined.
      get_logger(__name__).debug(f'Saving files to "{path_to_save}"')
  
      # not serialized saving
      if (
          serial is None
          or serial_of_soft_link is None
          or max_save == -1
      ):
          torch.save(source, path_to_save)
          return
  
      # no new file to save
      if max_save == 0 or (
          max_save == 1 and serial_of_soft_link != serial
      ):
          return
  
      # read soft link
      path_to_link = os.path.abspath(path_without_extension + "_best")
      path_to_pre_best = (
          os.readlink(path_to_link) if file_exists(path_to_link) else ""
      )
      serial_of_pre_best = serial
      if not file_exists(path_to_pre_best):
          path_to_pre_best = None
      else:
          serial_of_pre_best = int(path_to_pre_best.split("-")[-1])
  
      # save
      model.save_pretrained(path_to_save)
      optim_path = os.path.join(path_to_save, "optimizer.pt")
      config_path = os.path.join(
          path_to_save, "textbox_configuration.pt"
      )
      torch.save(optimizer.state_dict(), optim_path)
      torch.save(source, config_path)
  
      # delete the file beyond the max_save
      soft_link_goes_beyond = (
          max_save - 1
      ) * serial_intervals < serial - serial_of_soft_link
      serial_to_delete = (
          serial
          - (max_save - int(soft_link_goes_beyond)) * serial_intervals
      )
      get_logger(__name__).debug(
          f'Soft link now are pointing to serial: "{serial_of_soft_link}"'
      )
      if 0 <= serial_to_delete < serial:
          path_to_delete = os.path.abspath(
              path_without_extension + get_tag(tag, serial_to_delete)
          )
          safe_remove(path_to_delete)
  
      # update soft link
      pre_best_goes_beyond = (
          max_save - 1
      ) * serial_intervals < serial - serial_of_pre_best
      if serial_of_soft_link == serial:
          if pre_best_goes_beyond:
              safe_remove(path_to_pre_best)
          safe_remove(path_to_link)
          os.symlink(path_to_save, path_to_link)
  
imports: import os
  import datetime
  import importlib
  from accelerate.logging import get_logger
  from typing import Union, Optional
  import shutil
  import torch
  from accelerate.utils import set_seed
  from transformers import AutoTokenizer, BertTokenizer
  from .enum_type import PLM_MODELS, RNN_MODELS
label_desc: Use image node_id 8 for calling a global function with example usage: serialized_save(model, optimizer, source, serial, serial_of_soft_link, path_without_extension, tag, extension_name, serial_intervals, max_save) without return types