code: def save(
      config: PyTextConfig,
      model: Model,
      meta: Optional[CommonMetadata],
      tensorizers: Dict[str, Tensorizer],
      training_state: Optional[TrainingState] = None,
      identifier: Optional[str] = None,
  ) -> str:
      """
      Save all stateful information of a training task to a specified file-like
      object, will save the original config, model state, metadata,
      training state if training is not completed
      Args:
      identifier (str): used to identify a checkpoint within a training job,
      used as a suffix for save path
      config (PytextConfig): contains all raw parameter/hyper-parameters
      for training task
      model (Model): actual model in training
      training_state (TrainingState): stateful infomation during training
      Returns:
      identifier (str): if identifier is not specified, will save to
      config.save_snapshot_path to be consistent to post-training snapshot;
      if specified, will be used to save checkpoint during training,
      identifier is used to identify checkpoints in the same training
      """
      saved_path = ""
      if identifier:
          # saving during-training checkpoints
          saved_path = generate_checkpoint_path(config, identifier)
      else:
          # saving post-training snapshot if no identifer given
          saved_path = config.save_snapshot_path
          print(f"Saving pytorch model to: {saved_path}")
  
      saved_folder = os.path.dirname(saved_path)
      if not PathManager.exists(saved_folder):
          PathManager.mkdirs(saved_folder)
          print(f"created {saved_folder}")
  
      # Currently torch.save() has error pickling certain models when not saving
      # by model.state_dict(), thus currently overriding the model in
      # training_state with None, and put back saving
      # https://github.com/pytorch/pytorch/issues/15116
      model_in_training_state = None
      if training_state:
          model_in_training_state, training_state.model = (
              training_state.model,
              None,
          )
      try:
          state = {
              DATA_STATE: meta,
              CONFIG_JSON: config_to_json(PyTextConfig, config),
              MODEL_STATE: model.state_dict(),
              SERIALIZE_VERSION_KEY: LATEST_SERIALIZE_VERSION,
              TENSORIZERS: tensorizers,
              TRAINING_STATE: training_state,
          }
          if identifier is not None:
              _CHECKPOINT_MANAGER.save_checkpoint(state, saved_path)
          else:
              _CHECKPOINT_MANAGER.save_snapshot(state, saved_path)
  
      finally:
          if training_state:
              training_state.model = model_in_training_state
      return saved_path
  
imports: import io
  import logging
  import os
  from typing import Dict, Optional
  import torch
  from pytext.config import config_to_json, pytext_config_from_json, PyTextConfig
  from pytext.data import CommonMetadata
  from pytext.data.tensorizers import Tensorizer
  from pytext.models import Model
  from pytext.trainers.training_state import TrainingState
  from pytext.utils.file_io import PathManager
  from .pytext_checkpoint_management import get_checkpoint_manager
label_desc: Use image node_id 10 for calling a global function with example usage: save(config, model, meta, tensorizers, training_state, identifier) and returns: saved_path